Tell Swagger that the request body can be a single object or a list of objects

前端 未结 2 1336
不知归路
不知归路 2021-02-20 01:52

I am using Swagger with Scala to document my REST API. I want to enable bulk operations for POST, PUT and DELETE and want the same route to accept either a single object or a co

2条回答
  •  佛祖请我去吃肉
    2021-02-20 02:29

    I don't know if it's possible to annotate your API like that with Swagger. But my suggestion is to simplify/unify your API. If you think about it, if you're going to support bulk (meaning an array of objects) then there's no reason to have a special treatment of a single object. You should just change the API to always take an array and if someone wants to do a single object then thats just the case of a list with a single element object :: Nil.

提交回复
热议问题