Reputation: 11
I'm beginner of Swagger, and I'm trying to define endpoints which have:
What I'm doing is defining the following models:
ResourceBaseModel: type: object properties: shared_properties: type: string
ResourceCollectionResponse: type: array items: type: object allOf: - $ref: ResourceBaseModel - type: object properties: collection_normal_properties: type: string collection_read_only_properties: type: string readOnly: true
ResourceDetailResponse: type: object allOf: - $ref: ResourceBaseModel - type: object properties: detail_normal_properties: type: string detail_read_only_properties: type: string readOnly: true
ResourceRequest: type: object allOf: - $ref: ResourceBaseModel - type: object properties: request_write_only_properties: type: string
This is making every model defined 4 times and I feel it's not efficient.
So here are my questions:
I wonder if there will be one day I can define only one model to describe all of the models, or do you think an innovative language that can compile to Swagger YAML can benefit the whole community? Like how Sass/LESS builds CSS?
Thanks for your help and insightes!
Upvotes: 1
Views: 1462
Reputation: 2393
OpenAPI 3.0.x supports writeOnly as well as readOnly
schema properties. This should allow you to simplify your models, the allOf
/ discriminator
should not be necessary.
Upvotes: 1