pra*_*one 8 python java yaml openapi
我正在寻找一些解决方案,或者可能是一些脚本,可以帮助我通过模式验证替换($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
Run Code Online (Sandbox Code Playgroud)
输出:所有 $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
Run Code Online (Sandbox Code Playgroud)
你能建议一下吗?
这里有一些工具声称除了外部 $refs 之外还能够取消引用内部 $refs。请注意循环 $refs 的潜在问题。
命令行界面:
https://github.com/APIDevTools/swagger-cli
swagger-cli bundle --dereference <file>
Run Code Online (Sandbox Code Playgroud)
openapi bundle --dereferenced --output <outputName> --ext <ext> [entrypoints...]
Run Code Online (Sandbox Code Playgroud)
图书馆:
resolvefullyresolveInternal