Swagger.io - post 方法中的引用数组
Swagger.io - array of refs in post method
我有一个关于如何使用 yaml 语法在 swagger 中定义引用数组的问题。我有以下定义我的字段的 yaml 片段:
- name: myfield
in: formData
description: 'description'
required: false
type: array
items:
$ref: '#/definitions/MyRef'
定义如下:
MyRef:
type: object
properties:
id:
type: integer
value:
type: string
description: the value for the myRef
在我的字段预览中,一切看起来都很好:
但是我得到了错误 "Not a valid parameter definition",在详细错误中我得到了 "Data does not match any schemas from 'oneOf'"。
我在文档中找不到类似的内容。那么什么是正确的结构或者我遗漏了什么?
那是因为 formData
可能 只有 包含基元或基元数组。您不能使用 $ref
作为 items
值。这将在下一版本的规范 (3.0) 中更改,但在 2.0 工具中不受支持,因为规范不允许。
我有一个关于如何使用 yaml 语法在 swagger 中定义引用数组的问题。我有以下定义我的字段的 yaml 片段:
- name: myfield
in: formData
description: 'description'
required: false
type: array
items:
$ref: '#/definitions/MyRef'
定义如下:
MyRef:
type: object
properties:
id:
type: integer
value:
type: string
description: the value for the myRef
在我的字段预览中,一切看起来都很好:
但是我得到了错误 "Not a valid parameter definition",在详细错误中我得到了 "Data does not match any schemas from 'oneOf'"。
我在文档中找不到类似的内容。那么什么是正确的结构或者我遗漏了什么?
那是因为 formData
可能 只有 包含基元或基元数组。您不能使用 $ref
作为 items
值。这将在下一版本的规范 (3.0) 中更改,但在 2.0 工具中不受支持,因为规范不允许。