Forum Discussion

AndyTGardner's avatar
AndyTGardner
New Contributor
6 years ago

Defining Nested Data in Response Schema

I'm trying to define a schema for a response in the Yaml for my API and this includes a field being an array of sub data. My Yaml is as follows: PPOdata: type: object properties: ...
  • RonRatovsky's avatar
    6 years ago

    You should add 'type: object' to the internal items array:

     

            items:
              type: object
              additionalProperties:
                type: object
                properties:
                  ModuleName:
                    type: string
                    example: latency
                  ModuleSettings:
                    type: string
                    example: Min 0, Max 10
    

    While the definition is valid, itt doesn't actually produce the result you'd expect. When you don't specify a type, it means that any type can be used (string, array, object, number...). The 'additionalProperties' will only take effect if the actual used value is an object, but in other cases it will be ignored. Having that definition does not implicitly set the type to be object.