OpenAPI query string parameter with list of objects

后端 未结 2 1736
悲哀的现实
悲哀的现实 2020-12-04 01:44

I am trying to document with OpenAPI a query string which look like

filtered[0][id]=code&filtered[0][value]=12345

and contains a list o

相关标签:
2条回答
  • 2020-12-04 02:26

    As name implies, :), deepObject style only "provides a simple way of rendering nested objects", not arrays. At the least according to Version 3.0.1 it applies only to objects.

    Note that even nested objects might be not yet supported by tools because the specification "does not provide such examples".

    So your format is not compatible with Open API, yet may be you can define you query as parameters which follow a regex. I such cases usually I do my best yet provide some explanation

    https://swagger.io/specification/

    Update. Apparently, after somebody demanded a 'descriptive error' message for nested objects, the nested objects support is added to swagger-js v.3.9. https://github.com/swagger-api/swagger-js/pull/1450

    0 讨论(0)
  • 2020-12-04 02:30

    This is not possible as of OpenAPI 3.0.3.

    OpenAPI 3.0 Specification currently defines the deepObject behavior only for simple objects (with primitive properties) such as

    {
      "id": 5,
      "name": "Bob"
    }
    

    but not for arrays and not for nested objects.

    Since the behavior for arrays and nested objects is not defined, there's really no way to describe your query string. Technically, the only way would be to define filtered[0][id], filtered[0][value], etc. as individual query parameters.


    If you are designing a new API (rather than describing an existing one), consider passing the array of objects in the request body instead.

    0 讨论(0)
提交回复
热议问题