Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON API examples in Swagger 2.0

I'm trying to create example responses for an endpoint with Swagger 2.0.

    200:
      description: Successful response
      schema:
        type: object
        $ref: "#/definitions/User"
      examples:
        application/vnd.api+json:
            - data:
                attributes:
                  full_name: John Appleseed
            - data:
                attributes:
                  full_name: Mike Appleseed

My api consumes and produces application/vnd.api+json, but it won't recognize it. If I delete the examples, my spec works. Any idea how to specify it?

error

like image 703
Salsaparapizza Avatar asked Jul 16 '15 15:07

Salsaparapizza


1 Answers

It is not fully implemented yet, although you can define one single example like this:

   responses:
    "200":
      description: Successful response
      schema: 
        $ref: '#/definitions/User'
      examples:
        application/json:
          data:
            id: 1
            attributes:
              attr1: value1
              attr2: value2

there is one bug related with the mime-type, you cannot use dots thats why I did not put application/vnd.api+json

like image 73
Saúl Martínez Vidals Avatar answered Oct 08 '22 00:10

Saúl Martínez Vidals