放心异常 - 无效的 JSON 架构,无法继续



我正在使用TestNG和Rest Assureed。我们有 json 架构文件。在 Json 架构中,它使用 $ref 属性引用其他架构。

当我使用 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 架构:

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

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