Forum Discussion

lia's avatar
lia
New Contributor
2 years ago

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. 

    • lia's avatar
      lia
      New Contributor

      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. ðŸ˜¸