New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAVA] Generated api client doesn't work for plain text body types #8288

Open
Kiolali opened this Issue Jun 6, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@Kiolali

Kiolali commented Jun 6, 2018

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);
@sknick

This comment has been minimized.

sknick commented Jul 17, 2018

I can confirm this is an issue.

@HugoMario HugoMario self-assigned this Jul 17, 2018

@november1306

This comment has been minimized.

november1306 commented Jul 25, 2018

@HugoMario
hi, any news about this issue?

@Kiolali
did you found a suitable workaround to use plain/text in body?

@Kiolali

This comment has been minimized.

Kiolali commented Jul 26, 2018

yes! I used the suggested fix (add new else if in ApiClient.java in method public RequestBody serialize(Object obj, String contentType) throws ApiException;)

@HugoMario

This comment has been minimized.

Contributor

HugoMario commented Aug 8, 2018

hey @november1306, i'm really busy right now with other codegen issues. if somebbody else can propose a PR , it would be really appreciated.

@sknick

This comment has been minimized.

sknick commented Sep 12, 2018

@HugoMario I don't do swagger-codegen development, so I'm not really set up to run everything, but I've committed a bare bones PR with the change identified in it. Can you grab it and finish it out?

@HugoMario

This comment has been minimized.

Contributor

HugoMario commented Sep 12, 2018

thanks @sknick, i'll take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment