swagger-ui not displaying details on some methods
Hi! I got this method:
@RequestMapping(value = PING_RESOURCE_PATH, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(notes = "will return 'pong'", value = "ping")
@ResponseBody
public String ping() {
return "pong";
}
swagger-spring is generating this:
"path": "/rest/dev/ping",
"description": "RESTful API for debugging operations",
"operations": [
{
"httpMethod": "GET",
"summary": "ping",
"notes": "will return 'pong'",
"deprecated": false,
"responseClass": "String",
"nickname": "ping"
}
]
Swagger-ui will execute the request but not show response or information:

I have another method (error) that always returns a 400 and its working fine. Some other methods as well. Must have to do with the triviality :)
Hi, I believe the issue is, you're telling swagger that you're going to produce content-type application/json but you're really returning a string. The proper fix is to set the @Produces annotation to include "text/plain", which be produced by the spring-mvc integration.
So I'd change your sample to return proper json.
Well... You may be right about the slightly incorrect spring configuration but when you look at the json its expecting type String, no? Also the request is successfully executed and returning "pong". By the way: if I use an older version of swagger-ui its working flawlessly... Regards.
The following is not valid JSON:
"pong"
The following is valid JSON:
{ "ping": "pong" }
However, the UI should be able to handle return values that are not JSON/XML. There needs to be a way to specify the return value as a simple string (content type of "text/plain") if there isn't already.
...maybe the UI should treat all unknown "responseClass" values (those with no matching models) as text/plain?
"pong" IS valid JSON it's just not an object
I'm sorry but according to the spec you're right, just looked it up... http://www.json.org/
The UI will definitely handle the text/plain response type. But if you tell it that it's json, it will fail to parse.
See here for an example of sending response type:
http://petstore.swagger.wordnik.com/api/api-docs/pet
produces: [
"application/json",
"application/xml"
]
Currently, swagger-ui supports json, xml, text and html responses.
A String is valid Json I think. Spring/Jackson does not moan about it as well. The method response value is serialized by jackson and it does nothing to the string. I am also pretty sure that this worked before in previous swagger-ui versions.
According to the website mentioned above, only arrays and objects are valid JSON (as a whole).
The array is a list of values. The object (hash table) contains mapped key/value pairs. Values can be strings, numbers, objects, arrays, booleans or nulls. Keys can only be strings.
Anything else that makes up a value (string, number, boolean, null) or anything that makes up a string or number is apparently not valid JSON (unless put together with other parts to make a valid JSON object or array).
please reopen if you feel this is still an issue