Skip to content

Conversation

@dan-j
Copy link

@dan-j dan-j commented Aug 10, 2021

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 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.

There is an alternative approach which could also make this work, you could add HasKeyword() to the JSONPather interface. The naming would seem kind of wrong though, so you could rename HasKeyword() to HasProp() to be consistent with the JSONPather terminology, however this would be a breaking change.

…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.
refs int
}{
{`{ "not" : { "$ref":"#" }}`, 2, 0},
{`{ "not" : { "$ref":"#" }}`, 3, 1},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

elements++
if sch, ok := elem.(*Schema); ok {
if sch.HasKeyword("$ref") {
if kw, ok := elem.(SchemaKeyword); ok {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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 this pull request may close these issues.

1 participant