首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用每个模块都有自己的Open规范来构建多模块级项目,并且父模块在构建时具有全部规范合并

如何使用每个模块都有自己的Open规范来构建多模块级项目,并且父模块在构建时具有全部规范合并
EN

Stack Overflow用户
提问于 2021-03-31 13:01:31
回答 1查看 186关注 0票数 2

我正在设计一个应用程序,应用程序应该将OpenAPI-3规范文件合并到一个文件中。考虑以下打开的api v3模式文件color.yaml和book.yaml color.yaml

代码语言:javascript
运行
复制
openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
- url: http://localhost:8080
  description: Generated server url
paths:
  /api/color/{name}:
    get:
      tags:
      - color-controller
      operationId: getColor
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Color'
components:
  schemas:
    Color:
      type: object
      properties:
        name:
          type: string
        red:
          type: integer
          format: int32
        green:
          type: integer
          format: int32
        blue:
          type: integer
          format: int32

book.yaml

代码语言:javascript
运行
复制
openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
- url: http://localhost:8080
  description: Generated server url
paths:
  /api/book/{name}:
    get:
      tags:
      - book-controller
      operationId: getBook
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Book'
components:
  schemas:
    Book:
      type: object
      properties:
        name:
          type: string
        iban:
          type: string

</code>

父模块应该将这些文件合并到一个主yaml规范文件

代码语言:javascript
运行
复制
**merged.yaml**



 openapi: 3.0.1
    info:
      title: My title
      version: 1.0.0-SNAPSHOT
    servers:
    - url: http://localhost:8080
      description: Generated server url
    paths:
      /api/book/{name}:
        get:
          tags:
          - book-controller
          operationId: getBook
          parameters:
          - name: name
            in: path
            required: true
            style: simple
            explode: false
            schema:
              type: string
          responses:
            "200":
              description: OK
              content:
                '*/*':
                  schema:
                    $ref: '#/components/schemas/Book'
      /api/color/{name}:
        get:
          tags:
          - color-controller
          operationId: getColor
          parameters:
          - name: name
            in: path
            required: true
            style: simple
            explode: false
            schema:
              type: string
          responses:
            "200":
              description: OK
              content:
                '*/*':
                  schema:
                    $ref: '#/components/schemas/Color'
    components:
      schemas:
        Book:
          type: object
          properties:
            name:
              type: string
            iban:
              type: string
        Color:
          type: object
          properties:
            name:
              type: string
            red:
              type: integer
              format: int32
            green:
              type: integer
              format: int32
            blue:
              type: integer
              format: int32

另外,当我对特定的子模块规范文件进行更改时,它应该反映在父规范文件中,并且应该显示在swagger中进行测试。

EN

回答 1

Stack Overflow用户

发布于 2022-08-22 07:27:25

关于您问题的合并部分:

您可以使用APIMatic的API规范合并特性首先使用合并你的规格,然后将合并的输出转换为OpenAPI的格式。以下是几个步骤:

  1. 按以下方式构造您的目录:
代码语言:javascript
运行
复制
dir\
  spec1\  
    color.yaml
  spec2\
    book.yaml
  APIMATIC-META.json
  1. 一个极简的APIMATIC-META.json看起来可以这样来启用合并:
代码语言:javascript
运行
复制
{
    "MergeConfiguration": {
        "MergedApiName": "My title",
        "MergeApis": true,
        "MergeSettings": {
          "SkipCodeGenValidation": true
       }
    }
}
  1. 将目录压缩,上传,并通过他们的网站将其转换为OpenAPI v3,以获得合并的输出。下面是一个链接,它提供了关于上传和执行转换的逐步指南:https://docs.apimatic.io/manage-apis/api-merging/#transforming-the-zipped-file

如果您想要自动化这个过程,APIMatic也有一个API:https://www.apimatic.io/docs/api#/http/api-endpoints/transformation/transform-via-file

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

https://stackoverflow.com/questions/66888421

复制
相关文章

相似问题

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