Skip to content

Top-level $ref in 0.44.0 #391

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

Closed
joshkel opened this issue Dec 8, 2020 · 4 comments · Fixed by #392
Closed

Top-level $ref in 0.44.0 #391

joshkel opened this issue Dec 8, 2020 · 4 comments · Fixed by #392

Comments

@joshkel
Copy link
Contributor

joshkel commented Dec 8, 2020

When I upgraded from typescript-json-schema 0.43.0 to 0.44.0, I noticed that AJV started giving a new warning when compiling the generated schema:

$ref: keywords ignored in schema at path "#/properties/data/properties/pcList"

Sample TypeScript types:

interface Parent { name?: string; children: Child[]; }
interface Child { name?: string; parent?: Parent; }

The generated schema in 0.43.0 has a definitions.Parent section and also duplicates the Parent type's properties on the root schema. The generated schema in 0.44.0 has a top-level "$ref": "#/definitions/Parent" property. If I understand the discussions at ajv-validator/ajv#1121 correctly, the top-level $ref object is technically invalid.

If I've misunderstood this, please let me know. Thanks!

@domoritz
Copy link
Collaborator

domoritz commented Dec 8, 2020

Hmm. Is this and instance of the problem? If so, we may need to revert the pull request.

@joshkel
Copy link
Contributor Author

joshkel commented Dec 10, 2020

From doing some local experiments, I apparently had misunderstood; it looks like a top-level $ref can be valid; the fact that type is still there (like you said) is what's causing the problem.

I manually removed the top-level type from a sample recursive schema, and I'm able to compile and use it in AJV without errors.

@domoritz
Copy link
Collaborator

@darkowic and @joshkel do you think you can look into a fix for this bug?

@joshkel
Copy link
Contributor Author

joshkel commented Dec 15, 2020

@domoritz, I took a stab at fixing it in #392. Feedback welcome; I'm pretty new to JSON Schema and may have missed something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants