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
  • #9831
Closed
Open
Issue created Jun 22, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][PYTHON] Content-Type: application/json on GET(also HEAD,DELETE) requests

Created by: johnboyes

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The same problem as #476, #1061 is also occurring in Python.

The Python generator makes the default Content-Type application/json for all HTTP methods (including GET, HEAD and DELETE), whereas there should never be a Content-Type set for GET, HEAD and DELETE.

This causes a problem with other tools/servers that insist that GET, HEAD and DELETE requests do not have a Content-Type (as per the OpenAPI 3 specification).

An example of the problem is when using Prism as a validation proxy.

Prism rejects any GET request that has a Content-Type.

Here is an example of the problem manifesting itself.

openapi-generator version

master 969cea8c (21 June, 2021) and latest release at time of filing this issue v5.1.1

Not a regression, this is a long-standing issue.

OpenAPI declaration file content or url

Any GET, HEAD or DELETE request generated from any OpenAPI spec via the Python generator.

Generation Details

Standard Python config

Steps to reproduce
  1. Start with any OpenAPI3 spec e.g. the Petstore example at https://editor.swagger.io/
  2. Generate Python client code for the spec using the standard Python generator
  3. Look at the generated rest.py e.g. in the standard sample in this repo and see that the Content-Type defaults to application/json for all HTTP methods (including GET, HEAD and DELETE), rather than there being no Content-Type for GET, HEAD and DELETE.
Related issues/PRs

#476, #1061, #5941, #6167

Suggest a fix

The fix looks straightforward and I am happy to submit a PR.

Proposed fix is to amend the rest.mustache so that the Content-Type is left unset for GET, HEAD and DELETE requests, e.g.

if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']:
  if 'Content-Type' not in headers:
    headers['Content-Type'] = 'application/json'

instead of the existing

if 'Content-Type' not in headers:
    headers['Content-Type'] = 'application/json'
Assignee
Assign to
Time tracking