JSON API examples in Swagger 2.0

Salsaparapizza picture Salsaparapizza · Jul 16, 2015 · Viewed 11.9k times · Source

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

Answer

Saúl Martínez Vidals picture Saúl Martínez Vidals · Jul 29, 2015

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