Skip to content
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

Support query on dict/object values (breaking change!) #151

Merged
merged 2 commits into from
Nov 13, 2017
Merged

Conversation

smyrman
Copy link
Collaborator

@smyrman smyrman commented Oct 5, 2017

Starting on #139, case 2.

@rs, some feedback on putting Values Field over ValuesValidator FieldValidator inside schema.Dict. The idea would be to to do the same for schema.Array in a later PR. This also allows description fields to be set by jsonschema, as well as setting a Filterable value, and would become very consistent once we start on #77.

In addition schema.AllOf and schema.AnyOf should ideally get a GetFields implementation, although this is a harder problem as they would need to return multiple fields.

So far I have tested filtering to work with some simple manual test code:


This commit adds support for looking up field definitions inside
schema.Dict and schema.Object instances. To achieve this,
Dict.ValuesValidator has been deprecated in favour of a new Dict.Values
property that holds a full schema.Field.

As a result, it should be possible to filter on schema.Dict and
schema.Object sub-fields.

PS! This commit does not add support for filtering on fields inside
schema.Array, schema.AnyOf or schema.AllOf; this will come later.

schema/dict.go Outdated

// ValuesValidator is deprecated, use Values instead to specify a Field. If
// used, Values will be set to a required, non-filterable filed on Compile.
// ValuesValidator FieldValidator
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have an optino to add backwards compatibility by keeping the ValuesValidator field until we start on #77, if there is interest for it. It would add some complexity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I.e. I can either comment in or remove this code.

schema/dict.go Outdated
Required: true,
Validator: val,
}
}*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code would also either be commented in or removed.

@smyrman smyrman changed the title DO NOT MERGE: Support query on dict/object values Support query on dict/object values (breaking change!) Oct 10, 2017
Copy link
Contributor

@Dragomir-Ivanov Dragomir-Ivanov left a comment

Choose a reason for hiding this comment

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

Shouldn't this change require change in the documentation as well. There is almost no doc on schema.Dict

@smyrman
Copy link
Collaborator Author

smyrman commented Oct 10, 2017

Good point @Dragomir-Ivanov. There looks to be no documentation in the README that needs updating, but the doc-comment should most sertanly be updated:

Dict validates array values

That seems pretty wrong 😆

@smyrman smyrman force-pushed the dict-query branch 3 times, most recently from df1dd03 to bdb04ff Compare November 12, 2017 09:08
@smyrman
Copy link
Collaborator Author

smyrman commented Nov 12, 2017

@rs / @Dragomir-Ivanov PR updated with documentation changes, including a new list of breaking changes.

Sorry about the delay, it's been busy.

@smyrman
Copy link
Collaborator Author

smyrman commented Nov 12, 2017

@rs, would you prefer Array.ValuesValidator to be replaced in the same PR for more consistency on master, or are you OK with this arriving in a separate PR?

schema/dict.go Outdated
if _, err := v.KeysValidator.Validate(name); err != nil {
return nil
}
// TODO: As part of issue #77, replace Dict.ValuesValidator with a
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO is out of date (already done)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

schema/field.go Outdated
// present in the schema.
//
// You may reference sub field using dotted notation field.subfield.
GetField(name string) *Field
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

QueryField could be a better name. At least when it comes to e.g. Array and AnyOf, we are interested in a Field that can be used to validate query values, not necessarily a field that can validate values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Requires some rewrite of the whole logic to support better array querying, so we could wait with the rename this until we do the array part, if we need to slightly redo the logic anyway...

This commit adds support for looking up field definitions inside
schema.Dict and schema.Object instances. To achieve this,
Dict.ValuesValidator has been deprecated in favour of a new Dict.Values
property that holds a full schema.Field.

As a result, it should be possible to filter on schema.Dict and
schema.Object sub-fields.

PS! This commit does not add support for filtering on fields inside
schema.Array, schema.AnyOf or schema.AllOf; this will come later.
@smyrman smyrman merged commit 424d5a6 into master Nov 13, 2017
@smyrman smyrman deleted the dict-query branch November 13, 2017 09:14
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.

3 participants