Swagger - 设置"响应"基于"消费"

时间:2016-08-08 10:50:47

标签: swagger

是否可以指定"响应"基于"消费" Swagger上的选项?

我的API可以返回" json"或"文字"如果用户从200中选择Response Content Type选项application/json,那么,如果响应的状态为text/plain,那么"示例值"就会发生变化}或swagger.json

这是我的{ "swagger": "2.0", "produces": [ "application/json", "text/plain" ], "consumes" : [ "application\/json" ], "paths": { "/writer/1/": { "get": { "summary": "Get all 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" } } }, } 文件的一部分:

JSON

当用户选择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" } ] } 输出的示例
text/plain

这是用户选择id|short|modified 1|TEST1|2011-03-07 14:17:23 5|TEST2|2015-05-26 12:39:45 时的输出:

mywinsCount

0 个答案:

没有答案