Swagger 招摇过市语法:如何从可重用响应引用模型定义
在这里大摇大摆的新手。我已经看过了,据我所知,我下面的例子应该是有效的 我的响应类型只是不同结构的数组(这些结构在全局定义部分中定义,以减少膨胀,因为它们可能是嵌套的,因此可以重用) 以下是我的定义:Swagger 招摇过市语法:如何从可重用响应引用模型定义,swagger,swagger-2.0,swagger-editor,Swagger,Swagger 2.0,Swagger Editor,在这里大摇大摆的新手。我已经看过了,据我所知,我下面的例子应该是有效的 我的响应类型只是不同结构的数组(这些结构在全局定义部分中定义,以减少膨胀,因为它们可能是嵌套的,因此可以重用) 以下是我的定义: consumes: - application/json produces: - application/json schemes: - http swagger: '2.0' [...Additional details excluded...] paths: /first:
consumes:
- application/json
produces:
- application/json
schemes:
- http
swagger: '2.0'
[...Additional details excluded...]
paths:
/first:
get:
responses:
'200':
$ref: '#/responses/response1'
/second:
get:
responses:
'200':
$ref: '#/responses/response2'
definitions:
ObjectA:
type: object
properties:
listOfObjBs:
type: array
items:
$ref: '#/definitions/ObjectB'
ObjectB:
type: object
properties:
listOfObjCs:
type: array
items:
$ref: '#/definitions/ObjectC'
ObjectC:
description: A build
type: object
properties:
someNumericData:
type: integer
format: int64
responses:
response1:
description: There are 2 types of responses, this is the first kind.
schema:
type: object
headers:
data:
type: array
items:
$ref: '#/definitions/ObjectA'
response2:
description: This is the second kind.
schema:
type: object
headers:
data:
type: array
items:
$ref: '#/definitions/ObjectC'
然而,我在swagger web编辑器中遇到了验证问题
响应['response1']处出现架构错误。标题['data']。项应
没有其他属性AdditionalProperty:$ref
响应.response1.headers.data.items.$ref items处出现语义错误
$refs无法匹配以下任何一项:“#/definitions”,
“#/参数”
响应['response2']处出现架构错误。标题['data']。项应
没有其他属性additionalProperty:$ref
response2.headers.data.items.$ref items处的语义错误
$refs无法匹配以下任何一项:“#/definitions”,
“#/参数”
看起来我使用的json引用不正确,但我不知道为什么
我还尝试将response1和response2放在definitions部分并直接引用它们(例如,将路径下的$ref直接指向“#/definitions/response1”,而不是“#/response1”)。但是我从编辑那里得到一个错误,说我不能直接引用定义
构造此定义的正确方法是什么?具有主体的响应具有
schema
。要引用模型定义,请使用$ref
引用作为模式的值
:
响应:
答复1:#