OpenAPITools / OpenAPITools/openapi-generator

[REQ] Honor MIME types specified in body Content-Type header

Open
#5,218 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Several of the generators we've used (rust, typescript-axios, swift5) forcefully serialize and deserialize request/response bodies to JSON irrespective of the setting of the Content-Type header. For example, see this needsSerialization declaration, which serializes to JSON any body argument that is not a string, when the underlying library, axios, will happily handle native types that correspond to useful MIME types like image/*, etc.

This leaves me in a bind as an API designer: either use correct MIME types that tools like cURL and Postman handle well and forego meaningful code generation, or forego external, code-agnostic testing and diagnostic tools, and get code that works on shallow application/json-based objects that have MIME-types embedded in them.

Describe the solution you'd like

I'd like to be able to use native MIME types where appropriate and useful.

Describe alternatives you've considered

Modeling media as shallow objects that will encode to application/json, just for the purposes of code-generation.

Additional context

Really, this is a philosophical question about how the owners see this tool being used. Should I file defects when I encode MIME types and they are not respected, as detailed above? Should I just make peace with the trade-offs, as described, and choose as best I can?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache, especially the needsSerialization declaration, and compare how the rust and swift5 generators handle body serialization. Clarify which generators and MIME types are in scope, then verify generated clients preserve native body handling according to Content-Type rather than forcing JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust, swift, typescript
Domain
api, backend-api-design, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.