1

Is it possible to add the Response Content Type select box without creating the Response Class (Status 200) schema?

My web services return JSON or XML format depending on the accept header. I need this dropdown after that.

Sampada
  • 2,931
  • 7
  • 27
  • 39
John
  • 4,711
  • 9
  • 51
  • 101

1 Answers1

2

You can populate the valued for the 'Response Content Type' dropdown with the produces property of the Swagger definition:

---
swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
produces:
  - application/xml
  - application/json
paths:
  /:
    get:
      responses:
        200:
          description: OK

You'll eventually need to define your response schema as well, but that definition can be independent of the response content type (json vs xml).

Pang
  • 9,564
  • 146
  • 81
  • 122
anyarms
  • 349
  • 1
  • 8
  • can you please tell me, if my api returns json data so what would be the annotation for getting xml and json both content type?? – lazyCoder Jul 11 '16 at 14:17
  • 1
    If your API returns json data only, just specify the json line in the 'produces'. If you can produce either json or xml, use the example above. – anyarms Jul 12 '16 at 15:39
  • 1
    In the controller how do you get what response content-type is selected? – user1930591 Jun 20 '17 at 21:53