yaml - OpenAPI:覆盖引用,引用单个字段
问题描述
我正在使用两个文件:
common.yaml
包含:
components:
schemas:
GenericError:
type: object
properties:
code:
description: The error code.
type: integer
message:
description: The error description.
type: string
details:
description: Optional details.
type: object
examples:
Bamboozled:
value:
code: 10
message: Bamboozled
details: You've been bamboozled
services.yaml` 包含:
paths:
/logistic:
post:
description: Logistic
responses:
403:
description: Forbidden
content:
application/json:
schema:
$ref: '../common.yaml#/components/schemas/GenericError'
examples:
Bamboozled:
value:
$ref: '../common.yaml#/components/examples/Bamboozled/value'
在services.yaml
中,我想覆盖该details
字段。我尝试了以下方法:
examples:
Bamboozled:
value:
$ref: '../common.yaml#/components/examples/Bamboozled/value'
details: my custom details
但这不起作用,它会呈现:
{
"$ref":
"#/paths/~1logistic/post/responses/403/content/application~1json/examples/Bamboozled/value",
"details": "my custom details"
}
有没有办法可以正确覆盖它?
或者,我可以仅引用特定字段吗?所以我会有services.yaml
一些东西,比如:
examples:
Bamboozled:
value:
$ref: '../common.yaml#/components/examples/Bamboozled/value/code'
$ref: '../common.yaml#/components/examples/Bamboozled/value/message'
details: my custom details
(这不起作用)
解决方案
推荐阅读
- arrays - 使用 JSON 自定义数组格式?
- c++ - 将类添加到相同类型的向量会导致错误。已弃用
- apollo-server - 需要多个 ApolloServer 来实现连接到 REST API 的网关?
- ios - 在 pkg-config 搜索路径中找不到通过 Homebrew 安装的软件包
- javascript - 添加到购物车时如何在 Wordpress/Woocommerce/Js 中禁用“滚动到顶部”动画/效果?
- html - HTML 行并排显示,而不是在列中垂直显示
- python - Pandas Plotting:如何在不手动绘制的情况下绘制多条线?
- magento2 - 将 UPC 属性添加到产品页面
- rust - 虽然 Rust 的 char 支持非英文字符,但很多文章推荐使用 string 来存储非英文字符,而不是 char。为什么?
- c++ - 将模板指针转换为 char 指针时 C++ 不执行代码