mpen
mpen

Reputation: 282865

How to get current/compiled schema with AJV?

This question pertains to ajv.

How can I get the schema being validated?

e.g.

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. Presumably all of the subschemas have loaded before errResult can be computed -- so where is it stored and how do I access it?

Upvotes: 2

Views: 1431

Answers (1)

esp
esp

Reputation: 7687

The current schema object is in validate.schema. Ajv never constructs fully resolved schema, see FAQ for the comments.

Upvotes: 3

Related Questions