-
-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validateSchema
"strict" mode
#2463
Comments
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 const isSchemaValid = ajv.validateSchema(schema); // if this returns true
const validate = ajv.compile(schema); // this should not throw |
Oh interesting, I shall take a deeper look and get back to you. |
So I understand the issue and it is something I will try to raise with @epoberezkin. In the meantime I wanted to understand a few more things about your use case. Why do you need to lazy compile schemas? The usual pattern is to compile and cache all schemas during server boot (when performance is not usually an issue) and I also don't understand why you can't compile when adding a new schema as once again it is a one off task and not getting repeated with every request to the server. Also why is it a problem to just use Just to be clear, I'm not saying there isn't an issue to consider here with validateSchema, but just curious about your use case. |
Thank you!
So schemas are not known ahead of time but they are supplied by users dynamically. We could compile them right away but it might be a waste of resources because they might be used somewhen later. I'm aware that this might be an "early optimization problem" but given the existence of the
Given the schemas are user-supplied I'd prefer to keep the additional checks of strict mode as described by the documentation, but it is something we can evaluate to change. |
So the answer I got was that |
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 thecompile
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.
The text was updated successfully, but these errors were encountered: