Skip to content

[JAVA] Bug: Feign client applies Content-Type header when no request body is present #6647

@bmordue

Description

@bmordue
Description

Requests with no body parameters (ie, no request body) should not include a Content-Type header. It's not necessary, and it could cause problems with parsing the request at the server side.

Swagger-codegen version

2.3.0 (90010da)

Swagger declaration file content or url
swagger: '2.0'
basePath: /
schemes:
  - http
paths:
  '/toggle':
    post:
      summary: Toggle the switch
      description: If switch is off, toggle to on, and vice versa.
      responses:
        200:
          description: Success
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
    -i example.yaml \
    -l java \
    --library feign \
    -o $OUTPUT_DIR
Steps to reproduce

Generate a Java client using the Feign library using an API spec that includes a POST path with no body parameters. Use the client to make a request, and observe that the request has a "Content-Type" header.

Related issues/PRs

Issue #5613, fixed in #5616.

Suggest a fix/enhancement

Only add a Content-Type header is body parameters are specified: #6648

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions