OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][JAVASCRIPT] When request body have multiple content types, method for only one content type is created
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
When a path have multiple content types in its request body, only a single method is created for a single content. Which makes it to not be able to create request for non generated content types, especially if they have different schema. According to OpenAPI spec, request body can have multiple content types. Openapi-Generator also have an example spec file with multiple content type with different schema.
Expected behaviour is separate method for each content type is generated.
openapi-generator version
Tried with both 7.2 and 7.3
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: "1"
title: Multiple Content Types for same request
paths:
/multiplecontentpath:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/coordinates'
mutlipart/form-data:
schema:
type: object
properties:
coordinates:
$ref: '#/components/schemas/coordinates'
file:
type: string
format: binary
responses:
201:
description: Successfully created
headers:
Location:
schema:
type: string
components:
schemas:
coordinates:
type: object
required:
- lat
- long
properties:
lat:
type: number
long:
type: number
Using this spec, method for only application/json will be created. If you put the mutipart/form-data first, only method for multipart will be created.
Generation Details
inputSpec: multiple-content.yaml
outputDir: feign
generatorName: java
additionalProperties:
library: feign
inputSpec: multiple-content.yaml
outputDir: jersey3
generatorName: java
additionalProperties:
library: jersey3
I have also tried native, helidon, micronaut for java, all resulting same problem. For curiosity tried typescript-fetch and android, this also resulted is a single method.
Steps to reproduce
- Generate code using the provided OpenAPI spec and configuration.
- Check generated source codes for API.
Related issues/PRs
Suggest a fix
I am not sure what is wrong. But it might be something problematic in higher up in the generation chain. As not only the java but also JavaScript, android generator had the same problem. Other generator might have the same problem which I did not look into.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided multiple-content.yaml reproduction and the existing modules/openapi-generator/src/test/resources/3_0/content-data.yaml example, then run the Java and JavaScript generation configurations from the issue. Trace the shared request-body handling used by those generators. Done means generated APIs expose a separate method for each request content type and the reproduction confirms both schemas remain usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100