swagger-codegen-generators
swagger-codegen-generators copied to clipboard
SpringCloud - Add a prefix for configuration files generated
When generating a Spring Boot client with
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.34</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/myapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/client</output>
<language>spring</language>
<library>spring-cloud</library>
<generateModels>true</generateModels>
<modelPackage>${clientBasePackage}.model</modelPackage>
<generateApis>true</generateApis>
<apiPackage>${clientBasePackage}.api</apiPackage>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<configOptions>
<configPackage>${clientBasePackage}.config</configPackage>
<dateLibrary>java11</dateLibrary>
<title>${api-name}</title>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
the generated files in the package config are always
├───config
│ ApiKeyRequestInterceptor.class
│ ClientConfiguration.class
It is a problem when I have multiple clients injected in the same Spring Boot application. In that case the application is not starting and complains about a conflict between beans with the same name (clientConfiguration).
Is it possible to add an option like <configPrefix>MyApi</configPrefix> allowing to have
├───config
│ MyApiApiKeyRequestInterceptor.class
│ MyApiClientConfiguration.class
And of course renaming all the usages within other generated files.
The only solution I found is to add
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-ApiKeyRequestInterceptor</id>
<phase>generate-sources</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/generated-sources/client/src/main/java/.../config/ApiKeyRequestInterceptor.java</sourceFile>
<destinationFile>${project.build.directory}/generated-sources/client/src/main/java/.../config/MyApiApiClientApiKeyRequestInterceptor.java</destinationFile>
</configuration>
</execution>
<execution>
<id>rename-ClientConfiguration</id>
<phase>generate-sources</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/generated-sources/client/src/main/java/.../config/ClientConfiguration.java</sourceFile>
<destinationFile>${project.build.directory}/generated-sources/client/src/main/java/.../config/MyApiApiClientConfiguration.java</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-for-ApiKeyRequestInterceptor</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.build.directory}/generated-sources/client/src/main/java/.../config</basedir>
<includes>
<include>**/*.java</include>
</includes>
<replacements>
<replacement>
<token>ApiKeyRequestInterceptor</token>
<value>MyApiApiClientApiKeyRequestInterceptor</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>replace-for-ClientConfiguration</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.build.directory}/generated-sources/client/src/main/java/...</basedir>
<includes>
<include>**/*.java</include>
</includes>
<replacements>
<replacement>
<token>ClientConfiguration</token>
<value>MyApiApiClientConfiguration</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
But it's really boring...
Added a pull request