Dictionaries mapping strings to Array?
Hello, you all. I aim to generate the spec through a NestJS project, and It's all working until now. The problem arises when I want to specify that return data is a Dict that maps a key to an array of custom objects.
I read the documentation here https://swagger.io/docs/specification/data-models/dictionaries/ and some related content and got that I can create a map of strings to strings as:
type: object
additionalProperties:
type: string
but in, all examples I found I couldn't relate to an Array.
This is an example of my data:
{
"1":[CustomObjectType, CustomObjectType, CustomObjectType],
"5":[CustomObjectType, CustomObjectType, CustomObjectType]
}
So I think on Swagger it should be something like:
components:
schemas:
CustomMap:
type: object
additionalProperties:
$ref: '#/components/schemas/CustomObjectType'
isArray: true
CustomObjectType:
type: object
...
But I can't get it correctly. If I discover how I do it in Swagger, I can figure it out how to pass it to NestJS.
Thank you to anyone who can help me.
Hi lia ,
You were very close, there isn't a "isArray" flag but there is an "array" type. See the following example...
components: schemas: CustomMap: type: object additionalProperties: type: array items: $ref: '#/components/schemas/CustomObjectType' CustomObjectType: type: object
See: https://swagger.io/docs/specification/data-models/data-types/#array