forked from bufbuild/protoc-gen-validate
/
map.go
28 lines (26 loc) · 1.05 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package java
const mapConstTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
{{ if or (ne (.Elem "" "").Typ "none") (ne (.Key "" "").Typ "none") }}
{{ renderConstants (.Key "key" "Key") }}
{{ renderConstants (.Elem "value" "Value") }}
{{- end -}}
`
const mapTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
{{- if $r.GetMinPairs }}
io.envoyproxy.pgv.MapValidation.min("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMinPairs }});
{{- end -}}
{{- if $r.GetMaxPairs }}
io.envoyproxy.pgv.MapValidation.max("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMaxPairs }});
{{- end -}}
{{- if $r.GetNoSparse }}
io.envoyproxy.pgv.MapValidation.noSparse("{{ $f.FullyQualifiedName }}", {{ accessor . }});
{{- end -}}
{{ if or (ne (.Elem "" "").Typ "none") (ne (.Key "" "").Typ "none") }}
io.envoyproxy.pgv.MapValidation.validateParts({{ accessor . }}.keySet(), key -> {
{{ render (.Key "key" "Key") }}
});
io.envoyproxy.pgv.MapValidation.validateParts({{ accessor . }}.values(), value -> {
{{ render (.Elem "value" "Value") }}
});
{{- end -}}
`