Repository navigation
Conversation
…NPathers. traversal_test.go didn't feel correct so I've updated them as I expect them to work. The main issue was around how to check if a keyword has a nested prop using Schema.HasProp(), I don't think this works as expected because you can't apply type conversion from say `Not` to `*Schema` (see lines 89-94). As such I've added a new interface which can be implemented by Keywords which contain a schema, and exports a GetSchema() function.
dan-j
commented
Aug 10, 2021
| refs int | ||
| }{ | ||
| {`{ "not" : { "$ref":"#" }}`, 2, 0}, | ||
| {`{ "not" : { "$ref":"#" }}`, 3, 1}, |
Author
There was a problem hiding this comment.
To me this test should expect 3 elements (Schema, Not and Ref), and 1 ref. The previous version was 2 and 0, but this feels wrong.
dan-j
commented
Aug 10, 2021
| elements++ | ||
| if sch, ok := elem.(*Schema); ok { | ||
| if sch.HasKeyword("$ref") { | ||
| if kw, ok := elem.(SchemaKeyword); ok { |
Author
There was a problem hiding this comment.
The old behaviour doesn't work because you can't apply type-conversion from *Not (defined by type Not Schema) to *Schema, so it always returned false.
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.
See #106.
I'm sure if this is actually the right solution, but works for my use-case so I'm using my fork for now and we can discuss the approach here. Happy to refactor as needed.
traversal_test.go didn't feel correct so I've updated them as I expect them to work. The main issue was around how to check if a keyword has a nested prop using Schema.HasProp(), I don't think this works as expected because you can't apply type conversion from say
Notto*Schema(see lines 89-94). As such I've added a new interface which can be implemented by Keywords which contain a schema, and exports a GetSchema() function.There is an alternative approach which could also make this work, you could add
HasKeyword()to theJSONPatherinterface. The naming would seem kind of wrong though, so you could renameHasKeyword()toHasProp()to be consistent with theJSONPatherterminology, however this would be a breaking change.