[英]How to combine two components using allOf in openapi yaml specification?
[英]OpenAPI Specification (YML/YAML) : All $refs replace or expand to its definition (with schema validation)
我正在寻找一些解决方案或者一些脚本,可以帮助我在 YML 文件中使用模式验证替换($ref)或扩展其定义。 (详情请看下面的例子)
**示例:使用 $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
Output:所有 $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 的潜在问题。
命令行界面:
https://github.com/APIDevTools/swagger-cli
swagger-cli bundle --dereference <file>
openapi bundle --dereferenced --output <outputName> --ext <ext> [entrypoints...]
图书馆:
resolvefully
选项resolveInternal
选项的oas-resolver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.