JSON 架构和 Validate-JSON 不验证"required"



模式为:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "header": {
        "type": "object",
        "properties": {
            "token":         { "type": "string" },
            "id":            { "type": "number" },
            "command":       { "type": "string" }
        },
        "required": ["token", "id", "command"]
    }
}

但是这样的东西对于验证器是可以的:

{
    "badtoken": "abc123",
    "badcommand": "123"
}

命令行:

$ jsonschema -i file.json schema.json
$ validate-json file.json schema.json

为什么不工作?

实际上,我想做一个定义列表,然后使用它们:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "header": {
            "type": "object",
            "properties": {
                "token":         { "type": "string" },
                "id":            { "type": "number" },
                "command":       { "type": "string" }
            },
            "required": ["token", "id", "command"]
        }
    },
    "$ref": "#/definitions/header"
}

验证工作正常

最新更新