Skip to content

Commit 7a470ba

Browse files
authored
fix: schema validator templates (#74)
Signed-off-by: peefy <[email protected]>
1 parent d66c060 commit 7a470ba

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

examples/kube_resource/complex/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0EnvItems0:
149149

150150

151151
check:
152-
regex.match(name, r"(^[-_a-zA-Z0-9]+$")
152+
regex.match(str(name), r"^[-_a-zA-Z0-9]+$")
153153

154154

155155
schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0LivenessProbe:
@@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0:
285285

286286

287287
check:
288-
regex.match(name, r"(^[a-z]+$")
288+
regex.match(str(name), r"^[a-z]+$")
289289

290290

291291
schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe:

pkg/kube_resource/generator/testdata/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0EnvItems0:
149149

150150

151151
check:
152-
regex.match(name, r"(^[-_a-zA-Z0-9]+$")
152+
regex.match(str(name), r"^[-_a-zA-Z0-9]+$")
153153

154154

155155
schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0LivenessProbe:
@@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0:
285285

286286

287287
check:
288-
regex.match(name, r"(^[a-z]+$")
288+
regex.match(str(name), r"^[a-z]+$")
289289

290290

291291
schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe:

pkg/swagger/generator/templates/schemavalidator.gotmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- define "schemavalidator" -}}
22
{{- range . -}}
3-
{{- if or .Required .Maximum .Minimum .MaxLength .MinLength .Pattern .UniqueItems .Enum }}
3+
{{- if or .Maximum .Minimum .MaxLength .MinLength .Pattern .UniqueItems .MinItems .MaxItems .MultipleOf }}
44
{{- if .Maximum }}
55
{{ if .ExclusiveMaximum }}{{ .EscapedName }} < {{.Maximum}}{{- else }}{{ .EscapedName }} <= {{.Maximum}}{{ end }}
66
{{- end }}
@@ -14,7 +14,7 @@
1414
len({{ .EscapedName }}) >= {{.MinLength}}
1515
{{- end }}
1616
{{- if .Pattern }}
17-
regex.match({{ .EscapedName }}, r"({{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }}
17+
regex.match(str({{ .EscapedName }}), r"{{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }}
1818
{{- end }}
1919
{{- if .UniqueItems }}
2020
isunique({{ .EscapedName }})
@@ -25,6 +25,9 @@
2525
{{- if .MaxItems }}
2626
len({{ .EscapedName }}) <= {{ .MaxItems }}
2727
{{- end }}
28+
{{- if .MultipleOf }}
29+
multiplyof(int({{ .EscapedName }}), int({{ .MultipleOf }}))
30+
{{- end }}
2831
{{- end -}}
2932
{{- end -}}
3033
{{- end -}}

0 commit comments

Comments
 (0)