Failed validating 'type' json schema

visc

I've writen a small chunk os json schema but I'm getting a validation error using python jsonschema.

Here is my schema:

{


"$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"
      ]
    }
  }
}

Here is the error I'm receiving:

Failed validating u'type' in schema

I'm attempting to validate my schema with:

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

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

What am I doing wrong with the schema I've written? Am I not allowed to have a property named Type?

visc

My problem was Draft4Validator.check_schema takes a dic not a string, nor a json object.

Here was my solution:

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条评论
登录后参与评论

相关文章

来自分类Dev

从POJO生成Json Schema

来自分类Dev

JSon schema and Inheritance

来自分类Dev

Failed to read schema document [XSD] because

来自分类Dev

oneOf对象的Json Schema示例

来自分类Dev

数字的MaxLength的JSON Schema属性

来自分类Dev

从Json Schema生成样本Json输出

来自分类Dev

Is it alright to have a field type of ObjectId in a mongoose schema

来自分类Dev

基于属性值的条件Json Schema验证

来自分类Dev

测试schema.org ld + json内容

来自分类Dev

Json Schema-使用引用使用枚举

来自分类Dev

Json Schema,请考虑未指定的属性

来自分类Dev

用于验证测试的Json Schema数据集

来自分类Dev

验证Json Schema Draft V4

来自分类Dev

在React中阅读schema.org JSON

来自分类Dev

Json Schema:根据使用类型验证类型

来自分类Dev

从json-schema引用远程枚举值

来自分类Dev

用于可变性的Json Schema模板

来自分类Dev

JSON Schema 需要特定的数组元素

来自分类Dev

PatternProperties 中的 JSON Schema 严格类型

来自分类Dev

使用 AJV for Json Schema 修改数据

来自分类Dev

JSON Schema:如何扩展更多属性?

来自分类Dev

Fastify JSON Schema 默认值`null`

来自分类Dev

检查 JSON Schema 中的不同嵌套属性

来自分类Dev

flask:如何对Request JSON和JSON schema进行验证?

来自分类Dev

从 json 中引用 JSON Schema 类似 XML 引用 XML 模式

来自分类Dev

How do I do a nested list (array) of schema references in json schema

来自分类Dev

Json.NET模式会忽略$ schema吗?

来自分类Dev

混合JSON-LD和Microdata Schema.org

来自分类Dev

Schema.org:使用Microdata,RDFa或JSON-LD?