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

WIP: validate client params #850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GlenDC
Copy link
Member

@GlenDC GlenDC commented Jan 8, 2017

fixes issue #833

// Validate these params
func (o *AddCommentToTaskParams) Validate(formats strfmt.Registry) error {

if err := o.Body.Validate(formats); err != nil {
Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

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
Copy link
Member Author

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 ?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

@GlenDC
Copy link
Member Author

GlenDC commented Jan 18, 2017

Things left to do in order for the code in this PR to work and thus become merge-able:

  • make sure Validate method is defined for all models/bodies structs;
  • make sure the Required validation always is checked;
  • rebase latest master and regenerate bindata;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants