Nidhin David
Nidhin David

Reputation: 2474

Define array of different objects with max count 5 in swagger

I have completed a Node.js app using LINE APIs.I have the following request object. How can I define the array of different objects, here the messagesfield which contains different object structure for different message types. I hope swagger permits this very common scenario.

Request Body:

    {
            "to": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "messages":[
                {
                    "type":"text",
                    "text":"Hello, world1"
                },
                {
                     "type": "audio",
                     "originalContentUrl": "https://example.com/original.m4a",
                     "duration": 240000
                }
                {
                     "type": "location",
                     "title": "my location",
                     "address": "〒150-0002 東京都渋谷区渋谷2丁目21−1",
                     "latitude": 35.65910807942215,
                     "longitude": 139.70372892916203
                }
            ]
        }

My swagger definition for messages array.

"Messages Object": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "$ref": "#/definitions/multicast Message Error Response"
          },
          {
            "$ref": "#/definitions/multicast Message Error Response"
          }
        ]
      }
    }

And this is the rendered messages array. It has only one entry. I want to include many different entries

"messages": [
    {
      "code": 500,
      "httpCode": 400,
      "name": "string",
      "message": "string"
    }
  ]

Upvotes: 2

Views: 859

Answers (0)

Related Questions