Feature runtime.Validateable for for parameters #2387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theGenParameterValidateOnly
andGenItemsValidateOnly
structs for this to pass aGenParameter/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.