OpenAPITools / OpenAPITools/openapi-generator
[BUG] Description openapi-generator can't build AnyOf object that contains an empty value using Java (openapi: 3.1.0)
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?
- 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
openapi-generator version
7.14.0
When I am trying the generate the below openAPI definition, it does not correctly build the anyOf object. This openAPI definition is from a third party company that we are trying to integrate with.
"CustomMetric": {
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"description": {
"type": "string",
"title": "Description"
},
"value": {
"anyOf": [
{
},
{
"type": "null"
}
],
"title": "Value"
}
},
"type": "object",
"required": [
"name",
"description",
"value"
],
"title": "CustomMetric"
}
Generation Details
mvn clean generate-sources
mvn clean test
<configuration>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<artifactVersion>${project.version}</artifactVersion>
<generatorName>java</generatorName>
<library>resttemplate</library>
<generateApis>false</generateApis>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<licenseName>Apache 2.0</licenseName>
<licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<openApiNullable>false</openApiNullable>
<useJakartaEe>false</useJakartaEe>
<useOneOfInterfaces>false</useOneOfInterfaces>
<legacyDiscriminatorBehavior>true</legacyDiscriminatorBehavior>
</configOptions>
</configuration>
Steps to reproduce
Related issues/PRs
Suggest a fix
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 OpenAPI 3.1.0 schema and the Maven configuration using the Java generator and resttemplate library; run mvn clean generate-sources to inspect the generated CustomMetric model. Confirm the handling of the anyOf containing an empty schema and null, then run mvn clean test; done means generation and tests complete with the expected model behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100