Swagger editor dictionary parameter definition

前端 未结 1 1483
执笔经年
执笔经年 2020-12-04 02:28

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 th

相关标签:
1条回答
  • 2020-12-04 03:22

    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*:

    enter image description here

    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
    
    0 讨论(0)
提交回复
热议问题