Api 蓝图因 dredd 实时失败 api?
Api blueprint failing with dredd on a realtime api?
我正在将 dredd 从 1.08 升级到最新版本,同时我正在尝试验证我们的 api 文档,该文档是用实时测试 api 和它失败了。
由于测试 运行 是针对实时 api,从 api 返回的响应包含与 blurprint 文档中指定的值不同的值。我从 dredd 收到以下错误。
有人可以帮我解决吗? :)
body: At '/data/email' No enum match for: "dredd_testzz@keyflow.se"
body: At '/data/firstName' No enum match for: "Sniper"
body: At '/data/lastName' No enum match for: "Wolf"
body: At '/data/verified' No enum match for: false
## `ResponseSchema` (object)
+ email: `john.doe@example.com` (string, required) - Email address
+ firstName: John (string, required) - First name
+ lastName: Doe (string, required) - Last name
+ verified: true (boolean, required) - True
# Group Account
## Login [/login/?]
Login user
### Login [POST]
Authentication required.
+ Request (application/json)
+ Attribute (LoginInputSchema)
+ Response 200 (application/json; charset=UTF-8)
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
dredd生成的JSON模式如下
bodySchema: {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "number",
"enum": [
200
]
},
"data": {
"type": "object",
"properties": {
"email": {
"type": "string",
"enum": [
"john.doe@example.com"
],
"description": "Email address of the guest."
},
"firstName": {
"type": "string",
"enum": [
"John"
],
"description": "First name of the guest."
},
"lastName": {
"type": "string",
"enum": [
"Doe"
],
"description": "Last name of the guest."
},
"verified": {
"type": "boolean",
"enum": [
true
],
"description": "The user is verified or not"
},
},
"required": [
"email",
"firstName",
"lastName",
"verified",
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
]
}
TL;DR: 尝试在 API 蓝图文档中使用 fixed-type
而不是 fixed
。 fixed
要求样本值是实际值。
更详尽的解释:
body: At '/data/email' No enum match for: "dredd_testzz@keyflow.se"
这意味着被测服务器返回的响应包含可正确解析的 JSON 正文,但根据 API 描述提供的架构,正文无效。
错误指向/data/email
,也就是说{"data": {"email": ...
属性有问题。此外,它提到 enum
的值是预期的,并且实际响应包含 dredd_testzz@keyflow.se
,这是枚举不允许的。其他错误类似。
查看 API 描述,响应中预期的规范如下:
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
MSON 规范的 fixed
attribute, as explained in the 4.3 Nested Member Types 部分不仅修复了结构,还修复了所有值,并进一步向下传播数据结构:
...MAY specify fixed to indicate a "value object" where all the properties MUST be present and the values of the properties MUST be the values specified, if any, in its Nested Member Types. Further, such an object type structure MUST NOT contain any other properties.
我想你想使用 Dredd 文档的 fixed-type
instead, which fixes just the structure. This is further explained also in the Making Dredd Validation Stricter 部分。
我正在将 dredd 从 1.08 升级到最新版本,同时我正在尝试验证我们的 api 文档,该文档是用实时测试 api 和它失败了。
由于测试 运行 是针对实时 api,从 api 返回的响应包含与 blurprint 文档中指定的值不同的值。我从 dredd 收到以下错误。
有人可以帮我解决吗? :)
body: At '/data/email' No enum match for: "dredd_testzz@keyflow.se"
body: At '/data/firstName' No enum match for: "Sniper"
body: At '/data/lastName' No enum match for: "Wolf"
body: At '/data/verified' No enum match for: false
## `ResponseSchema` (object)
+ email: `john.doe@example.com` (string, required) - Email address
+ firstName: John (string, required) - First name
+ lastName: Doe (string, required) - Last name
+ verified: true (boolean, required) - True
# Group Account
## Login [/login/?]
Login user
### Login [POST]
Authentication required.
+ Request (application/json)
+ Attribute (LoginInputSchema)
+ Response 200 (application/json; charset=UTF-8)
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
dredd生成的JSON模式如下
bodySchema: {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "number",
"enum": [
200
]
},
"data": {
"type": "object",
"properties": {
"email": {
"type": "string",
"enum": [
"john.doe@example.com"
],
"description": "Email address of the guest."
},
"firstName": {
"type": "string",
"enum": [
"John"
],
"description": "First name of the guest."
},
"lastName": {
"type": "string",
"enum": [
"Doe"
],
"description": "Last name of the guest."
},
"verified": {
"type": "boolean",
"enum": [
true
],
"description": "The user is verified or not"
},
},
"required": [
"email",
"firstName",
"lastName",
"verified",
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
]
}
TL;DR: 尝试在 API 蓝图文档中使用 fixed-type
而不是 fixed
。 fixed
要求样本值是实际值。
更详尽的解释:
body: At '/data/email' No enum match for: "dredd_testzz@keyflow.se"
这意味着被测服务器返回的响应包含可正确解析的 JSON 正文,但根据 API 描述提供的架构,正文无效。
错误指向/data/email
,也就是说{"data": {"email": ...
属性有问题。此外,它提到 enum
的值是预期的,并且实际响应包含 dredd_testzz@keyflow.se
,这是枚举不允许的。其他错误类似。
查看 API 描述,响应中预期的规范如下:
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
MSON 规范的 fixed
attribute, as explained in the 4.3 Nested Member Types 部分不仅修复了结构,还修复了所有值,并进一步向下传播数据结构:
...MAY specify fixed to indicate a "value object" where all the properties MUST be present and the values of the properties MUST be the values specified, if any, in its Nested Member Types. Further, such an object type structure MUST NOT contain any other properties.
我想你想使用 Dredd 文档的 fixed-type
instead, which fixes just the structure. This is further explained also in the Making Dredd Validation Stricter 部分。