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>
相关推荐
皮皮林55114 小时前
Java性能调优黑科技!1行代码实现毫秒级耗时追踪,效率飙升300%!
java
冰_河14 小时前
QPS从300到3100:我靠一行代码让接口性能暴涨10倍,系统性能原地起飞!!
java·后端·性能优化
桦说编程17 小时前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
躺平大鹅19 小时前
Java面向对象入门(类与对象,新手秒懂)
java
初次攀爬者20 小时前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺20 小时前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
Derek_Smart21 小时前
从一次 OOM 事故说起:打造生产级的 JVM 健康检查组件
java·jvm·spring boot
NE_STOP1 天前
MyBatis-mybatis入门与增删改查
java
孟陬1 天前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端