a-h / rest

Generate OpenAPI 3.0 specifications from Go code.
MIT License
55 stars 22 forks source link

Persist deprecation of fields to TS models #9

Closed RichardInnocent closed 1 year ago

RichardInnocent commented 1 year ago

Background

If I deprecate a field in Go, I would like the field to marked as deprecated in the OpenAPI specification. This will allow users of my OpenAPI spec to be aware of which fields they should avoid.

Scenario

I have the following struct defined in Go:

type ExampleStruct struct {
    // NewField is the field that should be used.
    NewField string

    // OldField is the field that used to be used.
    // Deprecated: Use NewField instead.
    OldField string
}

Expected

This would create a model in the OpenAPI specification such as:

ExampleStruct:
  type: object
  properties:
    NewField:
      description: NewField is the field that should be used.
      type: string
    OldField:
      deprecated: true
      description: |-
        OldField is the field that used to be used.
        Deprecated: Use NewField instead.
      type: string
  required:
  - NewField
  - OldField

Note that OldField is marked as deprecated.

Actual

The model is created without any deprecation flag i.e.:

ExampleStruct:
  type: object
  properties:
    NewField:
      description: NewField is the field that should be used.
      type: string
    OldField:
      description: |-
        OldField is the field that used to be used.
        Deprecated: Use NewField instead.
      type: string
  required:
  - NewField
  - OldField