如何将extraProperties“:false插入我的架构?

时间:2019-12-06 14:34:32

标签: javascript json postman

能否请您告诉我,我需要在架构中的何处插入AdditionalProperties“:false,以将架构中未定义的任何内容标记为无效??目前,我仅设计了架构来测试有效属性,数据类型,正则表达式和端点,因此我想添加它以用于其他验证目的。

以下是我的架构:

tests['Status code is 200'] = pm.response.to.have.status(200);
const schema = 
 {
   "definitions": {},
   "$schema": "http://json-schema.org/draft-07/schema#",
   "$id": "http://example.com/root.json",
   "type": "array",
   "title": "The Root Schema",
   "items": {
     "$id": "#/items",
     "type": "object",
     "title": "The Items Schema",
     "required": [
       "ChannelId",
       "RecordId",
       "StartDateTime",
       "EndDateTime"
     ],
     "properties": {
       "ChannelId": {
         "$id": "#/items/properties/ChannelId",
         "type": "integer",
         "title": "The Channelid Schema",
         "default": 0,
         "examples": [
           0
         ]
       },
       "RecordId": {
         "$id": "#/items/properties/RecordId",
         "type": "string",
         "title": "The Recordid Schema",
         "default": "",
         "examples": [
           "0-106-0"
         ],
         "pattern": "^(.*)$"
       },
       "StartDateTime": {
         "$id": "#/items/properties/StartDateTime",
         "type": "string",
         "title": "The Startdatetime Schema",
         "default": "",
         "examples": [
           "2019-10-30T05:59:33+00:00"
         ],
         "pattern": "^(.*)$"
       },
       "EndDateTime": {
         "$id": "#/items/properties/EndDateTime",
         "type": "string",
         "title": "The Enddatetime Schema",
         "default": "",
         "examples": [
           "2019-10-30T06:58:23+00:00"
         ],
         "pattern": "^(.*)$"
       }
     }
   }
 };
 pm.test('Schema is valid', function () {
    var response = pm.response.json();
    var result = tv4.validateResult(response, schema, false, true);
    pm.expect(result.valid).to.equal(true, result.valid ? null : result.error.message);
});

0 个答案:

没有答案