0

我已经编写了一个模式来验证响应正文。并将所有项目设置为“必需”。但是当body返回空数组时,它直到PASS,应该是FAIL。像这样的架构:

var schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
    "$ref": "#/definitions/MyObject"
  },
  "definitions": {
    "MyObject": {
      "type": ["object"],
      "properties": {
        "transactionId": "integer",
        "transactionType": "string",
        "bpCode": "string",
        "bpId": "string",
        "postingDate ": "string",
        "dueDate": "string",
        "totalAmount": "number",
        "balanceDue": "number",
        "reconcileAmount": "number",
        "debitCredit": "string",
        "remarks": "string",
      },
      "required": ["transactionId", "transactionType", "bpCode", "bpId", "postingDate", "dueDate", "totalAmount", "balanceDue", "reconcileAmount", "debitCredit", "remarks"],
      "additionalProperties": false
    }
  }
};

tests["Valid respong body schema"] = tv4.validate(data.body, schema);

像这样的回应:

{
  "errorCode": null,
  "errorMessage": null,
  "body": []
}

4

1 回答 1

0

您应该排除空数组:

"type": "array",
"minItems": 1
"items": {
  "$ref": "#/definitions/MyObject"
}
于 2016-05-24T19:46:06.823 回答