【问题标题】:How to validate JSON against hyper-schema with json-schema-validator如何使用 json-schema-validator 针对超模式验证 JSON
【发布时间】:2014-11-01 10:05:58
【问题描述】:

我无法弄清楚如何正确设置超模式以与 json-schema-validator 一起使用。我用的是json-schema-validator的java版本,版本是2.2.5。

我的架构是:

{
"$schema": "http://json-schema.org/draftv4/hyper-schema#",
"title": "User object",
"description": "A user representation",
"type": "object",
"properties": {
    "email": {
        "description": "The user's email address",
        "format":"email",
        "maxLength": 255
    },
    "picture": {
        "description": "The user's picture",
        "type": "string",
        "media": {
            "binaryEncoding": "base64",
            "type": "image/png"
        }
    }
}
}

我的 json 对象是:

{"email":"k@w.de",
"picture":null}

现在,当我将架构加载到 JsonSchemaFactory 并打算开始验证时,我收到以下警告:

warning: the following keywords are unknown and will be ignored: [media]
level: "warning"
schema: {"loadingURI":"#","pointer":"/properties/picture"}
domain: "syntax"
ignored: ["media"]

除了 $schema 字段,还有什么要配置使用超模式的吗?

【问题讨论】:

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


    【解决方案1】:

    这是因为你的 $schema 错误!

    应该是http://json-schema.org/draft-04/hyper-schema#。请参阅section 6 of the core specification 了解众所周知的 URI 列表。

    【讨论】:

    • 好的。这行得通。我现在可以解决超模式了。但是,如果我提供了无效的 base64 字符串,例如“Abc der ...”作为图片值,则不会报告任何错误。此外,“readOnly”属性也无法识别,并导致与上述相同的警告。
    • 这里有两个独立的问题:base64 和 readOnly。你介意opening an issue 处理这两个问题吗?请在问题中粘贴您尝试验证的完整架构和数据。
    猜你喜欢
    • 2019-04-21
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 2012-11-28
    • 2020-12-01
    • 2021-04-18
    相关资源
    最近更新 更多