Skip to content
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

Use this library to parse/dereference/flatten JSON schema? #228

Closed
brettstack opened this issue Jul 8, 2016 · 3 comments
Closed

Use this library to parse/dereference/flatten JSON schema? #228

brettstack opened this issue Jul 8, 2016 · 3 comments

Comments

@brettstack
Copy link

Hi! Great library! Is it possible to get a flattened JSON schema that has all of the $ref's replaced with their actual value? I'm writing a code generator based on my JSON schemas and I'm a heavy (ab)user of $ref. Right now I'm using this lib and doing this myself using the refs and refVal values of the compiled schema, but thought I'd post here in case there's a better approach.

Thanks,
Brett.

@epoberezkin
Copy link
Member

epoberezkin commented Jul 9, 2016

@epoberezkin
Copy link
Member

Creating dereferenced schemas for recursive schemas is simply not possible (short of creating objects with circular references), and recursive schemas are a very common use case.

A better approach for code generation (and actually any schema-based processing) is to use custom keywords and your own context object that will be passed to them (see passContext option) and can accumulate the results of processing or anything else.

In this case you won't have to worry about traversing the schema and interpreting keywords items, properties etc. You will only have to implement your custom processing in custom keywords and Ajv will iterate the schema for you. I used this approach in jsonscript-js.

@epoberezkin
Copy link
Member

Also #125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment