Swagger-codegen: [Java, java8,resttemplate] Generated code doesn't compile when System property 'supportingFiles' is set to 'false'

Created on 7 Jan 2019  路  4Comments  路  Source: swagger-api/swagger-codegen

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.

Most helpful comment

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

All 4 comments

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?

Was this page helpful?
0 / 5 - 0 ratings