问题:我想重用一个定义。一旦直接进入对象内部。以下代码有效但来自http://editor.swagger.io/#/的验证器说“不是有效的响应定义”并指向“200”行。
我真的必须两次定义帐户吗?或者这是验证者的问题吗?
* responses:
* 200: <---- ERROR POINTING HERE
* description: Updated account
* schema:
* type: object
* properties:
* data:
* type: object
* properties:
* account:
* schema:
* $ref: '#/definitions/Account'
定义本身:
"Account" : {
"type" : "object",
"required": [
"id", "username", "lastname", "firstname", "traderid", "customerid", "company", "validated"
],
"properties": {
"id": {
"type": "string"
},
"username" : {
"type": "string"
},
"lastname" : {
"type": "string"
},
"firstname" : {
"type": "string"
},
"traderid" : {
"type": "string"
},
"customerid" : {
"type": "string"
},
"company" : {
"type": "string"
},
"validated" : {
"type": "boolean"
}
},
"example" : {
"id": "57790fdde3fd3ed82681f39c",
"username": "yuhucebafu",
"validated": false,
"customerid": "57790fdce3fd3ed82681f39a"
}
},
答案 0 :(得分:4)
问题在于schema
属性中使用account
。
200:
description: Updated account
schema:
type: object
properties:
data:
type: object
properties:
account:
schema: # <-- Problem is here.
$ref: '#/definitions/Account'
以下是更正后的回复定义:
200:
description: Updated account
schema:
type: object
properties:
data:
type: object
properties:
account:
$ref: '#/definitions/Account'
属性名称&#34;架构&#34;仅用作Swagger response object中的顶级属性,或in
properties/[propertyName]
设置为&#34; body&#34;。
一旦您开始指定架构,该架构中的所有内容大多数都遵循标准parameter object,这是高度递归的。例如:
items
的值都是架构。/definitions/[name]
的值是架构。allOf
的值都是架构。anyOf
,oneOf
或additionalProperties
中每个数组元素的值都是架构。schema
的值可以是架构(或布尔值)。你明白了。在所有这些情况下,JSON Schema都没有使用属性名称{
"code":200,
"message":"Success",
"data":"[{\"userName\":\"admin\",\"roleId\":\"SYS_ADMIN\",\"fullName\":\"Bibek Shakya\",\"emailId\":\"bibek@drose.com.np\",\"mobileNumber\":\"9843598726\",\"landLineNumber\":\"014323565\",\"picture\":\"index.jpg\"}]"}
,因为它会在一种语言中引入很多噪声,实际上#34;一切都是模式。&#34;