SwagGen icon indicating copy to clipboard operation
SwagGen copied to clipboard

Does SwagGen support references to properties of a schema?

Open raphaeloliveira opened this issue 6 years ago • 1 comments

Hey @yonaskolb, our backend team recently added on our openapi spec the following entry on schemas:

A new UpdateCardRequest

    UpdateCardRequest:
      type: object
      required:
        - nickname
      properties:
        nickname:
          $ref: '#/components/schemas/Card/properties/nickname'

A new property called nickname under the existing Card schema.

    Card:
      type: object
      properties:
        ...
        nickname:  
          type: string
          nullable: true

When swaggen generates the code, Card correctly receives the new nickname property of type String. However, the new UpdateCardRequest object fails to compile due to unknown Nickname type. Apparently having a $ref to a property (Card/properties/nickname) does not make Swaggen generate a typealias or a new object. Is my assumption correct?

As a temporary workaround I could make Nickname a new object under schema and have the nickname property under Card reference it. Thoughts?

raphaeloliveira avatar May 28 '19 02:05 raphaeloliveira

Referencing a property in a Schema like that is not supported in SwagGen. I didn’t even know it was part of the open api spec. If nickname is just a string, I would just define it as such in the UpdateCardRequest, thereby duplicating the definition. I don’t think it’s necessary to make it it’s own type

yonaskolb avatar May 28 '19 05:05 yonaskolb