OpenAPITools使用——FAQ

FAQ

Q1:为什么生成的Controller接口中没有@Controller注解

建议排查配置项configOptionsuseSpringController是否为true

xml 复制代码
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
    <execution>
        <!--其他配置...-->
        <configuration>
            <!--其他配置...-->
         	<generateApiDocumentation>false</generateApiDocumentation>
         	<generateModelDocumentation>false</generateModelDocumentation>
         	<generateSupportingFiles>false</generateSupportingFiles>
            <configOptions>
                <useSpringController>false</useSpringController>
            </configOptions>
        </configuration>
    </execution>
</executions>

Q2:服务端代码生成时如何防止pom文件被覆盖

可以配置openapiGeneratorIgnoreListpom.xml防止覆盖

xml 复制代码
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
    <execution>
        <!--其他配置...-->
        <configuration>
            <!--其他配置...-->
            <openapiGeneratorIgnoreList>pom.xml</openapiGeneratorIgnoreList>
            <configOptions>
            	<!--其他配置...-->
            </configOptions>
        </configuration>
    </execution>
</executions>

Q3:客户端代码生成时禁用API文档生成

在客户端代码生成时同步生成了api接口文档,如何禁用?

建议排查配置项configurationgenerateApiDocumentation是否为false。如何不想生成任何文档,建议将generateApiDocumentation,generateModelDocumentation都设置为false

  • generateApiDocumentation:是否生成 API 接口相关文档
  • generateModelDocumentation:生成数据模型相关文档
xml 复制代码
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
    <execution>
        <!--其他配置...-->
        <configuration>
            <!--其他配置...-->
         	<generateApiDocumentation>false</generateApiDocumentation>
         	<generateModelDocumentation>false</generateModelDocumentation>
            <configOptions>
            <!--其他配置...-->
            </configOptions>
        </configuration>
        </configuration>
    </execution>
</executions>

Q4:客户端代码生成时禁用Gradle等生成

使用maven构建时,默认生成了gradle的配置文件

建议排查配置项configurationgenerateSupportingFiles设置为false,但是需要自己手动补全一些文件如ApiClient

xml 复制代码
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
    <execution>
        <!--其他配置...-->
        <configuration>
            <!--其他配置...-->
         	<generateSupportingFiles>false</generateSupportingFiles>
            <configOptions>
            <!--其他配置...-->
            </configOptions>
        </configuration>
        </configuration>
    </execution>
</executions>
相关推荐
kfyty7258 分钟前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎10 分钟前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄11 分钟前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
忆~遂愿31 分钟前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略
java·大数据·linux·人工智能
小韩学长yyds40 分钟前
Java序列化避坑指南:明确这4种场景,再也不盲目实现Serializable
java·序列化
仟濹42 分钟前
【Java基础】多态 | 打卡day2
java·开发语言
Re.不晚42 分钟前
JAVA进阶之路——无奖问答挑战2
java·开发语言
Ro Jace2 小时前
计算机专业基础教材
java·开发语言
Libraeking2 小时前
破壁行动:在旧项目中丝滑嵌入 Compose(混合开发实战)
android·经验分享·android jetpack
mango_mangojuice2 小时前
Linux学习笔记(make/Makefile)1.23
java·linux·前端·笔记·学习