【问题标题】:Rest Assured Exception - invalid JSON Schema, cannot continue放心异常 - 无效的 JSON 架构,无法继续
【发布时间】:2017-08-17 05:40:24
【问题描述】:

我正在使用 TestNG 和 Rest Assured。 我们有 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 架构:

ma​​in.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
        }
    }
}

service_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
        }
    }
}

【问题讨论】:

    标签: jsonschema rest-assured hamcrest


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      相关资源
      最近更新 更多