Forum Discussion

johndorazio's avatar
johndorazio
New Contributor
5 years ago

nesting in XML representation

I can't figure out how to correctly represent nested arrays in XML. My API's current JSON response is an object with three properties, of which the first is an array of objects with properties, the s...
  • HKosova's avatar
    5 years ago

    You need to define the "results" property as a wrapped array (xml.wrapped = true) and also specify xml.name for both the "results" array and the array items. See the Representing XML guide for details.

    components:
      schemas:
        RootElement:
          type: object
          properties:
            results:
              type: array
              items:
                $ref: '#/components/schemas/result'
              xml:
                name: results
                wrapped: true
              # Optional array example
              example:
                - property1: 1
                  property2: 4
                  property3: stringvalue
                - property1: 0
                  property2: 16
                  property3: stringvalue2
        result:
          type: object
          xml:
            name: result
          properties:
            property1:
              type: integer
              xml:
                attribute: true
            property2:
              type: integer
              xml:
                attribute: true
            property3:
              type: string
              xml:
                attribute: true