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

Feature runtime.Validateable for for parameters #2387

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mwieser
Copy link

@mwieser mwieser commented Aug 21, 2020

Regarding #2309. Add a Validate method to the parameter generation, which reuses the validate methods of the properties if present. Refactored the parameter.gotml to have reusable code for binding and validation code generation. Added the GenParameterValidateOnly and GenItemsValidateOnly structs for this to pass a GenParameter/GenItems to a template to only generate the code necessary for validation.

This removes reassigning array/slice properties in the validation methods. As mentioned in #2309, it seems that the reassignment of the property is not necessary in the validation methods and I therefore removed it to remove side effects from the validation methods. In case the binding in the validate methods is needed, the step would need to be added again.

The reason for this PR is to validate parameter structs without having to bind them. This can be helpful when validating the params on a client before sending them. Furthermore the method exists for models so it would be more unified.

mwieser and others added 3 commits August 4, 2020 17:28
Refactored bind methods of param generation to support only generation of code necessary for validation without binding.
Add test for param validate to parameter_test.
@codecov
Copy link

codecov bot commented Aug 21, 2020

Codecov Report

Attention: 32 lines in your changes are missing coverage. Please review.

Comparison is base (5759dce) 82.13% compared to head (53b4f64) 82.30%.
Report is 397 commits behind head on master.

Files Patch % Lines
generator/types.go 81.81% 25 Missing and 1 partial ⚠️
cmd/swagger/commands/serve.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2387      +/-   ##
==========================================
+ Coverage   82.13%   82.30%   +0.17%     
==========================================
  Files          50       50              
  Lines        8563     8681     +118     
==========================================
+ Hits         7033     7145     +112     
- Misses       1032     1043      +11     
+ Partials      498      493       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@casualjim
Copy link
Member

Hi,

I'm sorry I missed this PR. Would it be possible to bring it up to date so I can merge it?

@fredbi fredbi changed the title Feature runntime.Validateable for for parameters Feature runtime.Validateable for for parameters Nov 23, 2020
@fredbi fredbi added generator validator Related to codegen generation of validations labels Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator validator Related to codegen generation of validations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants