-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
Question: Anyway to get a "compiled" version of the schema? #125
Comments
From your example you seem to want a schema with refs merged in... Ajv doesn't produce such thing, refs are either inlined as code in generated validation function (if they don't contain other refs and if they are not recursive) or compiled as separate functions. The reason this "final" schema is not created is that schema can be recursive (and it is a very common thing) in which case it is impossible to create. This seems to be similar to #22. |
what is the utility by the way? |
I was thinking what would I do if I had such an issue... I would probably simply use some templates (doT templates in my case :) to generate two different schemas - one with refs, another without. Another alternative is to use code to merge them as objects... It's not that difficult to write a generic processor that would replace $refs with actual schemas in case it is not recursive - you can even make a schema with a custom keyword to do such processing:
All you need to do is to define a custom keyword replaceRef (that will resolve and replace the ref with object) and then pass your schema as data to this "processing" schema:
At the moment you can only do it with inline keyword (as you need access to the parent object), but the next release which I am about to make will allow to use simpler validation/compiled keywords to do so. |
Thank you for the prompt response. "what is the utility by the way?" Regarding the generic processor, that is the approach we were going to go Thank you again for your time and the prompt response. We will move forward On Wed, Feb 17, 2016 at 1:14 PM, Evgeny Poberezkin <[email protected]
Matthew C. Rice |
@conrad10781 Have you found a solution for the processing approach as @epoberezkin is proposing? |
@ro70 , it was some time ago, but we ended up just iterating through all the schema's first, so we had them all, then iterating again and replacing ref instances with the actual schema. |
@conrad10781 Ok, I implemented something similar to your solution. My schemas had to be dereferenced and demerged. Thank you. |
@ro70 could you please share your solution ? |
@jegj For my purpose the following code did it. My schemas each have an id like
|
thanks ! |
I have found a possible way to get compiled schema with resolved references.. maybe it could help.
|
First, let me thank you for the work on the validator. We're using it to satisfy quite a few needs we've had with data validation on older data sets we have.
Is there anyway to get a "compiled" version of the schema that is built with $ref's? We need to pass it to a 3rd party utility we don't have control over and this utility doesn't seem to support $ref's in any way we've been able to figure out.
Specifically, where you would normally have the following ( I trimmed it down for readability ):
Product
Category
Is there anyway to execute something so that we could get something similar to the following? I'm sorry if "compiled" is not the right term.
The text was updated successfully, but these errors were encountered: