2017-03-24 34 views
1

我正在使用TestNG以及Rest Assured。 我們有json模式文件。在Json模式內部,它使用$ ref屬性引用其他模式。休息保證例外 - 無效JSON模式,無法繼續

當我使用matchesJsonSchemaInClasspath作爲Hamcrest斷言時,它失敗並出現驗證錯誤。 錯誤基本上驗證器無法讀取嵌套的JSON模式。 有人可以幫助我解決問題。

附加錯誤和Json模式。

錯誤:

com.github.fge.jsonschema.core.exceptions.InvalidSchemaException: 
fatal: invalid JSON Schema, cannot continue 
Syntax errors: 
[ { 
    "level" : "warning", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/response.json#", 
    "pointer" : "" 
    }, 
    "domain" : "syntax", 
    "message" : "the following keywords are unknown and will be ignored: [javaType, name]", 
    "ignored" : [ "javaType", "name" ] 
}, { 
    "level" : "error", 
    "message" : "value has incorrect type (found boolean, expected one of [array])", 
    "domain" : "syntax", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#", 
    "pointer" : "" 
    }, 
    "keyword" : "required", 
    "found" : "boolean", 
    "expected" : [ "array" ] 
}, { 
    "level" : "error", 
    "message" : "URI \"./service_header.json\" is not normalized", 
    "domain" : "syntax", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#", 
    "pointer" : "/properties/service_header" 
    }, 
    "keyword" : "$ref", 
    "value" : "./service_header.json" 
}, { 
    "level" : "error", 
    "message" : "value has incorrect type (found boolean, expected one of [array])", 
    "domain" : "syntax", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#", 
    "pointer" : "/properties/service_header" 
    }, 
    "keyword" : "required", 
    "found" : "boolean", 
    "expected" : [ "array" ] 
}, { 
    "level" : "error", 
    "message" : "value has incorrect type (found boolean, expected one of [array])", 
    "domain" : "syntax", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_item.json#", 
    "pointer" : "/properties/items" 
    }, 
    "keyword" : "required", 
    "found" : "boolean", 
    "expected" : [ "array" ] 
}, { 
    "level" : "error", 
    "message" : "URI \"./setvice_item.json\" is not normalized", 
    "domain" : "syntax", 
    "schema" : { 
    "loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_item.json#", 
    "pointer" : "/properties/items/items" 
    }, 
    "keyword" : "$ref", 
    "value" : "./service_item.json" 
} ] 
level: "fatal" 

JSON架構:

main.json

{ 
    "type":"object", 
    "$schema":"http://json-schema.org/draft-04/hyper-schema", 
    "name": "Response", 
    "title": "Response", 
    "javaType": "com.ruthresh.Response", 
    "description": "Enables you to make a POST response.", 
    "required":true, 
    "properties":{ 
     "service_header":{ 
      "type":"object", 
      "description": "The service header for a response.", 
      "required":true, 
      "$ref":"./service_header.json" 
     }, 
     "items":{ 
      "type":"array", 
      "description": "An array of individual items.", 
      "required":true, 
      "maxLength":5000, 
      "minLength":1, 
      "items":{ 
       "$ref":"./service_item.json" 
      } 
     } 
    } 
} 

service_header.json

{ 
    "type":"object", 
    "$schema":"http://json-schema.org/draft-04/hyper-schema", 
    "name":"service_header", 
    "title":"Service response Header", 
    "description":"The service header for a response.", 
    "id":"service_header:v1", 
    "javaType": "com.ruthresh.Header", 
    "required":true, 
    "properties":{ 
     "email_subject":{ 
      "type":"string", 
      "description":"Email subject.", 
      "maxLength":255 
     }, 
     "email_message":{ 
      "type":"string", 
      "description":"Email Message.", 
      "maxLength":4000 
     } 
    } 
} 

serivice_item.json

{ 
    "type":"object", 
    "$schema":"http://json-schema.org/draft-04/hyper-schema", 
    "name":"serivice_item", 
    "title":"Service response Header", 
    "description":"The service header for a response.", 
    "id":"serivice_item:v1", 
    "javaType": "com.ruthresh.Item", 
    "required":true, 
    "properties":{ 
     "item_subject":{ 
      "type":"string", 
      "description":"Item subject.", 
      "maxLength":255 
     }, 
     "item_message":{ 
      "type":"string", 
      "description":"Item Message.", 
      "maxLength":4000 
     } 
    } 
} 

回答

0

作爲錯誤消息指出,「必需的」應該是所要求的特性的陣列,而不是布爾值。