我正在设计一个应用程序,应用程序应该将OpenAPI-3规范文件合并到一个文件中。考虑以下打开的api v3模式文件color.yaml和book.yaml color.yaml
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
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规范文件中
**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中进行测试。
发布于 2022-08-22 07:27:25
关于您问题的合并部分:
您可以使用APIMatic的API规范合并特性首先使用合并你的规格,然后将合并的输出转换为OpenAPI的格式。以下是几个步骤:
dir\
spec1\
color.yaml
spec2\
book.yaml
APIMATIC-META.json
APIMATIC-META.json
看起来可以这样来启用合并:{
"MergeConfiguration": {
"MergedApiName": "My title",
"MergeApis": true,
"MergeSettings": {
"SkipCodeGenValidation": true
}
}
}
如果您想要自动化这个过程,APIMatic也有一个API:https://www.apimatic.io/docs/api#/http/api-endpoints/transformation/transform-via-file
https://stackoverflow.com/questions/66888421
复制相似问题