ajv-validator/ajv

Add `validateSchema` "strict" mode

relu91 opened this issue · 6 comments

What version of Ajv you are you using?
8.12.0

What problem do you want to solve?
We have a server-side "repository" of schemas that we lazy-compile (and cache) only when they are really used. When adding a new schema to the repository the JSON payload is validated using the validateSchema function. My assumption was that if the schema is valid then the compile function should always work. However, this is not true if you enable the strict mode (which is enabled by default).

What do you think is the correct solution to problem?
I would like to have a function (or an additional option in the validateSchema) that can assure that the compile function will return the validate function.

Will you be able to implement it?
I've looked into the inner workings of avj in the past, I might know the places to touch but I probably need some guidance.

Hi @relu91 I am having trouble getting my head around the problem you are having, it feels like I'm missing context. Can you maybe provide an example, either with runkit like this or as a repo demonstrating what currently happens along with what you would like to happen?

Hi @jasoniangreen thanks for the quick answer! I cloned your runkit and tried to create an example of what the problem is. What I would like to have is a function that evaluates a schema and tells me that the schema can be used in the compile function. So basically:

const isSchemaValid = ajv.validateSchema(schema); // if this returns true
const validate = ajv.compile(schema); // this should not throw