OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generate Java code with multiple enum values using allOf
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating the Java code with allOf and each item has a different value for the same enum, the multiples values are not combined in the result class.
openapi-generator version
openapi-generator-maven-plugin: 7.10.0
OpenAPI declaration file
openapi: "3.0.3"
info:
title: "Test enum"
version: "1.0.0"
paths:
/api/test:
post:
requestBody:
content:
pet:
schema:
$ref: "#/components/schemas/Pet"
responses:
"201":
description: "Created"
content:
pet:
schema:
$ref: "#components/schemas/Pet "
components:
schemas:
Pet:
allOf:
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
type: "object"
Dog:
type: "object"
additionalProperties: false
properties:
'type':
type: "string"
enum:
- "Dog"
age:
type: "string"
Cat:
type: "object"
additionalProperties: false
properties:
'type':
type: "string"
enum:
- "Cat"
name:
type: "string"
Generation Details
Java Maven plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.10.0</version>
<configuration>
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
<generatorName>spring</generatorName>
<configOptions>
<dateLibrary>java8</dateLibrary>
<oas3>true</oas3>
<annotationLibrary>none</annotationLibrary>
<documentationProvider>none</documentationProvider>
<containerDefaultToNull>true</containerDefaultToNull>
</configOptions>
</configuration>
</plugin>
Steps to reproduce
Just build the project.
Suggest a fix
The Pet class should be generated with the enum 'type' having the values Cat and Dog, but the Pet class has only one value for the enum Type.
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
Reproduce the issue with the provided OpenAPI declaration and the openapi-generator-maven-plugin using the Spring generator. Inspect the generated Pet class and the handling of the shared type enum across the Cat and Dog allOf references. Done means the generated enum contains both Cat and Dog values and the regression is covered by an appropriate generator test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100