Forum Discussion

jeremyfiel's avatar
jeremyfiel
Visitor
5 years ago

API Design: XML response returns a nested array

I'm having difficulty writing a definition for an XML response object which includes two strings and an array of integers in the same parent element.

 

```yml

Element:
type: array
description: returns a list of report ID's
required:
- result
- title
- dogs
properties:
result:
description: Server Response
type: string
name:
description: blah
type: string
items:
$ref: '#/components/schemas/name'
title:
description: Report ID
type: array
items:
$ref: '#/components/schemas/title'
xml:
wrapped: true

```

```xml

<element>

      <name>jeremy</name>

      <title>designer</title>

      <dogs>tito</dogs>

      <dogs>burrito</dogs>

      <dogs>cheeto</dogs>

</element>

```

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Jeremy,

    Your example

     

    <element>
      <name>jeremy</name>
      <title>designer</title>
      <dogs>tito</dogs>
      <dogs>burrito</dogs>
      <dogs>cheeto</dogs>
    </element>

     

    can be defined as follows:

     

    components:
      schemas:
        element:
          type: object
          properties:
            name:
              type: string
              example: jeremy
            title:
              type: string
              example: designer
            dogs:
              type: array
              items:
                type: string
              xml:
                wrapped: false
              example:
                - tito
                - burrito
                - cheeto

     

    See also Representing XML.