diff --git a/examples/kube_resource/complex/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k b/examples/kube_resource/complex/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k index 28949ea..e9cd03c 100644 --- a/examples/kube_resource/complex/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k +++ b/examples/kube_resource/complex/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k @@ -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: @@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0: check: - regex.match(name, r"(^[a-z]+$") + regex.match(str(name), r"^[a-z]+$") schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe: diff --git a/pkg/kube_resource/generator/testdata/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k b/pkg/kube_resource/generator/testdata/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k index 28949ea..e9cd03c 100644 --- a/pkg/kube_resource/generator/testdata/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k +++ b/pkg/kube_resource/generator/testdata/muti_models/models/core_oam_dev_v1alpha2_containerized_workload.k @@ -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: @@ -285,7 +285,7 @@ schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0PortsItems0: check: - regex.match(name, r"(^[a-z]+$") + regex.match(str(name), r"^[a-z]+$") schema CoreOamDevV1alpha2ContainerizedWorkloadSpecContainersItems0ReadiessProbe: diff --git a/pkg/swagger/generator/templates/schemavalidator.gotmpl b/pkg/swagger/generator/templates/schemavalidator.gotmpl index 632ca67..e6f7392 100644 --- a/pkg/swagger/generator/templates/schemavalidator.gotmpl +++ b/pkg/swagger/generator/templates/schemavalidator.gotmpl @@ -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 }} @@ -14,7 +14,7 @@ len({{ .EscapedName }}) >= {{.MinLength}} {{- end }} {{- if .Pattern }} - regex.match({{ .EscapedName }}, r"({{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }} + regex.match({{ .EscapedName }}, r"{{.Pattern}}"){{ if not .Required }} if {{ .EscapedName }}{{ end }} {{- end }} {{- if .UniqueItems }} isunique({{ .EscapedName }}) @@ -25,6 +25,9 @@ {{- if .MaxItems }} len({{ .EscapedName }}) <= {{ .MaxItems }} {{- end }} + {{- if .MultipleOf }} + multiplyof(int({{ .EscapedName }}), int({{ .MultipleOf }})) + {{- end }} {{- end -}} {{- end -}} {{- end -}}