简体   繁体   English

如何使用AJV获取当前/已编译的架构?

[英]How to get current/compiled schema with AJV?

This question pertains to ajv . 这个问题与ajv有关

How can I get the schema being validated? 如何获得验证的架构?

eg 例如

const validatePromise = ajv.compileAsync({...options.schema, $async: true});

validatePromise.then(validate => {
    validate(value).then(() => {
        // validation was successful
    }, errResult => {
        if(errResult instanceof Ajv.ValidationError) {
            // how to get the schema?
        }
    })
});

Before you tell me to just put {...options.schema, $async: true} into a variable, remember that remote schemas can be loaded -- I want the fully-resolved schema with all of its rules and properties. 在告诉我将{...options.schema, $async: true}放入变量之前,请记住可以加载远程模式-我想要具有所有规则和属性的完全解析的模式。 Presumably all of the subschemas have loaded before errResult can be computed -- so where is it stored and how do I access it? 大概所有子方案在errResult可以计算之前就已经加载了-那么它存储在哪里以及如何访问它?

The current schema object is in validate.schema. 当前的架构对象位于validate.schema中。 Ajv never constructs fully resolved schema, see FAQ for the comments. Ajv从不构造完全解析的架构,有关注释,请参阅FAQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM