swagger-api / swagger-api/swagger-codegen
[JAVA] text/plain as response type throws exception
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I use the swagger-codegen-maven-plugin and POST to an endpoint which returns "text/plain", which is in the swagger 2.0 spec.
It throws this exception
"Content type "" + contentType + "" is not supported for type: " + returnType,
Content type plain/text;charset=UTF-8 is not supposed for type ..ResponseEntity
I kind of fixed this myself by adding this, though it isn't very pretty
} else if (isTextMime(contentType)) {
return (T) new ResponseEntity().body(respBody).statusCodeValue(response.code());
}
and my own isTextMime function
It's the deserialize function in the generated ApiClient that's failing.
- Deserialize response body to Java object, according to the return type and
- the Content-Type response header.
Swagger-codegen version
2.3.1 (I could not get 3.0.0 to run)
Swagger declaration file content or url
We had some issues with the swagger spec, but I got those devs to fix the issues, and it did not seem to help.
The base from the spec:
{"swagger":"2.0","info":{"description":"xx","version":"1",
"title":"xHub REST API","termsOfService":"none","contact":{"name":"none"},
"license":{"name":"none","url":"http://www.nolicense.com"}}
,"host":"xx:8051","basePath":"/",
"tags":[..],"schemes":["http"]
The request :
,"/testdata/xx/{env}/live/{live}"
:{"post":{"tags":["Testdata"],"summary":"","operationId":"","consumes":["application/json"],"produces":["text/plain"],
"parameters":[{"name":"env","in":"path","description":"env","required":true,"type":"string"},
{"name":"live","in":"path","description":"live","required":true,"type":"boolean"},
{"in":"body","name":"request","description":"request","required":true,"schema":{"$ref":"#/definitions/xxDTO"}}],
"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ResponseEntity"}},"201":{"description":"Created"},
"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}
Command line used for generation
Just the codegen plugin, generating model, api and supporting files
Steps to reproduce
Get "text/plain" as content-type in response to a request (a POST in my case)
Related issues/PRs
I could not find the same issue anywhere.. Although I feel like I'm doing something wrong..
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue points to the generated ApiClient's deserialize function; start there and trace handling of a text/plain response with a ResponseEntity return type. Reproduce the POST response described in the issue, then verify that deserialization no longer throws and returns the response body; no test file is named in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100