我有 2 个架构和一个示例。我想使用下拉菜单更改请求主体。
实际上一切都正常。我有一个显示示例的列表,并且仅当我将示例写为“value”时,RequestBody 中的值才会更改。如果我将示例指定为 ref,则会加载第一个示例,但当下拉列表中的值发生变化时不会显示第二个示例。
这难道只是没有实现,这是一个错误还是我做错了什么/配置了什么?
配置示例:
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{"$ref": "#/components/schemas/reportexample1"},
{"$ref": "#/components/schemas/reportexample2"}
]
},
"examples": {
"reportexample1": {
"summary": "reportexample1",
"$ref": "#/components/schemas/reportexample1"
},
"reportexample2": {
"summary": "reportexample2",
"$ref": "#/components/schemas/reportexample2"
}
}
}
}
},
......
"components": {
"schemas": {
"reportexample1": {
"type": "object",
"properties": { .... }
},
"reportexample2": {
"type": "object",
"properties": { .... }
}
}
}
$ref
要在中使用,必须在部分中定义examples
参考示例并使用示例对象语法。components/examples
examples
无法引用模式(#/components/schemas/...
) – 这就是您的原始代码片段不起作用的原因。尝试这个:
Artur May 的答案中建议的内联示例方法也将起作用。
您可以尝试直接在示例部分中定义示例,而不是使用 $ref 引用它们。
像这样: