Json 验证器成功验证任何字符串输入

问题描述 投票:0回答:0

根架构:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "properties": {
        "deviceId": {
            "description": "Unique ID of the device of type UUIDv4",
            "type": "string",
            "format": "uuid"
        }
    },
    "required": ["deviceId"]
}

Json 验证正确报告以下输入的错误,因为 uuid 无效

{
    "deviceId" : "410c75b4"
}

然而,验证器不会报告任何错误,如果以下是输入。

Input Json Data:
""
"1234"
0

根据我的理解,根模式特别指出

deviceId
required
json 输入,但 json 验证器仍然成功验证了空字符串、随机字符串或一些针对 json 模式的数字。

Python代码

    try:
        validate(instance=jsoninput, schema=rootschema, format_checker=jsonschema.FormatChecker())
    except Exception as err:
        print(f'Validation failed: {err}')
        return False

也在这里测试https://www.jsonschemavalidator.net/

json jsonschema json-schema-validator python-jsonschema
© www.soinside.com 2019 - 2024. All rights reserved.