swagger-api / swagger-api/swagger-codegen
[JAVA] Generated api client doesn't work for plain text body types
@HugoMario is already working on this.
Since Jul 17, 2018.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The generated API Client for Java does not work properly for plain string body types. The error message is:
io.swagger.client.ApiException: Content type "text/plain" is not supported
at io.swagger.client.ApiClient.serialize(ApiClient.java:749)
at io.swagger.client.ApiClient.buildRequest(ApiClient.java:994)
at io.swagger.client.ApiClient.buildCall(ApiClient.java:945)
at io.swagger.client.api.DefaultApi.addTodoCall(DefaultApi.java:103)
Swagger-codegen version
2.4.0
Swagger declaration file content or url
/todo:
post:
summary: Add new ToDo
description: ''
operationId: addTodo
consumes:
- text/plain
produces:
- application/json
parameters:
- in: body
name: body
required: false
schema:
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Task'
Command line used for generation
java -jar .\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i ..../swagger.json -l java -o outputpath
Suggest a fix/enhancement
add new else if in ApiClient.java in method public RequestBody serialize(Object obj, String contentType) throws ApiException:
} else if (obj instanceof String) {
return RequestBody.create(MediaType.parse(contentType), (String) obj);
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.
Assessment
This issue has not been assessed yet.