我正在寻找一些解决方案或者一些脚本,可以帮助我通过模式验证替换($ref)或扩展其在 YML 文件中的定义。 (具体请看下面的例子)
**示例:使用 $ref 输入 **
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
输出:所有 $ref 替换或扩展为其定义(使用模式验证)
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
default:
description: unexpected error
content:
application/json:
schema:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
你能建议一下吗?
这里有一些工具声称除了外部 $refs 之外还能够取消引用内部 $refs。请注意循环 $refs 的潜在问题。
CLI:
-
https://github.com/APIDevTools/swagger-cli https://github.com/APIDevTools/swagger-cli
swagger-cli bundle --dereference <file>
-
Redocly OpenAPI CLI https://redoc.ly/docs/cli/commands/#how-to-make-a-fully-dereferenced-bundle
openapi bundle --dereferenced --output <outputName> --ext <ext> [entrypoints...]
图书馆:
- Java: Swagger 解析器 https://github.com/swagger-api/swagger-parser与resolvefully https://github.com/swagger-api/swagger-parser#2-resolvefully option
- 节点.js:oas 解析器 https://github.com/Mermade/oas-kit/tree/master/packages/oas-resolver与resolveInternal https://github.com/Mermade/oas-kit/blob/master/docs/options.md option
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)