首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用springdoc-openapi-maven插件和swagger-codegen-maven-plugin生成客户端代码?

如何使用springdoc-openapi-maven插件和swagger-codegen-maven-plugin生成客户端代码?
EN

Stack Overflow用户
提问于 2021-01-18 23:43:10
回答 1查看 1.8K关注 0票数 1

我的目标是使用3.0生成Spring客户端。

我想首先生成API的OpenAPI规范文件(Springdoc Plugin),然后使用Maven从这个文件(swagger-codegen-maven-plugin)生成客户端代码。

我的问题是swagger-codegen-maven-plugin是在springdoc-openapi-maven-plugin.之前执行的因此,当springdoc-openapi-maven-plugin执行swagger-codegen-maven-plugin时,swagger-codegen-maven-plugin生成的输出文件不存在。

给定以下Maven构建插件配置,如何在springdoc-openapi-maven-plugin之前执行swagger-codegen-maven-plugin?

我的Maven构建插件配置:

代码语言:javascript
复制
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <apiDocsUrl>myServerUrl:myPort/v3/api-docs</apiDocsUrl>
                    <outputFileName>openApiFile.json</outputFileName>
                    <outputDir>${project.basedir}/src/main/resources</outputDir>
                    <skip>false</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.24</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openApiFile.json</inputSpec>
                            <language>typescript-angular</language>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-21 22:28:43

问题是springdoc-openapi-maven-plugin是在integration-test阶段执行的,而swagger-codegen-maven-plugin默认阶段是generate-sources,它在构建生命周期中在integration-test之前执行。

我刚刚为swagger-codegen-maven-plugin指定了一个阶段,它在integration-test<phase>post-integration-test</phase>之后。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65783600

复制
相关文章

相似问题

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