Forum Discussion
Hi deepika_u95
For the discriminator, the example above is a little wrong, instead of
...
discriminator: foo
It should be
...
discriminator:
propertyName: foo
See: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/?sbsearch=discriminator for more details.
Regarding oneOf, I don't understand. It is about validation, not about what the petstore example server returns in its response (it is only a demo server).
See if https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/?sbsearch=oneOf adds any insight
- deepika_u952 years agoNew Contributor
Thanks for your response ponelat . Sorry I misunderstood the server response. So since we dont have a Dog or Cat model in the repository swagger-petstore/src/main/java/io/swagger/petstore/model at master · swagger-api/swagger-petstore · GitHub, we dont get Cat or Dog properties in server response when we do GET operation, eventhough we POST Cat or Dog properties in the request body of POST. Is that correct? Looking forward for your response. Thank you
- ponelat2 years agoStaff
deepika_u95 there are a few concepts we need to establish.
1. Annotations in the petstore demo referenced will generate an OpenAPI file
2. Describing an API is different from implementing it. We can use OpenAPI to describe an API (new or existing) that will tell consumers what to expect.
3. The relationship between GET/POST/PUT is arbitrary, which means your GET can do one thing and your POST can do something completely different, it is up to you the API designer to decide what they should do.
I believe you're asking how to implement GET /pets/... to return one of two types, a Cat or a Dog.
To do that, you would edit the controller files.
Related Content
- 3 years ago
- 6 years ago
Recent Discussions
- 2 days ago
- 2 days ago
- 19 days ago