Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a response object with an array in YAML using Swagger Editor

I'm working on an API definition in Swagger Editor with YAML. I am trying to represent the following response body:

{
    success: true,
    ids: [123456, ...]
}

and this is what my YAML looks like:

definitions:
  SuccessfulResponse:
    type: object 
    properties:
      success:
        type: boolean
        description: True if the all operations were successful
      ids:
        type: array
        items: 
          id: 
          type: string 

Ive tried several different ways but like this but nothing seems valid

enter image description here

How do I properly describe the return object that Ive given above?

like image 575
Wesley Smith Avatar asked Nov 07 '16 05:11

Wesley Smith


People also ask

How do you specify an array in swagger?

Firstly, we start by specifying the array of strings in Swagger using YAML notation. In the schema section, we include type: array with items String.

How define array type in YAML?

An array is a group of similar values with a single name. In YAML, Array represents a single key mapped to multiple values. Each value starts with a hyphen - symbol followed by space. In a single line, write the same thing above using 'square brackets syntax.


1 Answers

Here is an example to define a property as an array of string:

  photoUrls:
    type: array
    items:
      type: string

Ref: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml#L661-L667

like image 155
William Cheng Avatar answered Oct 12 '22 21:10

William Cheng