yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to make `$ref` model conform to a protocol ?

mackoj opened this issue · comments

How can I make models that will be use in response($ref) conform to a particular protocol ?

      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/user'
public protocol BaseModel {
  var code: String? { set get }
  var msg: String? { set get }
  var token: String? { set get }
}

The protocol conformance in question don't require adding code but only adding the conformance all the work is done in the protocol itself.

In this case I want to make the User conform to BaseModel because all object that is in response always conform to BaseModel.

Thanks,

There isn’t a way to specify anything for JUST response models and not other models, as definitions can be used in both requests, responses or just be listed in the definitions.
You could add something for every model (definition) if you customize the template and add a protocol to model.stencil

All models now conform to APIModel which you could add your extensions to #109

Thanks, again for this feature.