Open
Conversation
Contributor
|
hey @jdesrosiers The const typeErrors = alternative[instanceLocation]["https://json-schema.org/keyword/type"];Previously this was safe because {
$schema: "https://json-schema.org/draft/2020-12/schema",
anyOf: [
{ properties: { foo: { type: "string" } } },
{ properties: { foo: { type: "boolean" } } }
]
}
const instance = { foo: 42 }; The Minimal FIX that i can think of is adding optional chaining here in const typeErrors = alternative[instanceLocation]?.["https://json-schema.org/keyword/type"]; |
Collaborator
Author
|
Thanks, @srivastava-diya! I'll fix that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I wrote a
@hyperjump/json-schemaEvaluationPlugin to generate output directly in the normalized format we use in this project. The goal is to make using this with@hyperjump/json-schemamore efficient. While doing that, I found a couple places where I think the format can be cleaned up a little. Please review the changes and let me know if you think there might be any issues. All the tests pass, but I'm not 100% sure there aren't edge cases we haven't thought of that might not pass.Object.keys)?{ "#": {}, // <-- Removes this "#/foo": { "https://json-schema.org/keyword": { "https://example.com/main#/properties/foo/type": false } } }ifschemas is used to determine whether to evaluatethenorelse, but the keyword itself always reportstruebecause it's ignored for determining if the schema passes. Therefore, if we process its schema, we could get it reporting that a keyword passes when it actually failed. It doesn't seem to matter either way. I wasn't able to come up with an example where that caused a bug, but it seems like the safe thing to do is to skip that schema evaluation when building the normalized output.anyOf/oneOfwork, that doesn't seem to be necessary. We only care about declared properties that are also in the instance. Hopefully, this doesn't end up being necessary, because it would require an uggly hack in the EvaluationPlugin to make it work.