如何在 Maven 的 openapi-generator-maven-plugin 中自定义 ApiClient 类名?

问题描述 投票:0回答:1

我在 Maven 项目中使用 openapi-generator-maven-plugin 来生成基于 OpenAPI 规范的客户端。生成的客户端默认包含一个名为 ApiClient 的类,位于 com.somthing.java.api_client.generate 包中。我需要将此 ApiClient 类重命名为 HelloworldApiClient 以遵守我们的项目命名约定。 这是我的 pom.xml 配置的相关部分:

<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.build.directory}/${open-specification.path}</inputSpec>
        <generatorName>java</generatorName>
        <library>feign</library>
        <generateApiTests>false</generateApiTests>
        <generateModelTests>false</generateModelTests>
        <apiPackage>com.somthing.spring.api_client.generated.api</apiPackage>
        <modelPackage>com.somthing.somthing.api_client.generated.model</modelPackage>
        <configOptions>
          <useJakartaEe>true</useJakartaEe>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>

有没有办法直接配置插件或提供额外的配置将

ApiClient
类重命名为
HelloworldApiClient
?或者,是否有任何涉及脚本或自定义生成器模板的最佳实践或解决方法可以实现此结果?

任何关于自定义生成的客户端名称的指导或见解,特别是对于

ApiClient
类,我们将不胜感激。

spring-boot openapi openapi-generator openapi-generator-maven-plugin
1个回答
0
投票

也许使用后缀适合您?

<configuration>
   <apiNameSuffix>NameSuffix</apiNameSuffix>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.