swagger-api / swagger-api/swagger-codegen
[JAVA] swagger-codegen-maven-plugin - configuration for java code generation leads to missing files
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Swagger-codegen version
2.4.12
Description
First of all: I'm new to swagger. I've just added the swagger-codegen-maven-plugin and I'm a little bit confused about how to correctly use it.
We've just got an YAML with API specifications and swagger should be used to generate sources from it. Adding the plugin and enabling the properties as documented works but unfortunately lot of trash is generated which is not needed in our project (pom.xml, AndroidManifest.xml etc.). The used configuration (version from plugin-management: 2.4.12):
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger-file.yaml</inputSpec>
<language>java</language>
<configOptions>
<sourceFolder>generated-java</sourceFolder>
</configOptions>
<apiPackage>xyz.rest.api</apiPackage>
<invokerPackage>xyz.rest.invoker</invokerPackage>
<modelPackage>xyz.rest.model</modelPackage>
<output>${project.basedir}/src/main</output>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<!--configHelp>true</configHelp--> <!-- prints help -->
</configuration>
</execution>
</executions>
</plugin>
So far so good since everything compiles and works. Due to long work with the JAXB Maven plugin we wanted to remove those unused files and found the property generateSupportingFiles and supportingFilesToGenerate. Disabling generateSupportingFiles immediately leads to compile failure since the invoker and auth package is not generated anymore (which looks like a bug to me since files that are needed for compiling shouldn't be marked as "supporting files").
However, trying to add all those files back again seems to lead to adding each single file to supportingFilesToGenerate (no wildcard etc. supported and no keywords?)? Unfortunately there is no further documentation and only stuff we could find in the web shows examples where all files are added one after another.
Another problem is that after adding those files we now have again other files that were not added but will be generated:
- .swagger-codegen-ignore (everything commented out but generated)
- .swagger-codegen (directory containing the file "VERSION")
- src/main (directory that would contain AndroidManifext.xml - not generated... only the directory)
- gradle/wrapper (directory which would contain gradle - not generated... only the directory)
Plugin configuration:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger-file.yaml</inputSpec>
<language>java</language>
<configOptions>
<sourceFolder>generated-java</sourceFolder>
</configOptions>
<apiPackage>xyz.rest.api</apiPackage>
<invokerPackage>xyz.rest.invoker</invokerPackage>
<modelPackage>xyz.rest.model</modelPackage>
<output>${project.basedir}/src/main</output>
<supportingFilesToGenerate>ApiCallback.java,ApiClient.java,ApiException.java,ApiResponse.java,Configuration.java,Pair.java,ProgressRequestBody.java,ProgressResponseBody.java,StringUtil.java,ApiKeyAuth.java,Authentication.java,HttpBasicAuth.java,JSON.java,OAuth.java</supportingFilesToGenerate>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<!--configHelp>true</configHelp--> <!-- prints help -->
</configuration>
</execution>
</executions>
</plugin>
I guess that something in our configuration is wrong to achieve what we want to achieve so any assistance would be much appreciated. We haven't tried Swagger 3.x yet since the YAML file references a Swagger 2 version.
Best regards,
Marco
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 by reproducing the swagger-codegen 2.4.12 Maven plugin configuration with the referenced Swagger YAML and compare output with generateSupportingFiles disabled and supportingFilesToGenerate populated. Investigate how supporting files, required invoker/auth classes, and generated directories such as .swagger-codegen are selected. Done means the configuration behavior and the unwanted generated artifacts are corrected or clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100