-
Notifications
You must be signed in to change notification settings - Fork 54
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
Validation of zero values #19
Comments
required values are rendered as pointers normally, the zero value for that is nil |
I have a case, where I have set a boolean as required and
In this case I get a validation error, if I send in |
You're explicitly disabling the ability to detect if a value is required or not with x-nullable: false. |
I want it to provide a validation error, if I'm starting to grasp the complexity of my issue as it would require some intermediate unmarshalling into a struct with pure pointers, perform the validation and then make a conversion to my desired result of a struct with values. |
there are a number of helpers in the swag package to make working with pointers easier. |
Yeah, I know about that, but I just don't want those conversions everywhere in my code (we are talking about around 100 endpoints with 10+ properties a piece). It makes for ugly code to use pointers for required and values for optional in the API layer, while using values for required and pointers for optional in the database layer. |
I have a PR that deals with this, but I can't merge because it's a breaking change, and a big one. |
Cool, looking forward to that then! I'll manage with |
@casualjim can you publish the PR you mentioned? |
See alse go-swagger/go-swagger#959 (related but not duplicate) |
This library currently marks a zero value for a required property as an error (
validate/values.go
Line 116 in 027696d
But this doesn't really make sense in an API, because you should be allowed to send in a
0
for an integer property or afalse
for a boolean property even if it is required.In regards to integers, the minimum option should define whether
0
is allowed, not the required option.In regards to booleans, the required check doesn't make any sense at all in its current form as you aren't able to send anything other than
true
.The text was updated successfully, but these errors were encountered: