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