Dictionaries mapping strings to Array?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
Swagger Core
-
Swagger Editor
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, @ponelat, it totally solved my problem, it was exactly that. I thought that maybe an Array type would fit, but I had no idea how to specify the item's type. It seems very clear now. 😸
