-
-
Notifications
You must be signed in to change notification settings - Fork 559
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
Fix to generate validations of hash elements #1298
Conversation
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.
Thank you for doing that! I left a couple of questions in the review.
goagen/codegen/validation.go
Outdated
}) | ||
keyVal = fmt.Sprintf("%sif e != nil {\n%s\n%s}", Tabs(depth+1), val, Tabs(depth+1)) | ||
} | ||
elemVal := v.Code(h.ElemType, true, false, false, "e", context+"[*]", depth+1, false) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
goagen/codegen/validation.go
Outdated
@@ -386,6 +437,11 @@ const ( | |||
{{ .validation }} | |||
{{ tabs .depth }}}` | |||
|
|||
hashValTmpl = `{{ tabs .depth }}for k, {{ if .elemValidation }}e{{ else }}_{{ end }} := range {{ .target }} { | |||
{{ .keyValidation }} | |||
{{ if .elemValidation }}{{ .elemValidation }}{{ end }} |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Thank you for your review. I misunderstood the specification. |
@@ -386,6 +438,12 @@ const ( | |||
{{ .validation }} | |||
{{ tabs .depth }}}` | |||
|
|||
hashValTmpl = `{{ tabs .depth }}for {{ if .keyValidation }}k{{ else }}_{{ end }}, {{ if .elemValidation }}e{{ else }}_{{ end }} := range {{ .target }} { | |||
{{- if .keyValidation }} |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Awesome PR, thank you! Do you think you could backport to |
* Fix to generate validations of hash elements * Fix to compute validations for the keys and values separately and render both separately * Add tests for hash validations * Fix cyclo
HashOf
accepts optional DSLs as third and fourth argument which allows providing validations for the keys and values of the hash. But there is no validation codes generated.Sample design:
Above design generates following codes:
app/contexts.go
app/user_type.go
This patch is applied:
app/contexts.go
app/user_type.go