Skip to content

Generate proper comments for deprecated fields #975

@papkos

Description

@papkos

The OpenAPI 3 spec specifies a field to flag a property as deprecated. oapi-codegen does not process this field, even though there is a standard way of marking fields (and other things) as deprecated in Go: https://github.com/golang/go/wiki/Deprecated

It should also be possible to add an extension comment to explain why something is deprecated and what to use instead.

Example YAML:

components:
  schemas:
    DeprecatedProperty:
      type: object
      required:
        - newProp
        - oldProp
      properties:
        newProp:
          type: string
          description: Use this now!
        oldProp1:
          type: string
          deprecated: true
          # description: No description on this one to test generation in that case
        oldProp2:
          type: string
          deprecated: true
          description: It used to do this and that
        oldProp3:
          type: string
          deprecated: true
          x-deprecated-reason: Use NewProp instead!
        oldProp4:
          type: string
          deprecated: true
          x-deprecated-reason: Use NewProp instead!
          description: It used to do this and that

Expected Go code:

// DeprecatedProperty defines model for DeprecatedProperty.
type DeprecatedProperty struct {
	// NewProp Use this now!
	NewProp string `json:"newProp"`
	// Deprecated:
	OldProp1 *string `json:"oldProp1,omitempty"`

	// OldProp2 It used to do this and that
	// Deprecated:
	OldProp2 *string `json:"oldProp2,omitempty"`
	// Deprecated: Use NewProp instead!
	OldProp3 *string `json:"oldProp3,omitempty"`

	// OldProp4 It used to do this and that
	// Deprecated: Use NewProp instead!
	OldProp4 *string `json:"oldProp4,omitempty"`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions