[Java, java8,resttemplate] Generated code doesn't compile when System property 'supportingFiles' is set to 'false'
Description
I integrate swagger-codegen-maven-plugin's goal 'generate' into my Maven build and use following configuration:
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.json</inputSpec>
<language>java</language>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<library>resttemplate</library>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
Calling mvn clean package produces a failing build with following output
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.685 s
[INFO] Finished at: 2019-01-07T15:13:51+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project swagger-playground: Compilation failure: Compilation failure:
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[3,25] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: package io.swagger.client
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[29,13] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.StoreApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[36,21] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.StoreApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[40,12] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.StoreApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[44,30] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.StoreApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[3,25] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: package io.swagger.client
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[31,13] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.PetApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[38,19] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.PetApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[42,12] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.PetApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[46,30] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.PetApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[3,25] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: package io.swagger.client
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[29,13] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.UserApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[36,20] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.UserApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[40,12] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.UserApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[44,30] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.UserApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/StoreApi.java:[32,18] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.StoreApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[34,18] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.PetApi
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[149,72] package ApiClient does not exist
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/PetApi.java:[186,72] package ApiClient does not exist
[ERROR] /home/sparsick/dev/workspace_github/swagger-playground/target/generated-sources/swagger/src/main/java/io/swagger/client/api/UserApi.java:[32,18] cannot find symbol
[ERROR] symbol: class ApiClient
[ERROR] location: class io.swagger.client.api.UserApi
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
When I change the property 'generateSupportingFiles' to true, the build is successful.
In case <generateSupportingFiles>false</generateSupportingFiles> following Java Classes are not generated:
- io.swagger.client.ApiClient.java
- io.swagger.client.RFC3339DateFormat.java
- io.swagger.client.auth.ApiKeyAuth.java
- io.swagger.client.auth.Authentication.java
- io.swagger.client.auth.HttpBasicAuth.java
- io.swagger.client.auth.OAuth.java
- io.swagger.client.auth.OAuthFlow.java
Swagger-codegen version
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
Swagger declaration file content or url
https://petstore.swagger.io/v2/swagger.json
Command line used for generation
git clone https://github.com/sparsick/swagger-playground
cd swagger-playground
mvn clean package
Steps to reproduce
see above
Related issues/PRs
Suggest a fix/enhancement
If you confirm that this is a bug, I could try to fix it.
For me the following workaround works:
<generateSupportingFiles>false</generateSupportingFiles>
<environmentVariables>
<supportingFiles>ApiClient.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,RFC3339DateFormat.java</supportingFiles>
</environmentVariables>`
In my opinion the mentioned files are supporting files .. but their non-existence must not prevent from compiling the others
Thank you for the workaround. It works for me, too. :+1:
My understanding of supporting files is that they are optional. In this case, their absence breaks the build, so it seems they are mandatory and IMHO it means that they are not supporting files.
I'd thought of a losely coppeling between ApiClient and actual Api files. But that'd result in only having models and two non usable client files so i agree that these should be generated. Would be interesting to see how other libraries approach this.
Still facing this. Any thoughts?
anything? this is incredibly frustrating
To me this looks conceptually broken. Any generator/library should know which files it absolutely requires and it should (force-)generate those regardless of what generateSupportingFiles and supportingFilesToGenerate say. Just stumbled upon this myself.
This is really frustrating. If we have:
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<invokerPackage>${default.package}.invoker</invokerPackage>
and
<generateApis>true</generateApis>
<generateModels>true</generateModels>
then, using the same logic, we should also have the possibility to configure
<generateInvoker>true</generateInvoker>
Then
<generateSupportingFiles>false</generateSupportingFiles>
could refer to all the other (non-Java) files as most of us probably understand it.
This way we could easily generate a complete java client without the actual "SupportingFiles".
I came across this as well. From the documentation, its not clear that the invoker java classes needed by the API classes are actually created as supporting files. Is there any interest in fixing this? The use case is where we don't want the supporting files to be generated that are not java classes, but we need the java classes for using the invoker packages.
Please someone knows how properly set only api and model packages outside target/gen-sources as defult, for example inside main/java etc.. keeping unnecessary files out and without adding allowed files atribute... tia