OpenAPITools / OpenAPITools/openapi-generator
[BUG] instantiationTypes not taken into account
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
I want to instantiate a Set from a type: array in my OpenAPI file. The controller is correctly generated with a Set<MyType> types. However, the model is generated with a line this.mySet = new ArrayList();, causing a compile error.
I have the following in my pom.xml:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.1.0</version>
<executions>
<execution>
<id>generate-client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/../apidocs/technical/openapi.yml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<basePackage>com.mycompany.myproject.domain.api.gen</basePackage>
<modelPackage>com.mycompany.myproject.domain.api.gen.models</modelPackage>
<apiPackage>com.mycompany.myproject.domain.api.gen</apiPackage>
<configPackage>com.mycompany.myproject.domain.api.config</configPackage>
<dateLibrary>java17</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useTags>true</useTags>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
<modelNameSuffix>Dto</modelNameSuffix>
<typeMappings>
<typeMapping>array=Set</typeMapping>
</typeMappings>
<importMappings>
<importMapping>Set=java.util.Set</importMapping>
</importMappings>
<instantiationTypes>
<instantiationType>array=HashSet</instantiationType>
</instantiationTypes>
</configuration>
</execution>
</executions>
</plugin>
openapi-generator version
I'm using 7.1.0 and the issue was not present in 6.4.0.
OpenAPI declaration file content or url
Unfortunately, I can't paste code as it's confidential, but I'm more than happy to help troubleshoot this issue.
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I'm guessing the <instantionTypes> parameter is not read correctly, because it seems like the array is correctly understood as a Set in my controller.
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 Java Spring generator's model-generation path and the Maven configuration shown in the report, focusing on how typeMappings and instantiationTypes are consumed for array properties. Build a minimal OpenAPI reproduction because the original schema is unavailable, compare generated model output between 6.4.0 and 7.1.0, and define done as generating a Set field initialized with the configured HashSet.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100