OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] Generated files with option supportFilesToGenerate=false results in Compilation Errors
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I have following Maven Plugin set up:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>de.github.sparsick.openapi.spring.boot.contract.first.api</apiPackage>
<modelPackage>de.github.sparsick.openapi.spring.boot.contract.first.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
and the openapi.yaml is the pet store example
Then mvn clean compile results in
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project openapi-spring-boot-contract-first: Compilation failure: Compilation failure:
[ERROR] /home/sparsick/dev/workspace_github/openapi-spring-boot/contract-first/target/generated-sources/openapi/src/main/java/de/github/sparsick/openapi/spring/boot/contract/first/api/PetsApi.java:[79,21] cannot find symbol
[ERROR] symbol: variable ApiUtil
[ERROR] location: interface de.github.sparsick.openapi.spring.boot.contract.first.api.PetsApi
[ERROR] /home/sparsick/dev/workspace_github/openapi-spring-boot/contract-first/target/generated-sources/openapi/src/main/java/de/github/sparsick/openapi/spring/boot/contract/first/api/PetsApi.java:[108,21] cannot find symbol
[ERROR] symbol: variable ApiUtil
[ERROR] location: interface de.github.sparsick.openapi.spring.boot.contract.first.api.PetsApi
[ERROR] -> [Help 1]
My expectation is that the generator is generating everything what I need to compile the API and the model.
Workaround:
It works when I change my Maven plugin configuration in
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<apiPackage>de.github.sparsick.openapi.spring.boot.contract.first.api</apiPackage>
<modelPackage>de.github.sparsick.openapi.spring.boot.contract.first.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
openapi-generator version
openapi-generator-maven-plugin in version 4.3.0
OpenAPI declaration file content or url
Command line used for generation
Using following Maven plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>de.github.sparsick.openapi.spring.boot.contract.first.api</apiPackage>
<modelPackage>de.github.sparsick.openapi.spring.boot.contract.first.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Checkout https://github.com/sparsick/openapi-spring-boot
cd contract-first- Delete in
pom.xmlline<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate> - Uncomment in
pom.xmlline<generateSupportingFiles>false</generateSupportingFiles> - Run
mvn compile
Related issues/PRs
Suggest a fix
ApiUtil.java should be a part of the must have files.
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 Maven plugin configuration in the issue and the spring generator output, focusing on the generated PetsApi.java references to ApiUtil.java. Reproduce the failure with the linked pet store OpenAPI declaration by running mvn compile after disabling generateSupportingFiles. Done means the generated API and model compile without requiring the supportingFilesToGenerate workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design, build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100