Skip to content

Commit

Permalink
fix: schema validator templates
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Dec 5, 2023
1 parent d8316c0 commit 2ea148b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0EnvItems0:


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


schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0LivenessProbe:
Expand Down Expand Up @@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0:


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


schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0EnvItems0:


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


schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0LivenessProbe:
Expand Down Expand Up @@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0:


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


schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe:
Expand Down
7 changes: 5 additions & 2 deletions pkg/swagger/generator/templates/schemavalidator.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "schemavalidator" -}}
{{- range . -}}
{{- if or .Required .Maximum .Minimum .MaxLength .MinLength .Pattern .UniqueItems .Enum }}
{{- if or .Maximum .Minimum .MaxLength .MinLength .Pattern .UniqueItems .MinItems .MaxItems .MultipleOf }}
{{- if .Maximum }}
{{ if .ExclusiveMaximum }}{{ .EscapedName }} < {{.Maximum}}{{- else }}{{ .EscapedName }} <= {{.Maximum}}{{ end }}
{{- end }}
Expand All @@ -14,7 +14,7 @@
len({{ .EscapedName }}) >= {{.MinLength}}
{{- end }}
{{- if .Pattern }}
regex.match({{ .EscapedName }}, r"({{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }}
regex.match(str({{ .EscapedName }}), r"{{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }}
{{- end }}
{{- if .UniqueItems }}
isunique({{ .EscapedName }})
Expand All @@ -25,6 +25,9 @@
{{- if .MaxItems }}
len({{ .EscapedName }}) <= {{ .MaxItems }}
{{- end }}
{{- if .MultipleOf }}
multiplyof(int({{ .EscapedName }}), int({{ .MultipleOf }}))
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}

0 comments on commit 2ea148b

Please sign in to comment.