You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用openapi-generator-maven-plugin生成模型接口而非实体类?

生成模型接口而非具体类(openapi-generator-maven-plugin 6.4.0)

interfaceOnly参数仅控制资源API接口的生成,不会改变模型类的生成逻辑。要生成模型接口,需要在configOptions中添加以下配置:

  • 开启模型接口生成:设置modelInterfaces为true
  • 配合开启接口优先:设置useInterfaces为true(部分语言模板需此参数生效)

完整的maven插件配置示例:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.4.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <!-- 填写你的OpenAPI spec路径、生成语言等基础配置 -->
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <modelInterfaces>true</modelInterfaces>
                    <useInterfaces>true</useInterfaces>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

注:如果使用非Java语言,需确认对应语言的模板是否支持modelInterfaces或类似参数,部分语言可能有专属的配置项。

内容的提问来源于stack exchange,提问作者nik0x1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 05:09:55