-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
Use mapping to directly validate mapped schema #338
base: master
Are you sure you want to change the base?
Conversation
Cool so can't the duplicate code be removed? and if not could you avoid the duplication by introducing a function please. |
Just a few nits but this is otherwise correct. |
This reverts commit 9aa5c5a.
Looks like the test fails to print the expected error. You can use this to reproduce:
|
This is what schema.go:856 else is for Spec quote: ``It is implied, that the property to which discriminator refers, contains the name of the target schema. In the example above, the objectType property should contain either simpleObject, or complexObject string.''*/
I didn't even know about this notation .. I searched for where Example was called, expecting the validation would come from outside or something ..didn't know it was in the comments.. So that is where the else would come into play (from your original question) |
// "bark": true, | ||
// "breed": "Dingo", | ||
// "pet_type": "Cat" | ||
// } |
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.
I understand the request data should be invalid per the provided schema. What am I missing?
The test used to not pass because there was no output, because no error is returned. Are you sure this should not output anything?
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.
This relates to your original question about not being sure regarding the presence of the "else
" statement:
Quoting from https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/
"It is implied, that the property to which discriminator refers, contains the name of the target schema. In the example above, the objectType property should contain either simpleObject, or complexObject string. If the property values do not match the schema names, you can map the values to the names. To do this, use the discriminator/mapping keyword:"
I'm interpreting this as saying that if you don't specify the mapping the default mapping is based on the names of the objects included in the oneOf list: simpleObject
, complexObject
in the spec doc, Dog
or Cat
in the Example()
from validate_request_test.go
.
Because of that "else", ValidateRequest()
is not anymore returning an error in the Example()
code, and therefore I had to modify the output to be empty, accordingly.
Let me know if you believe I'm getting it all wrong or it makes sense.
Side note: the fact that now a "barking cat" is legitimate in the Example()
can be ruled out with other means (additionalProperties
and required
keyword props). This would possibly make the Example more meaningful (and getting it back to fail again).
Commit 5547859 permits, when the discriminator and mapping are used to
visitJSON
for the specificSchema
without losing time, and to return the specific error instead of the generic one returned when mapping is not specified.