OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][webclient] UnsupportedMediaTypeException if multiple consumes media type and unknown type in first position
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
Template : Java/webclient
We generated client side code in Java/webclient mode for an api which define multiples media types in 'consumes' part. The swagger file is like the following (I omitted the unuseful parts) :
{
"swagger": "2.0",
"paths": {
"/mypath": {
"post": {
"operationId": "post",
"consumes": [
"application/json-patch+json",
"application/json",
"text/json",
"application/*+json"
],
"produces": [
"application/json"
]
}
}
}
}
The important thing is the order of the consumes list. The first value in the example is "application/json-patch+json". In this case, the execution of the generated webclient code throws the following error :
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json-patch+json' not supported for bodyType=MyObject
at org.springframework.web.reactive.function.BodyInserters.unsupportedError(BodyInserters.java:391)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
If the first value is "application/json", everything works fine.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
Generation Details
below our maven configuration to generate the java webclient code :
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>swagger</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<invokerPackage>${utilPackage}</invokerPackage>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>true</generateSupportingFiles>
<modelPackage>${modelPackage}</modelPackage>
<apiPackage>${clientPackage}</apiPackage>
<generatorName>java</generatorName>
<inputSpec>${project.basedir}/src/main/swagger/swagger.json</inputSpec>
<generateModelDocumentation>false</generateModelDocumentation>
<configOptions>
<library>webclient</library>
<serializableModel>true</serializableModel>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<performBeanValidation>true</performBeanValidation>
<useBeanValidation>true</useBeanValidation>
<serializationLibrary>jackson</serializationLibrary>
<serializableModel>true</serializableModel>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Related issues/PRs
Suggest a fix
In client-side, if a content-type is unknown, doesn't throw an exception and try the next one.
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 generated Java/webclient client produced by the Maven configuration and reproduce the issue using the shown consumes order. Trace how the client selects a request content type when the first type is unsupported; done means an unknown first type is skipped so a supported type is tried without UnsupportedMediaTypeException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100