Swagger editor dictionary parameter definition

£可爱£侵袭症+ 提交于 2019-11-27 08:25:54

问题


I'm struggling with how to define a dictionary type in swagger editor. One of the parameters to my POST method is called 'roles' and it's value is a dictionary where the key is the email address and the value is an integer.


回答1:


Swagger supports associative arrays/hashmaps/dictionaries where keys are strings. A dictionary is defined by using an object schema with the additionalProperties keyword specifying the value type of key/value pairs. The key type is not mentioned because keys are always strings.

So a string-to-integer dictionary can be defined as:

definitions:
  MyDictionary:
    type: object
    additionalProperties:
      type: integer


By default, Swagger UI 3.x and Swagger Editor 3.x render dictionaries as containing properties named additionalProp*:

If you want a more meaningful example, add an example to your dictionary schema:

definitions:
  MyDictionary:
    type: object
    additionalProperties:
      type: integer
    example:
      apples: 5
      oranges: 7


来源:https://stackoverflow.com/questions/41867499/swagger-editor-dictionary-parameter-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!