OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Not compilable code generated when oneOf refs to an array type
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 oneOf refs to an array type, then the generated code is not compilable. java.util.List isn't imported and other compile time errors emerge.
openapi-generator version
6.0.1 maven plugin. I don't know if it's a regression as I've never had same situation with previous versions.
OpenAPI declaration file content or url
oneOf:
- type: string
- $ref: '#/components/schemas/my_array'
my_array:
type: array
items: {}
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/my-api.yaml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<library>native</library>
<dateLibrary>java8</dateLibrary>
<serializationLibrary>jackson</serializationLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
mvn compile
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/8765
https://github.com/OpenAPITools/openapi-generator/issues/6015
https://github.com/OpenAPITools/openapi-generator/issues/5997
Suggest a fix
The generated code semantically is fine in human POV. Likely a bit change in compiler will make it syntactically fine too.
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 supplied OpenAPI YAML and the openapi-generator-maven-plugin configuration using generatorName java; run mvn compile to reproduce the generated-code failure. Compare the generated Java for the oneOf array reference with the expected imports and compilation errors, then verify that the generated client compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100