-
Notifications
You must be signed in to change notification settings - Fork 114
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
POC: Implement an Object validator #24
Conversation
Travis failed, but it looks like it's errors in the JWT implementation and not related to this PR. |
@rs feedback on the direction of this PR would be appreciated. I'm holding off on JSON Schema stuff because I could use something like this to implement "items" of arrays. Thanks |
I’m on vacation with limited access to internet. I will look at it asap. |
Thanks @rs I assumed you were on vacation so was being patient. |
JWT usage is fixed in master. Please rebase. |
c2ee188
to
1f2820a
Compare
Weird, now it's triggering --- FAIL: TestRoutePathParentsExists (0.00s) errors :( |
1f2820a
to
500a9a5
Compare
rebased. Thanks |
By reading the code, I'm not sure to see how the errors would be formatted with sub-fields. Don't you think it could be a good idea to add some tests on the format of the error in different context? |
Good point. I will do that. Thanks for the feedback. |
500a9a5
to
9053b79
Compare
OK, I've added 3 more tests. Because the error messages are a map, go makes the ordering that comes back non-deterministic, so I'm using assert.Contains to test for multiple values detected as bad. I made an array test but am only testing 1 bad value in the array because Array will stop executing after the first value that does not validate. I also improved the error message a little to make it more readable. 1 thing I noticed which I may send a PR in for, is that Thanks. |
Boolean does always take a capital as it is coming from a proper noun. http://english.stackexchange.com/questions/4481/should-the-word-boolean-be-capitalized |
if !ok { | ||
return nil, errors.New("not a dict") | ||
} | ||
fmt.Printf("%+v", value) |
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.
Is it a debug leftover?
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.
yep thinko. I'll remove it.
What about something like that to ease testing: https://play.golang.org/p/Dn5htsZKSv |
This looks good. I was avoiding making the Error() function more complex, but if you're ok with a sort and the extra garbage I'll use your implementation. Thanks! |
7538bd2
to
1c489a1
Compare
OK, rebased, removed thinko and refactored ErrorMap and tests to be like much nicer playground example. Thanks for all the feedback! |
1c489a1
to
c9306dc
Compare
OK, I spotted an unnecessary allocation and got rid of it in the error path. |
c9306dc
to
ba19506
Compare
- leverages Schema validation to validate a sub document using Schema - allows you to create arrays of objects which have their fields validated correctly. - add more tests for output of error map - ensure ErrorMap.Error() output is deterministic - simplify ErrorMap implementation (rs)
ba19506
to
88aab5e
Compare
Fixed an ordering issue in arguments to assert.Equal |
Thx @yanfali you're awesome |
Issue #23 Proof of concept
Create an "object" Validator which leverages leverages Schema validation to validate a sub document using Schema itself.
Goal is to allow you to creation arrays of objects which have their fields validated correctly.
This needs more tests and work, but I wanted to get your feedback @rs on this general approach, or if you have thoughts on a better way to do this.