yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
625 stars 147 forks source link

Does SwagGen support references to properties of a schema? #166

Open raphaeloliveira opened 5 years ago

raphaeloliveira commented 5 years ago

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?

yonaskolb commented 5 years ago

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