swagger - API design pattern for specifying different response models -


i'm trying rough out api returning article content. seems valuable able specify whether want entire article, summary, or possibly other variation on content.

my instinct add query parameter request datamodel (feel free suggest better names). instance, default may entire article, summary may id, title, & description, , list might return id, title, author, & lastmodifieddate.

  • /v0/articles/{id}
  • /v0/articles/{id}?datamodel=summary
  • /v0/articles/{id}?datamodel=list

however using swagger documentation , swagger doesn't appear support returning different objects based on query parameters (see this). i'm wondering if there other established patterns equally acceptable?

the right solution swagger create return type contains common properties across data models. can model discriminator , use allof constructs creating proper response type.

if take @ sample definition here:

https://swaggerhub.com/api/swagger-tutorials/modeling-samples/1.0.0

you'll see how can done animal return type, , cat , dog concrete types.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -