本地文件引用的嵌套条件属性在 python-jsonschema 中不起作用

问题描述

我的 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 有问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)