Swagger - Set the "response" based on "consumes" -
is possible specify "response" based on "consumes" option on swagger?
my api can return "json" or "text" , i'd "example value", when response's status 200
changes if user selects response content type
option application/json
or text/plain
.
this piece of swagger.json
file:
{ "swagger": "2.0", "produces": [ "application/json", "text/plain" ], "consumes" : [ "application\/json" ], "paths": { "/writer/1/": { "get": { "summary": "get writers", "description": "writer description.", "tags": [ "writer" ], "responses": { "200": { "description" : "successful operation", "schema" : { "$ref" : "#\/definitions\/writerresponse" } }, } } } "definitions": { "writerresponse": { "properties": { "meta": { "type" :"object", "schema" : { "$ref" : "#\/definitions\/metadefinition" } }, "data": { "type" :"array", "items": { "$ref" : "#\/definitions\/writer" } } } }, "writer": { "properties": { "id": { "type": "integer", "description": "writer id.", "example": "1477" }, "short": { "type": "string", "description": "short description.", "example": "short example" }, "modified": { "type": "string", "description": "modified description.", "example": "2016-05-21 22:58:36" } } }, }
this example of json
output when user selects application/json
:
{ "meta": { "total": "1234", "last_page": "967", "per_page": "4000", "current_page": "1", "next_page_url": "http://localhost/api/<ws>/1?page=2", "prev_page_url": "http://localhost/api/<ws>/1?page=1", "from": "1", "to": "4000" }, "data": [ { "id": "1", "short": "test1", "modified": "2011-03-07 14:17:23" }, { "id": "5", "short": "test2", "modified": "2015-05-26 12:39:45" } ] }
and output when user selects text/plain
:
id|short|modified 1|test1|2011-03-07 14:17:23 5|test2|2015-05-26 12:39:45
Comments
Post a Comment