如何在 Maven 中将多个 OpenAPI 3.0 规范文件合并为一个?

发布于 2025-01-15 04:36:25 字数 637 浏览 4 评论 0原文

在使用 Spring Boot 的 Maven 项目中,有多个 OpenAPI 3.0 规范文件。一个规范定义了所有 HTTP 错误 (errors.yml),并且 error.yml 的组件在其他规范中引用。 我想生成一个输出规范,其中包含 error.yml 的所有组件。

输入规范:

  schema:
    $ref: "errors.yml#/components/schemas/Error"

希望的输出规范:

schema:
  $ref: "#/components/schemas/Error"
  ...
Error:
  ...

我可以使用 swagger-codegen-cli 来完成:

java -Dfile.encoding=UTF-8 -jar swagger-codegen-cli-3.0.33.jar generate -l openapi-yaml -i search-api-contract/target/expert_api.yml -o . -DoutputFile=search-api-contract/target/expert_api.yml

如何使用 Maven pom.xml 生成一个规范?

In a Maven project with Spring Boot, there are several OpenAPI 3.0 specification files. One spec defines all HTTP errors (errors.yml), and the components of errors.yml are referenced in other spec.
I want to generate an output spec with all components of errors.yml inside.

Input spec:

  schema:
    $ref: "errors.yml#/components/schemas/Error"

Wished output spec:

schema:
  $ref: "#/components/schemas/Error"
  ...
Error:
  ...

I can do it with swagger-codegen-cli:

java -Dfile.encoding=UTF-8 -jar swagger-codegen-cli-3.0.33.jar generate -l openapi-yaml -i search-api-contract/target/expert_api.yml -o . -DoutputFile=search-api-contract/target/expert_api.yml

How to generate one spec with Maven pom.xml?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2025-01-22 04:36:25

Swagger Codegen 有一个 Maven 插件< /a>.你可以这样使用它:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.33</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>path/to/main/openapi.yaml</inputSpec>

                <!-- Use 'openapi-yaml' to get resolved YAML or 'openapi' to get resolved JSON -->
                <language>openapi-yaml</language>

                <!-- Default is ${project.build.directory}/generated-sources/swagger -->
                <output>path/to/output/folder</output>

                <configOptions>
                    <!-- Default output file name is 'openapi.yaml' or 'openapi.json' -->
                    <outputFile>myapi.yaml</outputFile>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

Swagger Codegen has a Maven plugin. You can use it like this:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.33</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>path/to/main/openapi.yaml</inputSpec>

                <!-- Use 'openapi-yaml' to get resolved YAML or 'openapi' to get resolved JSON -->
                <language>openapi-yaml</language>

                <!-- Default is ${project.build.directory}/generated-sources/swagger -->
                <output>path/to/output/folder</output>

                <configOptions>
                    <!-- Default output file name is 'openapi.yaml' or 'openapi.json' -->
                    <outputFile>myapi.yaml</outputFile>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文