0

I have an api that exposes a resource such as /stores. The problem is that stores have different types which require different json schemas (there are only 4 types though).

My question is how can I use swagger to validate the incoming data based on the type of store. Is it possible to have conditional checks based out of type with swagger or should I look into creating sub types such as

/stores/it

/stores/cars

...

thanks!

silviud
  • 1,015
  • 1
  • 12
  • 21
  • different resources for one path? I don't think that's poosible... – zakaria amine May 25 '17 at 13:47
  • Do the store types have any common properties? – Helen May 25 '17 at 16:06
  • the stores have most of the attributes common, different are just a few but are essential. in ooo paradigm they subclass the same base and override only a few properties – silviud May 25 '17 at 18:08
  • Inheritance/polymorphism can be implemented using `discriminator` - check out [Swagger Inheritance and Composition](https://stackoverflow.com/q/27862407/113116) and [“discriminator” in polymorphism](https://stackoverflow.com/q/39683846/113116). – Helen May 25 '17 at 19:50
  • Hi Helen, i did ... but is no clear way on how to handle it into the parameters section, even though I use parameters : [ {"name": "stores", "in": "body", "schema": { "$ref": "#/definitions/BaseStore" } } ] and I send data such as {"kind": "carStore", "name": "newCarStore"} ... I get 400 bad request. – silviud May 30 '17 at 19:10
  • Hi Helen, I found out where the error was - the definitions of the models was missing type: object into each store type, there was not error when parsing but was not processing ok - if you want to convert you comment to answer I would gladly accept it - thanks! – silviud May 30 '17 at 19:44

0 Answers0