当接口返回的数据量大时如何比对 jsonschema

在线生成jsonschame
https://jsonschema.net/home

pip install jsonschema
from jsonschema import validate
def test_schame():
schame = {
s c h e m a " : " h t t p : / / j s o n − s c h e m a . o r g / d r a f t − 07 / s c h e m a " , " schema": "http://json-schema.org/draft-07/schema", " schema":"http://jsonschema.org/draft07/schema","id”: “http://example.com/example.json”,
“type”: “object”,
“required”: [
“productId”,
“productName”,
“price”,
“tags”
],
“properties”: {
“productId”: {
“$id”: “#/properties/productId”,
“type”: “integer”,
“title”: “The productId schema”,
“description”: “An explanation about the purpose of this instance.”,
“default”: 0,

    },
    "productName": {
        "$id": "#/properties/productName",
        "type": "string",
        "title": "The productName schema",
        "description": "An explanation about the purpose of this instance.",


    },
    "price": {
        "$id": "#/properties/price",
        "type": "number",

    },
    "tags": {
        "$id": "#/properties/tags",
        "type": "array",
        "additionalItems": True,
        "items": {
            "$id": "#/properties/tags/items",
            "anyOf": [
                {
                    "$id": "#/properties/tags/items/anyOf/0",
                    "type": "string",
                    "title": "The first anyOf schema",
                    "description": "An explanation about the purpose of this instance.",
                    "default": "",
                    "examples": [
                        "home",
                        "green"
                    ]
                }
            ]
        }
    }
},
"additionalProperties": True

}
test_data = {
“productId”: 1,
“productName”: “A green door”,
“price”: 12.50,
“tags”: [“home”, “green”]
}
validate(instance=test_data,schema=schame)

参考:https://blog.csdn.net/zbj18314469395/article/details/93721393

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值