admin管理员组文章数量:1430142
I have a swagger tag document using the Swagger UI that always returns text/html but it should return application/json. The POST requests and every other type returns application/json but this particular GET request does not. The service end point code is correct. And if I change the request to POST it does return as application/json. So it is just type GET within swagger which does not return the correct type. Any thoughts how to correct the call within the UI to use the application/json?
This is swagger version 2.1.4 that was downloaded recently from the swagger site.
"/bankName": {
"get": {
"summary": "Bank Name Search",
"description": "Bank Name Search, input routing number to return bank name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"name": "routingNumber",
"description": "Input Bank Routing Number",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "An array",
"schema": {
"type": "object",
"properties": {
"errorInfo": {
"$ref": "#/definitions/ErrorInfo"
},
"bankName": {
"type": "string",
}
}
}
},
"400": {
"description": "Invalid Request Input supplied"
},
"500": {
"description": "General Unexpected Error"
}
}
}
}
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:9086
Origin:http://localhost:9086
Pragma:no-cache
Referer:http://localhost:9086/swagger/index.html
Here is the Java code Spring Restful definition:
@RequestMapping(value="bankName",
method=RequestMethod.GET,
produces=MediaType.APPLICATION_JSON_VALUE)
I have a swagger tag document using the Swagger UI that always returns text/html but it should return application/json. The POST requests and every other type returns application/json but this particular GET request does not. The service end point code is correct. And if I change the request to POST it does return as application/json. So it is just type GET within swagger which does not return the correct type. Any thoughts how to correct the call within the UI to use the application/json?
This is swagger version 2.1.4 that was downloaded recently from the swagger site.
"/bankName": {
"get": {
"summary": "Bank Name Search",
"description": "Bank Name Search, input routing number to return bank name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"name": "routingNumber",
"description": "Input Bank Routing Number",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "An array",
"schema": {
"type": "object",
"properties": {
"errorInfo": {
"$ref": "#/definitions/ErrorInfo"
},
"bankName": {
"type": "string",
}
}
}
},
"400": {
"description": "Invalid Request Input supplied"
},
"500": {
"description": "General Unexpected Error"
}
}
}
}
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:9086
Origin:http://localhost:9086
Pragma:no-cache
Referer:http://localhost:9086/swagger/index.html
Here is the Java code Spring Restful definition:
@RequestMapping(value="bankName",
method=RequestMethod.GET,
produces=MediaType.APPLICATION_JSON_VALUE)
Share
Improve this question
edited Apr 27, 2016 at 8:44
ADreNaLiNe-DJ
4,9194 gold badges27 silver badges35 bronze badges
asked Apr 6, 2016 at 13:04
Berlin BrownBerlin Brown
11.8k38 gold badges140 silver badges213 bronze badges
12
- 3 why your get has "consumes"? – Junbang Huang Commented Apr 18, 2016 at 3:17
- 2 GET requests do not have content-type as they do not have body. – Tamas Hegedus Commented Apr 23, 2016 at 13:56
-
1
I guess there is problem in your API response. Can you check if your
GET
API response content-type is application/json? – emil Commented Apr 26, 2016 at 1:01 -
4
Please elaborate how a request in the Swagger UI can "return" anything and what you mean by "correcting the call within the UI". Since the Swagger UI will only display the spec nicely and allow to send requests accordingly, but doesn't control what is returned by the server, it doesn't make sense to me at the moment. Is the problem that the server returns the wrong content type or Swagger UI just displays it wrong? If you, for example, manually use the CURL mand the UI creates in a shell (add
-i
param for headers), what is returned then? Can you copy the CURL mand and its result here? – CherryDT Commented Apr 26, 2016 at 10:55 - 2 Swagger UI is just a tool for designing and documenting an API. It seems like the problem may be in the framework/code where your API is implemented. Do you have two functions where one handles the POST request and a second handles the GET request? – drsnark Commented Aug 4, 2017 at 19:27
1 Answer
Reset to default 1Have you tried this?
"/bankName": {
"get": {
"summary": "Bank Name Search",
"description": "Bank Name Search, input routing number to return bank name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"name": "routingNumber",
"description": "Input Bank Routing Number",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "An array",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errorInfo": {
"$ref": "#/definitions/ErrorInfo"
},
"bankName": {
"type": "string",
}
}
}
}
}
},
"400": {
"description": "Invalid Request Input supplied"
},
"500": {
"description": "General Unexpected Error"
}
}
}
}
本文标签:
版权声明:本文标题:javascript - Swagger 'GET' request always returns as texthtml Accept type on response and NOT applicationjson - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745508989a2661380.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论