验证“类型” json模式失败

我住在

我已经编写了一个小块os json模式,但是使用python jsonschema时遇到了验证错误。

这是我的架构:

{


"$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "output": {
      "type": "object",
      "properties": {
        "Type": {
          "type": "object",
          "properties": {
            "Type": {
              "type": "string"
            },
            "Value": {
              "type": "string"
            },
            "Default": {
              "type": "string"
            },
            "Description": {
              "type": "string"
            },
            "Options": {
              "type": "array"
            }
          },
          "required": [
            "Type",
            "Value",
            "Default",
            "Description",
            "Options"
          ]
        },
        "Inverted": {
          "type": "object",
          "properties": {
            "Type": {
              "type": "string"
            },
            "Value": {
              "type": "bool"
            },
            "Default": {
              "type": "bool"
            },
            "Description": {
              "type": "string"
            }
          },
          "required": [
            "Type",
            "Value",
            "Default",
            "Description"
          ]
        },
        "Pulse Width": {
          "type": "object",
          "properties": {
            "Type": {
              "type": "string"
            },
            "Value": {
              "type": "number"
            },
            "Default": {
              "type": "number"
            },
            "Description": {
              "type": "string"
            }
          },
          "required": [
            "Type",
            "Value",
            "Default",
            "Description"
          ]
        }
      },
      "required": [
        "Type",
        "Inverted",
        "Pulse Width"
      ]
    }
  }
}

这是我收到的错误:

Failed validating u'type' in schema

我正在尝试使用以下方法验证我的架构:

schema = ""
with open(jsonSchemaFilePath, 'r') as schema_file:
    schema = schema_file.read()

try:
    Draft4Validator.check_schema(schema)
except SchemaError as schemaError:
    print schemaError

我编写的架构有什么问题?我是否不能拥有一个名为Type的属性?

我住在

我的问题是Draft4Validator.check_schema需要一个dic不是字符串,也不是JSON对象。

这是我的解决方案:

schema = {}
with open(jsonSchemaFilePath, 'r') as schema_file:
    schema = json.loads(schema_file.read())

try:
    Draft4Validator.check_schema(schema)
except SchemaError as schemaError:
    print schemaError

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章