首页 > 解决方案 > Json Schema 嵌套属性被忽略

问题描述

我正在尝试使用 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
}

标签: jsonvalidationschemajsonschemajson-schema-validator

解决方案


这会很痛……错别字…… "properties ":

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

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


推荐阅读