1

RefResolverValidator脚本是

from jsonschema import RefResolver
from jsonschema.validators import validator_for
from tests.automation.io.helpers.loader import load_schema

base = load_schema('base.schema.json') # {"$schema": "http://json-schema.org/draft-07/schema#" }
definitions = load_schema('defination.schema.json') # https://jsonschema.dev/s/FZDbO
schema = load_schema('update.schema.json') # https://jsonschema.dev/s/lvLFa

schema_store = {
  base.get('$id','base.schema.json') : base,
  definitions.get('$id','defination.schema.json') : definitions,
  schema.get('$id','update.schema.json') : schema,
}

resolver = RefResolver.from_schema(base, store=schema_store)
Validator = validator_for(base)
validator = Validator(schema, resolver=resolver)

data = {
    "common_data": {
        "os_ip": "127.0.0.1",
        "os_user": "root",
        "os_pwd": "hello",
        "remote_os": "Windows"
    },
    "dup_file": "ad7a.exe"
}
validator.validate(data)

我的 JSON 架构看起来像

base.schema.json=>{"$schema": "http://json-schema.org/draft-07/schema#" }

defination.schema.json=> https://jsonschema.dev/s/FZDbO

update.schema.json=> https://jsonschema.dev/s/lvLFa

得到错误:jsonschema.exceptions.ValidationError: 'ad7a.exe' does not match '^(.*.)(bin)$'

同样的事情我已经测试过https://json-schema.hyperjump.io/它工作得非常好,怀疑python-jsonschema只有一些问题。

4

0 回答 0