oracle - API 蓝图在实时 API 上因 dredd 失败?

标签 oracle apiblueprint apiary.io dredd mson

我正在将 dredd 从 1.08 升级到最新版本,在此过程中,我试图验证我们的 api 文档(用实时测试 api 编写的蓝图),但失败了。

由于测试是针对实时 api 运行的,因此从 api 返回的响应包含与模糊文档中指定的值不同的值。我从 dredd 收到以下错误。

有人可以帮我解决一下吗? :)

body: At '/data/email' No enum match for: "[email protected]"

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: `<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa90959294d49e959fba9f829b978a969fd4999597" rel="noreferrer noopener nofollow">[email protected]</a>` (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 Schema 如下

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": [
            "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90fafff8febef4fff5d0f5e8f1fde0fcf5bef3fffd" rel="noreferrer noopener nofollow">[email protected]</a>"
          ],
          "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:尝试使用fixed-type而不是fixed在您的 API 蓝图文档中。 fixed要求样本值是实际值。


更详细的解释:

body: At '/data/email' No enum match for: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690d1b0c0d0d361d0c1a1d131329020c100f05061e471a0c" rel="noreferrer noopener nofollow">[email protected]</a>"

这意味着被测服务器返回的响应包含可正确解析的 JSON 正文,但根据 API 描述提供的架构,该正文无效。

错误指向/data/email ,这意味着{"data": {"email": ...属性(property)有问题。此外,它提到 enum 值是预期的,并且实际响应包含 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97f3e5f2f3f3c8e3f2e4e3ededd7fcf2eef1fbf8e0b9e4f2" rel="noreferrer noopener nofollow">[email protected]</a> ,这是枚举所不允许的。其他错误类似。

查看 API 描述,响应中预期内容的规范如下:

+ Attribute
    + status: 200 (number, required, fixed)
    + data (ResponseSchema, required, fixed)

fixed 属性,如 4.3 Nested Member Types 中所述MSON 规范的部分,不仅修复了结构,还修复了所有值,并进一步向下传播数据结构:

...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.

我想你想使用 fixed-type 相反,它只是修复了结构。 Making Dredd Validation Stricter 中也对此进行了进一步解释。 Dredd 文档的部分。

关于oracle - API 蓝图在实时 API 上因 dredd 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47350176/

相关文章:

javascript - 如何禁止非授权用户访问API?

apiblueprint - 在 API Blueprint/MSON 中使用模式

markdown - 是否可以将 Markdown 文件中的表格居中?

SQL 查找完全包含给定集合的集合

apiblueprint - 省略 MSON 中定义的对象的属性

apiblueprint 结构来实现所需的描述

c# - 使用 httpClient.GetAsync 时添加 header

string - Oracle函数返回字符串之间的相似度

sql - 在我的查询中当 RowNum =1 时没有得到空值

sql - Oracle SQL 主键卡住