首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenApi 3.0.2 \x\x\x{e76f}\x{e76f}\x{e76f}/控制器接口命名

OpenApi 3.0.2 \x\x\x{e76f}\x{e76f}\x{e76f}/控制器接口命名
EN

Stack Overflow用户
提问于 2019-08-26 08:52:59
回答 1查看 4.2K关注 0票数 7

我正在尝试为OpenApi 3.0.2规范编写生成的服务器端Spring代码。

这是其中一条“小路”的样子:-

代码语言:javascript
复制
paths:
  /api/v1/int/integrations/{some-path-variable}/some-action:
    get:
      summary: Summary
      description: How to change the generated Api/Controller class name?
      operationId: methodName
      tags:
        - inventory
      parameters:
        - name: Authorization
      other details....

使用Maven插件生成服务器端代码,该插件配置为:-

代码语言:javascript
复制
    <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>               
        <version>4.1.0</version>           

        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/open-api/myapi.yaml</inputSpec>
                    <generatorName>spring</generatorName>
                    <library>spring-boot</library>
                    <output>${project.build.directory}/generated-openapi/spring</output>
                    <generateApis>true</generateApis>
                    <addCompileSourceRoot>true</addCompileSourceRoot>
                    <artifactVersion>${project.version}</artifactVersion>
                    <groupId>com.company.division</groupId>
                    <artifactId>myapi-api</artifactId>
                    <generateApiTests>true</generateApiTests>
                    <modelPackage>com.company.division.myapi.generated.model</modelPackage>
                    <apiPackage>com.company.division.myapi.generated.api</apiPackage>
                    <generateApiDocumentation>true</generateApiDocumentation>

                    <configOptions>
                        <dateLibrary>java8</dateLibrary>
                        <java8>true</java8>
                        <interfaceOnly>true</interfaceOnly>
                        <reactive>false</reactive>
                        <useBeanValidation>true</useBeanValidation>
                        <performBeanValidation>true</performBeanValidation>
                        <useOptional>false</useOptional>
                        <serviceInterface>true</serviceInterface>
                        <serviceImplementation>false</serviceImplementation>
                    </configOptions>
                </configuration>

            </execution>
        </executions>
    </plugin>

从插件配置中可以看到,我只是在生成模型类和Spring接口/ API接口方面进行了干预。

问题

对于上述的OpenAPI规范,生成的MVC控制器惰性面被命名为ApiApi。我猜这是从这条路的起始部分衍生出来的。我可以去掉/api/v1/int部件,但它将生成名为IntegrationsApi的接口,但我不想命名它,比如InventoryApi。我们有什么选择来控制生成的控制器接口?

EN

回答 1

Stack Overflow用户

发布于 2019-08-31 06:28:21

“useTags”创建接口和控制器类名

在插件配置中设置useTags configOption解决了我的问题:

代码语言:javascript
复制
<configuration>
    <configOptions>
        <useTags>true</useTags>
        <dateLibrary>java8</dateLibrary>
        <java8>true</java8>
        <interfaceOnly>true</interfaceOnly>
        <reactive>false</reactive>
        <useBeanValidation>true</useBeanValidation>
        <performBeanValidation>true</performBeanValidation>
        <useOptional>false</useOptional>
        <serviceInterface>true</serviceInterface>
        <serviceImplementation>false</serviceImplementation>
    </configOptions>
</configuration>
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57654685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档