Rest Assured Exception - 无效的JSON Schema,无法继续

时间:2017-03-24 10:19:32

标签: jsonschema rest-assured hamcrest

我正在使用TestNG和Rest Assured。 我们有json模式文件。在Json模式中,它引用了使用$ ref属性的其他模式。

当我使用matchesJsonSchemaInClasspath进行Hamcrest断言时,它失败并出现验证错误。 该错误基本上是Validator无法读取嵌套的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
        }
    }
}

1 个答案:

答案 0 :(得分:0)

正如错误消息所示," required"应该是必需属性的数组而不是布尔值。