如何使用 springdoc-openapi-maven-plugin 和 swagger-codegen-maven-plugin 生成客户端代码?
How to generate client code using springdoc-openapi-maven-plugin and swagger-codegen-maven-plugin?
我的目标是 使用 OpenAPI 3.0..
生成 Spring 引导 REST 客户端
我想首先生成我的API和[=21]的OpenAPI规范文件(springdoc-openapi-maven-plugin) =]然后 使用 Maven 从这个文件 (swagger-codegen-maven-plugin) 生成客户端代码。
我的问题是 swagger-codegen-maven-plugin 在 springdoc-openapi-maven-plugin 之前执行。所以,springdoc-openapi-maven-plugin生成的输出文件在swagger-codegen-maven-plugin执行时不存在。
给定以下 Maven 构建插件配置,如何在 swagger-codegen-maven-plugin 之前执行 springdoc-openapi-maven-plugin ?
我的 Maven 构建插件配置:
<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>
问题是 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>
.
我的目标是 使用 OpenAPI 3.0..
生成 Spring 引导 REST 客户端我想首先生成我的API和[=21]的OpenAPI规范文件(springdoc-openapi-maven-plugin) =]然后 使用 Maven 从这个文件 (swagger-codegen-maven-plugin) 生成客户端代码。
我的问题是 swagger-codegen-maven-plugin 在 springdoc-openapi-maven-plugin 之前执行。所以,springdoc-openapi-maven-plugin生成的输出文件在swagger-codegen-maven-plugin执行时不存在。
给定以下 Maven 构建插件配置,如何在 swagger-codegen-maven-plugin 之前执行 springdoc-openapi-maven-plugin ?
我的 Maven 构建插件配置:
<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>
问题是 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>
.