-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
WIP: validate client params #850
base: master
Are you sure you want to change the base?
Conversation
// Validate these params | ||
func (o *AddCommentToTaskParams) Validate(formats strfmt.Registry) error { | ||
|
||
if err := o.Body.Validate(formats); err != nil { |
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.
@casualjim this fails to compile, as that body model has not defined the Validate functions. This is however defined for the Body called here: https://github.com/go-swagger/go-swagger/pull/850/files#diff-ab37f2908b4671ebce8d3bc51539d622R123 ; I'm a bit stuck on this one, could you point me to the correct template location on how I could ensure that body model has the validation defined? Or is it because this model is automatically appended in the generator code (via the name+Body stuff)? If i'm doing crazy stuff in this commit you can also point it out though
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.
That struct should actually have a Validate method, it has 2 required fields, so there is a reason it's not rendering that validate method
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.
so are you saying, @casualjim, that the reason it is not rendering is an unreported bug?
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.
yeah that's what it looks like because the same issue exists on the server side
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.
Ok weird, I'll try to track that issue later today. Can you please also check if my conditionals added in the template are reasonable, as you might have a better idea whether or not those will hold up for all permutations.
*/ | ||
Body *models.Task | ||
/*ID | ||
The id of the item | ||
|
||
Required: true | ||
In: path | ||
*/ | ||
ID int64 |
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 ID parameter is required, but for now Required isn't validated in my added Validate Client Parameter code. Any idea how I would be able to add validation for required parameters @casualjim ?
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.
The biggest question I have with this one, how to check a non-nil value. As I tried some string query parameter as required in a local test API, and it seemed to render as an ordinary string.
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 think there is an issue here: https://github.com/go-swagger/go-swagger/blob/master/generator/operation.go#L903
Things left to do in order for the code in this PR to work and thus become merge-able:
|
dfa3c16
to
a1e6afd
Compare
fixes issue #833