Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #476
Closed
Open
Issue created Jul 05, 2018 by Administrator@rootContributor

java: Content-Type: application/json on GET requests

Created by: lorenzleutgeb

Description

GET requests usually have no body, and therefore most of the time no Content-Type header is transferred. The OpenAPI makes it especially hard (probably impossible) to define one, as I have noted in OAI/OpenAPI-Specification#1628

I only ran into this issue because I observed that the Java client generated by this generator used Content-Type: application/json and I could not explain why. After some searching I think I found the cause for this rather strange behaviour.

In api.mustache (line highlighted) you call ApiClient#selectHeaderContentType (line highlighted) for all types of requests. Since (by validity of the input spec) there are no content types for GET requests, you will always default to application/json. That's bad, and for example makes it impossible to describe JSON API and get a Java client in a straightforward way.

The workaround that I used is an interceptor like this:

if ("GET".equals(request.method()) && request.header("Content-Type") != null) {
  System.err.println("We attempt to send a content type on a GET request! Removing it forcibly!");

  request = request.newBuilder()
    .removeHeader("Content-Type")
    .build();
}
openapi-generator version

020883fd (master from 2018-07-04)

OpenAPI declaration file content or url

Use ping.yaml.

Command line used for generation

java -jar openapi-generator-cli.jar generate -g java -i api.yml -o jclient

Steps to reproduce

Generate client.

Related issues/PRs

See Description.

Suggest a fix/enhancement

Do not attempt to even infer a content type for a GET request.

Assignee
Assign to
Time tracking