swagger-api / swagger-api/swagger-codegen-generators
SpringCloud - Add a prefix for configuration files generated
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
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 MyApi 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...
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 spring-cloud generator templates that produce ApiKeyRequestInterceptor and ClientConfiguration, using the Maven configuration and generated class names in the issue as the entry point. Trace every generated reference to these classes, then verify that a configurable prefix renames the files and usages so multiple clients no longer create conflicting clientConfiguration beans.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100