I am trying to generate classes automatically from swagger-codegen-maven-plugin (version 3.0.8) and (group Id: io.swagger.codegen.v3) like below. Code generation works great however I want to change name of Generated ApiClient to something like PREFIX+ApiClient (EXAMPLE: customApiClient where custom is prefix).
<build>
<finalName>cdm-customer-servicing-api-client</finalName>
<plugins>
<plugin>
<!-- This 2019 version is required for OpenAPI 3 -->
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.8</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/spec.json</inputSpec>
<language>java</language>
<apiPackage>*****.client.api</apiPackage>
<modelPackage>*******. client.model</modelPackage>
<configOptions>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<artifactVersion>${project.version}</artifactVersion>
<library>resttemplate</library>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<licenseName>Apache 2.0</licenseName>
<licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
</configOptions>
<additionalProperties>
<property></property>
</additionalProperties>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
</configuration>
</execution>
</executions>
</plugin>
Above definition generates models, apis specified in YML spec, no issues there. It also generates ApiClient.java which is autowired in all API classes. I want to change name of ApiClient.java to add some prefix or suffix.
Reason is: I do have 2 spec in service and I want to ensure that ApiClient from one service does not override another ApiClient.
Let me know if someone has a luck.
It can be done implementing a custom generator that extends
JavaClientCodegen.java
../gradlew clean openApiMeta
(couldn't find a mvn equivalent)org.openapitools.codegen.CustomJavaGenerator
resources/customjava/CustomApiClient.mustache
and replace every instance ofApiClient
(case sensitive) as shownpublic class {{customApiClientPrefix}}ApiClient { ...
Package and install the project so it appears on mavenLocal repo as e.g.
customjava-openapi-generator-1.0.0.jar
.Generate the code, in this case, with gradle.
Add the custom jar to the classpath and the
openApiGenerate
config to gradle.build. Should be similar for maven../gradlew clean openApiGenerate