【问题标题】:Json Schema Nested Properties Ignored忽略 Json 架构嵌套属性
【发布时间】:2018-10-21 23:40:21
【问题描述】:

我正在尝试使用 json Schema,但我似乎遗漏了一些东西。 我在“测试”中设置的所有内容都被完全忽略了。我可以将类型设置为任何类型,它仍然被接受。如何验证这些嵌套属性?

forward_schema = {
    "$schema": "http://json-schema.org/draft-06/schema#",
    "title": "ForwarderObject",
    "description": "All Forwarding Settings",
    "type": "object",
    "properties": {
        "active": {
            "type": "boolean",
        },
        "groups": {
            "type": "object",
            "title": "groups",
            "properties ": {
                "test": {
                    "type": "something",
                },

            },
            "required": ["test"]
        },

    },

    "required": ['active', "groups"],
}

test_object = {
    'groups':
        {
            'test':
                {
                    'from': ['1240321726a'],
                    'to': ['225388559'],
                    'filters':
                        {
                            'Asserter':
                                {
                                    'regex': ['"1232/"', '2aa']
                                }
                        },
                    'group-name': 'test',
                    'label': '',
                    'edited': ''
                },
        },
    'active': true
}

【问题讨论】:

  • Ty,确实很痛
  • 您可以选择以拼写错误为由删除您的问题。通常认为在 SO 上做正确的事情。但总是问更多问题=]
  • 澄清一下!
  • 请随时将我的答案标记为已接受的答案

标签: json validation schema jsonschema json-schema-validator


【解决方案1】:

这会很痛...错字... "properties ":

双引号中有一个空格。 我花了 5 分钟来锻炼身体! 您可以通过将其设置为 false 来测试是否达到了子模式。

"properties ": { "test": false, }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多