asim
asim

Reputation: 1

How to describe a model in Swagger for an array with simple objects?

I have a REST service to document, and some of them accept simple array like:

[
  { "name":"a" },
  { "class":"b" },
  { "hello":"c" }
]
How do I describe this in the Swagger yaml model section? I can only create 'is_sellerarray' like
{
  "is_seller": [
    {
      "name": "string",
      "asim": "string"
    }
  ]
}

Upvotes: 0

Views: 245

Answers (1)

Ramesh KC
Ramesh KC

Reputation: 582

You can define your own array type. Your Pet object will have name and asim as two attributes. Follow documents for more information. https://swagger.io/docs/specification/data-models/

type: array
items:
  $ref: '#/components/schemas/Pet'

You can play around online swagger editor to see real time changes. https://editor-next.swagger.io/

Upvotes: 0

Related Questions