-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix: swapping out the $ref parsing engine of flattenSchema #292
Conversation
How does this work in conjunction with https://github.com/readmeio/react-jsonschema-form? Are they related? I'm a little bit out of the loop on this one |
@dok This is completely unrelated to that. This Ideally we'd dereference these schemas before they're passed into the explorer from the beginning so we wouldn't need to have any |
dereference: { | ||
// If circular `$refs` are ignored they'll remain in `derefSchema` as `$ref: String`, otherwise `$ref‘ just | ||
// won't exist. This allows us to do easy circular reference detection. | ||
circular: 'ignore', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the way we would detect whether a dereferenced object after this function call? Whether a $ref: String
exists within the dereferenced object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If $ref
exists in derefSchema
at all, then it's circular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Are there any other times where a $ref cannot be satisfied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's an external ref (like a URL to another spec) it'll remain unsatisfied if it's inaccessible.
That said, we shouldn't be attempting to resolve external refs at this point in the application cycle so I'm going to add resolve.external: false
into the options here to prevent that as well as a test for that.
value = findSchemaDefinition(value.$ref, oas); | ||
// If we have a $ref present then it's circular and mark the type as such so we at least have something to | ||
// identify it as to the user. | ||
value.type = 'circular'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erunion oh I see. Thanks for the clarification. Is this easier to work with than the isCyclic functionality? It does seem to have a similar format to that (it looks recursive). |
@dok Yeah this work could likely be built into either our form module, or when we build up JSON Schema with Reworking that is all is a much larger project though and should probably be done further up the stack so we aren't processing the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-approving with this in mind
@erunion looks good! |
🧰 What's being changed?
This completely swaps out the
$ref
parsing engine behindflattenSchema
with json-schema-ref-parser to allow us to properly, easily, handle circular references without infinitely recusing them.How it works is we'll funnel an incoming schema and API definition into
json-schema-ref-parser
to dereference it but allowing it to ignore circular refs. If a$ref
is circular, it'll remain in the schema as$ref
, enabling us to quickly detect and ignore circular refs when flattening a schema.With this change,
flattenSchema
is now an async function.