Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-swagger/go-swagger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: osixia/go-swagger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Sep 6, 2019

  1. Copy the full SHA
    bd000b5 View commit details

Commits on Sep 27, 2019

  1. Copy the full SHA
    0a5a47b View commit details

Commits on Oct 22, 2019

  1. Merge tag 'v0.21.0'

    [Full Changelog](v0.20.1...v0.21.0)
    
    **Implemented enhancements:**
    
    - Add warning messages for inconsistent parameter types and validations [\#2069](#2069)
    
    **Fixed bugs:**
    
    - JSON tags are not honored in case of allOf. [\#2071](#2071)
    
    **Closed issues:**
    
    - How to register a handler for the server? [\#2083](#2083)
    - Flatten before serve [\#2078](#2078)
    - Additional keys in response model [\#2073](#2073)
    - Go v0.20.0: checksum mismatch when using GOPROXY=direct [\#2065](#2065)
    - Code generation fails when swagger is built with go1.13 [\#2058](#2058)
    - feature: support custom swagger type [\#1183](#1183)
    
    **Merged pull requests:**
    
    - Add OpenAPI Terraform provider to 'Who is using this project?' section [\#2084](#2084) ([dikhan](https://github.com/dikhan))
    - Add flag to allow overwriting protected templates [\#2082](#2082) ([dominikznidar](https://github.com/dominikznidar))
    - Feat\(serve\) : Add flatten flag to serve command [\#2079](#2079) ([seblegall](https://github.com/seblegall))
    - added contrib to the docker image [\#2076](#2076) ([ronnie-stratoscale](https://github.com/ronnie-stratoscale))
    - Keep spec orders for mixin command [\#2074](#2074) ([BupycHuk](https://github.com/BupycHuk))
    - fixes undue propagation of x-go-name to tags in AllOf serializer [\#2072](#2072) ([fredbi](https://github.com/fredbi))
    - Provide example for configure command-line flags [\#2068](#2068) ([antonok](https://github.com/antonok))
    - Add default flag support  `import "flags"` [\#2067](#2067) ([hisunwei](https://github.com/hisunwei))
    - Added installation instructions through docker for windows users [\#2061](#2061) ([EliCDavis](https://github.com/EliCDavis))
    - update go-openapi libraries for go 1.13 fix [\#2059](#2059) ([casualjim](https://github.com/casualjim))
    
    \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
    BertrandGouny committed Oct 22, 2019
    Copy the full SHA
    487f909 View commit details

Commits on Oct 29, 2019

  1. Copy the full SHA
    af139c9 View commit details
32 changes: 16 additions & 16 deletions generator/bindata.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions generator/model.go
Original file line number Diff line number Diff line change
@@ -341,6 +341,8 @@ func makeGenDefinitionHierarchy(name, pkg, container string, schema spec.Schema,
"github.com/go-openapi/runtime",
"github.com/go-openapi/swag",
"github.com/go-openapi/validate",
"github.com/go-openapi/runtime/middleware",
"gitlab.osixia.net/go/x/go-swagger/extensions",
}

return &GenDefinition{
2 changes: 1 addition & 1 deletion generator/templates/schema.gotmpl
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ func Unmarshal{{ pascalize .Name }}Slice(reader io.Reader, consumer runtime.Cons
{{ template "schemavalidator" . }}
{{- else if not (or .IsInterface .IsStream) -}}
// Validate validates this {{ humanize .Name }}{{/* this schema implements the runtime.Validatable interface but has no validations to check */}}
func ({{.ReceiverName}} {{ if or .IsTuple .IsComplexObject .IsAdditionalProperties }}*{{ end }}{{ if or (not .IsExported) .Discriminates }}{{ camelize .Name }}{{ else }}{{ pascalize .Name }}{{ end }}) Validate(formats strfmt.Registry) error {
func ({{.ReceiverName}} {{ if or .IsTuple .IsComplexObject .IsAdditionalProperties }}*{{ end }}{{ if or (not .IsExported) .Discriminates }}{{ camelize .Name }}{{ else }}{{ pascalize .Name }}{{ end }}) Validate(route *middleware.MatchedRoute) error {
return nil
}
{{- else -}}
76 changes: 54 additions & 22 deletions generator/templates/schemavalidator.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{{ define "primitivefieldvalidator" }}
{{ if .Required }}
if err := validate.Required{{ if and (eq .GoType "string") (not .IsNullable) }}String{{ end }}({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ if not (or .IsAnonymous .IsNullable) }}{{ .GoType }}({{ end }}{{.ValueExpression }}{{ if not (or .IsAnonymous .IsNullable) }}){{ end }}); err != nil {
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{ end }}
@@ -48,6 +51,9 @@
{{define "slicevalidator" }}
{{ if .Required }}
if err := validate.Required({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ .ValueExpression }}); err != nil {
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{ end }}
@@ -93,7 +99,7 @@
{{- if and .IsNullable (not .IsMapNullOverride) }}
if {{ .ValueExpression }} != nil {
{{- end }}
if err := {{.ValueExpression }}.Validate(formats); err != nil {
if err := {{.ValueExpression }}.Validate(route); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName({{ if .Path }}{{ .Path }}{{ else }}""{{ end }})
}
@@ -116,7 +122,10 @@
}
{{- else if and (.Required) (not .IsArray) }}{{/* Required slice is processed below */}}
if err := validate.Required({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{.ValueExpression }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{- if .IsPrimitive }}
@@ -126,7 +135,7 @@
{{- if and .IsNullable (not .IsMapNullOverride) }}
if val != nil {
{{- end }}
if err := val.Validate(formats); err != nil {
if err := val.Validate(route); err != nil {
return err
}
{{- if and .IsNullable (not .IsMapNullOverride) }}
@@ -153,7 +162,10 @@
{{- else if and .IsCustomFormatter (or .HasValidations .Required) }}{{/* custom format not captured as primitive */}}
{{- if .Required }}
if err := validate.Required{{ if and (eq .GoType "string") (not .IsNullable) }}String{{ end }}({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ if not (or .IsAnonymous .IsNullable) }}{{ .GoType }}({{ end }}{{.ValueExpression }}{{ if not (or .IsAnonymous .IsNullable) }}){{ end }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{- if not .IsStream }}{{/* TODO: IsStream and CustomFormattershould be mutually exclusive in type resolver */}}
@@ -174,7 +186,7 @@
{{- if and .IsNullable (not .IsMapNullOverride) }}
if val != nil {
{{- end }}
if err := val.Validate(formats); err != nil {
if err := val.Validate(route); err != nil {
return err
}
{{- if and .IsNullable (not .IsMapNullOverride) }}
@@ -208,7 +220,10 @@
{{- else if .IsAliased }}
{{- if and .Required .IsInterface }}
if err := validate.Required({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{.ValueExpression }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{- if and .IsMap .HasValidations }}{{/* validation of aliased maps but does not know about AdditionalProperties: e.g. it comes from a $ref */}}
@@ -223,7 +238,7 @@
if {{ .ValueExpression }} != nil {
{{- end }}
{{- end }}
if err := {{ if $.IsMap }}val{{ else }}{{ .ValueExpression }}{{ end }}.Validate(formats); err != nil {
if err := {{ if $.IsMap }}val{{ else }}{{ .ValueExpression }}{{ end }}.Validate(route); err != nil {
return err
}
{{- if and .IsNullable (not .IsMapNullOverride) }}
@@ -250,7 +265,10 @@
{{- if not .IsAnonymous }}
{{- if and .Required (or .IsNullable .IsBaseType) }}
if err := validate.Required({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{.ValueExpression }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- if and (not .Required) .IsBaseType }}
if {{ .ValueExpression }} == nil {
@@ -262,7 +280,12 @@
{{- if and .IsNullable (not .IsMapNullOverride) }}
if {{ .ValueExpression }} != nil {
{{- end }}
if err := {{.ValueExpression }}.Validate(formats); err != nil {
{{- if .Required }}
if swag.IsZero({{ .ValueExpression }}) && extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
{{- end }}
if err := {{.ValueExpression }}.Validate(route); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName({{ if .Path }}{{ .Path }}{{ else }}""{{ end }})
}
@@ -298,7 +321,10 @@
{{- else if and .IsCustomFormatter (or .HasValidations .Required) }}{{/* custom format not captured as primitive */}}
{{- if .Required }}
if err := validate.Required{{ if and (eq .GoType "string") (not .IsNullable) }}String{{ end }}({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ if not (or .IsAnonymous .IsNullable) }}{{ .GoType }}({{ end }}{{.ValueExpression }}{{ if not (or .IsAnonymous .IsNullable) }}){{ end }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{- if not .IsStream }}
@@ -319,7 +345,10 @@
{{- else if and .IsCustomFormatter (or .HasValidations .Required) }}{{/* custom format not captured as primitive */}}
{{- if .Required }}
if err := validate.Required{{ if and (eq .GoType "string") (not .IsNullable) }}String{{ end }}({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ if not (or .IsAnonymous .IsNullable) }}{{ .GoType }}({{ end }}{{.ValueExpression }}{{ if not (or .IsAnonymous .IsNullable) }}){{ end }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{- if not .IsStream }}
@@ -407,7 +436,7 @@ func ({{ .ReceiverName }} *{{ if .IsExported }}{{ pascalize .Name }}{{ else }}{{
{{- end }}
{{ end }}
// Validate validates this {{ humanize .Name }}
func ({{.ReceiverName }} {{ if or .IsTuple .IsComplexObject .IsAdditionalProperties }}*{{ end }}{{ if .Discriminates }}{{ camelize .Name }}{{ else if .IsExported }}{{ pascalize .Name }}{{ else }}{{ .Name }}{{ end }}) Validate(formats strfmt.Registry) error {
func ({{.ReceiverName }} {{ if or .IsTuple .IsComplexObject .IsAdditionalProperties }}*{{ end }}{{ if .Discriminates }}{{ camelize .Name }}{{ else if .IsExported }}{{ pascalize .Name }}{{ else }}{{ .Name }}{{ end }}) Validate(route *middleware.MatchedRoute) error {
var res []error

{{ range .AllOf }}
@@ -419,7 +448,7 @@ func ({{.ReceiverName }} {{ if or .IsTuple .IsComplexObject .IsAdditionalPropert

{{ range .Properties }}
{{ if and (ne $.DiscriminatorField .Name) (or .Required .HasValidations) }}
if err := {{.ReceiverName }}.validate{{ pascalize .Name }}(formats); err != nil {
if err := {{.ReceiverName }}.validate{{ pascalize .Name }}(route); err != nil {
res = append(res, err)
}
{{- end }}
@@ -428,20 +457,20 @@ func ({{.ReceiverName }} {{ if or .IsTuple .IsComplexObject .IsAdditionalPropert
{{ template "mapvalidator" . }}
{{- end }}
{{ if and .IsTuple .AdditionalItems }}
if err := {{ .ReceiverName }}.validate{{ pascalize .Name }}Items(formats); err != nil {
if err := {{ .ReceiverName }}.validate{{ pascalize .Name }}Items(route); err != nil {
res = append(res, err)
}
{{ end }}
{{- else if (or .Required .HasValidations) }}
if err := {{ .ReceiverName }}.{{ pascalize (dropPackage .GoType) }}.Validate(formats); err != nil {
if err := {{ .ReceiverName }}.{{ pascalize (dropPackage .GoType) }}.Validate(route); err != nil {
res = append(res, err)
}
{{- end }}
{{- end }}
{{ template "fieldvalidator" . }}
{{ range .Properties }}
{{ if and (ne $.DiscriminatorField .Name) (or .Required .HasValidations) }}
if err := {{.ReceiverName }}.validate{{ pascalize .Name }}(formats); err != nil {
if err := {{.ReceiverName }}.validate{{ pascalize .Name }}(route); err != nil {
res = append(res, err)
}
{{ end }}
@@ -450,7 +479,7 @@ func ({{.ReceiverName }} {{ if or .IsTuple .IsComplexObject .IsAdditionalPropert
{{ template "mapvalidator" . }}
{{- end }}
{{ if and .IsTuple .AdditionalItems }}{{/* validates additionalItems in a tuple */}}
if err := {{ .ReceiverName }}.validate{{ pascalize .Name }}Items(formats); err != nil {
if err := {{ .ReceiverName }}.validate{{ pascalize .Name }}Items(route); err != nil {
res = append(res, err)
}
{{ end }}
@@ -567,15 +596,18 @@ func ({{ .ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else
{{ end }}

{{ if and (ne $.DiscriminatorField .Name) (or .Required .HasValidations) }}
func ({{.ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else if $.IsExported }}{{ pascalize $.Name }}{{ else }}{{ $.Name }}{{ end }}) validate{{ pascalize .Name }}(formats strfmt.Registry) error {
func ({{.ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else if $.IsExported }}{{ pascalize $.Name }}{{ else }}{{ $.Name }}{{ end }}) validate{{ pascalize .Name }}(route *middleware.MatchedRoute) error {
{{ if not .Required }}
if swag.IsZero({{ .ValueExpression }}) { // not required
return nil
}
{{ end }}
{{- if and $.IsTuple .IsMap .Required }}
if err := validate.Required{{ if and (eq .GoType "string") (not .IsNullable) }}String{{ end }}({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ if not (or .IsAnonymous .IsNullable) }}{{ .GoType }}({{ end }}{{.ValueExpression }}{{ if not (or .IsAnonymous .IsNullable) }}){{ end }}); err != nil {
return err
if extensions.SkipRequiredOnUpdate({{.ReceiverName }}, route.Operation) {
return nil;
}
return err
}
{{- end }}
{{template "propertyvalidator" . }}
@@ -675,7 +707,7 @@ func ({{ .ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else
{{ end }}


func ({{.ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else if $.IsExported }}{{ pascalize $.Name }}{{ else }}{{ $.Name }}{{ end }}) validate{{ pascalize .Name }}(formats strfmt.Registry) error {
func ({{.ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else if $.IsExported }}{{ pascalize $.Name }}{{ else }}{{ $.Name }}{{ end }}) validate{{ pascalize .Name }}(route *middleware.MatchedRoute) error {
{{ if not .Required }}
if swag.IsZero({{ .ValueExpression }}) { // not required
return nil
@@ -710,7 +742,7 @@ func ({{ .ReceiverName }} *{{ if $.Discriminates }}{{ camelize $.Name }}{{ else
return nil
}
{{ end }}
func ({{.ReceiverName }} *{{ pascalize .Name }}) validate{{ pascalize .Name }}Items(formats strfmt.Registry) error {
func ({{.ReceiverName }} *{{ pascalize .Name }}) validate{{ pascalize .Name }}Items(route *middleware.MatchedRoute) error {
{{ if or .AdditionalItems.Required .AdditionalItems.HasValidations }}
for {{ .IndexVar }} := range {{ .ValueExpression }}.{{ pascalize .Name }}Items {
{{template "propertyvalidator" .AdditionalItems }}
@@ -719,4 +751,4 @@ func ({{.ReceiverName }} *{{ pascalize .Name }}) validate{{ pascalize .Name }}It
return nil
}
{{ end }}
{{ end }}
{{ end }}
48 changes: 24 additions & 24 deletions generator/templates/server/parameter.gotmpl
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
{{ define "bodyvalidator" }}
{{- if .HasModelBodyParams }}
// validate body object{{/* delegate validation to model object */}}
if err := body.Validate(route.Formats); err != nil {
if err := body.Validate(route); err != nil {
res = append(res, err)
}

@@ -33,7 +33,7 @@
{{- end }}
}
{{- end }}
if err := body[{{ .IndexVar }}].Validate(route.Formats); err != nil {
if err := body[{{ .IndexVar }}].Validate(route); err != nil {
res = append(res, err)
break
}
@@ -73,7 +73,7 @@
{{- if and .IsNullable (not .IsMapNullOverride) }}
if val != nil {
{{- end }}
if err := val.Validate(route.Formats); err != nil {
if err := val.Validate(route); err != nil {
res = append(res, err)
break
}
@@ -94,13 +94,13 @@
{{- if and (not .IsArray) (not .IsMap) .Schema.HasValidations }}
// validate inline body
{{ .ReceiverName }}.{{ pascalize .Name }} = {{ if and (not .Schema.IsBaseType) .IsNullable }}&{{ end }}body
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}Body(route.Formats); err != nil {
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}Body(route); err != nil {
res = append(res, err)
}
{{- else if and (or .IsArray .IsMap) .Schema.HasValidations }}
// validate inline body {{ if .IsArray }}array{{ else }}map{{ end }}
{{ .ReceiverName }}.{{ pascalize .Name }} = {{ if and (not .Schema.IsBaseType) .IsNullable }}&{{ end }}body
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}Body(route.Formats); err != nil {
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}Body(route); err != nil {
res = append(res, err)
}
{{- else }}
@@ -167,14 +167,14 @@ if err := validate.Enum(
}
{{- else if and .IsCustomFormatter (not .SkipParse) }}{{/* parsing is skipped for simple body items */}}
// {{ .ItemsDepth }}Format: {{ printf "%q" .SwaggerFormat }}
value, err := formats.Parse({{ printf "%q" .SwaggerFormat }},{{ varname .ValueExpression }}V)
value, err := route.Formats.Parse({{ printf "%q" .SwaggerFormat }},{{ varname .ValueExpression }}V)
if err != nil {
return errors.InvalidType({{ .Path }}, {{ printf "%q" .Location }}, "{{ .GoType }}", value)
}
{{ varname .ValueExpression }} := *(value.(*{{.GoType}}))
{{- else if and .IsComplexObject .HasValidations }}{{/* dedicated to nested body params */}}
{{ varname .ValueExpression }} := {{ varname .ValueExpression }}V
if err := {{ .ValueExpression }}.Validate(formats) ; err != nil {
if err := {{ .ValueExpression }}.Validate(route) ; err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName({{ .Path }})
}
@@ -227,7 +227,7 @@ if err := validate.Enum(
{{- end }}
{{- if and .IsCustomFormatter (not .IsStream) }}
{{- if ne .SwaggerFormat "byte" }}
if err := validate.FormatOf({{.Path}}, "{{.Location}}", "{{.SwaggerFormat}}", {{ .ValueExpression}}.String(), formats); err != nil {
if err := validate.FormatOf({{.Path}}, "{{.Location}}", "{{.SwaggerFormat}}", {{ .ValueExpression}}.String(), route.Formats); err != nil {
return err
}
{{- else }}
@@ -404,14 +404,14 @@ func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) BindRequest(r *http.Requ
{{ range .Params }}
{{ if not .IsArray -}}
{{ if .IsQueryParam }}q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, _ := qs.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ else if .IsPathParam }}r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, _ := route.Params.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ else if .IsHeaderParam }}if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r.Header[http.CanonicalHeaderKey({{ .Path }})], true, route.Formats); err != nil {
{{ else if .IsHeaderParam }}if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r.Header[http.CanonicalHeaderKey({{ .Path }})], true, route); err != nil {
res = append(res, err)
}
{{ else if .IsFormParam -}}
@@ -426,25 +426,25 @@ func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) BindRequest(r *http.Requ
{{ .ReceiverName }}.{{ pascalize .Name }} = &runtime.File{Data: {{ camelize .Name }}, Header: {{ camelize .Name }}Header}
}
{{ else }}fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, _ := fds.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ end }}{{/* end .FileParam */}}
{{ end }}{{/* end not .Array */}}
{{ else if .IsArray -}}
{{ if .IsQueryParam }}q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, _ := qs.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(q{{ pascalize .Name }}, qhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ else if .IsPathParam }}r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, _ := route.Params.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r{{ pascalize .Name }}, rhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ else if .IsHeaderParam }}if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r.Header[http.CanonicalHeaderKey({{ .Path }})], true, route.Formats); err != nil {
{{ else if .IsHeaderParam }}if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(r.Header[http.CanonicalHeaderKey({{ .Path }})], true, route); err != nil {
res = append(res, err)
}
{{ else if and .IsFormParam }}fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, _ := fds.GetOK({{ .Path }})
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, route.Formats); err != nil {
if err := {{ .ReceiverName }}.bind{{ pascalize .ID }}(fd{{ pascalize .Name }}, fdhk{{ pascalize .Name }}, route); err != nil {
res = append(res, err)
}
{{ end }}{{ end }}
@@ -519,7 +519,7 @@ func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(file
{{- else if not .IsBodyParam }}
{{- if or .IsPrimitive .IsCustomFormatter }}
// bind{{ pascalize .ID }} binds and validates parameter {{ .ID }} from {{ .Location }}.
func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawData []string, hasKey bool, formats strfmt.Registry) error {
func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawData []string, hasKey bool, route *middleware.MatchedRoute) error {
{{- if and (not .IsPathParam) .Required }}
if !hasKey {
return errors.Required({{ .Path }}, {{ printf "%q" .Location }})
@@ -548,14 +548,14 @@ func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawDa
}
{{ .ValueExpression }} = {{ if .IsNullable }}&{{ end }}value
{{ else if .IsCustomFormatter }}// Format: {{ .SwaggerFormat }}
value, err := formats.Parse({{ printf "%q" .SwaggerFormat }}, raw)
value, err := route.Formats.Parse({{ printf "%q" .SwaggerFormat }}, raw)
if err != nil {
return errors.InvalidType({{ .Path }}, {{ printf "%q" .Location }}, {{ printf "%q" .GoType }}, raw)
}
{{ .ValueExpression }} = {{ if and (not .IsArray) (not .HasDiscriminator) (not .IsFileParam) (not .IsStream) (not .IsNullable) }}*{{ end }}(value.(*{{ .GoType }}))
{{else}}{{ .ValueExpression }} = {{ if .IsNullable }}&{{ end }}raw
{{ end }}
{{if .HasValidations }}if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}(formats); err != nil {
{{if .HasValidations }}if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}(route); err != nil {
return err
}
{{ end }}
@@ -565,7 +565,7 @@ func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawDa
// bind{{ pascalize .ID }} binds and validates array parameter {{ .ID }} from {{ .Location }}.
//
// Arrays are parsed according to CollectionFormat: "{{ .CollectionFormat }}" (defaults to "csv" when empty).
func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawData []string, hasKey bool, formats strfmt.Registry) error {
func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawData []string, hasKey bool, route *middleware.MatchedRoute) error {
{{if .Required }}if !hasKey {
return errors.Required({{ .Path }}, {{ printf "%q" .Location }})
}
@@ -592,7 +592,7 @@ func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawDa
{{ template "sliceparambinder" . }}
{{ .ValueExpression }} = {{ varname .Child.ValueExpression }}R
{{- if .HasSliceValidations }}
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}(formats); err != nil {
if err := {{ .ReceiverName }}.validate{{ pascalize .ID }}(route); err != nil {
return err
}
{{- end }}
@@ -602,7 +602,7 @@ func ({{ .ReceiverName }} *{{ $className }}Params) bind{{ pascalize .ID }}(rawDa
{{ end }}
{{ if or (and (not .IsArray) .HasValidations) (and .IsArray .HasSliceValidations) }}
// validate{{ pascalize .ID }} carries on validations for parameter {{ .ID }}
func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}(formats strfmt.Registry) error {
func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}(route *middleware.MatchedRoute) error {
{{ template "propertyparamvalidator" . }}
return nil
}
@@ -611,7 +611,7 @@ func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}(f
{{- if and .HasSimpleBodyParams (not .HasModelBodyItems) (not .HasModelBodyMap) }}
{{- if .Schema.HasValidations }}
// validate{{ pascalize .ID }}Body validates an inline body parameter
func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}Body(formats strfmt.Registry) error {
func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}Body(route *middleware.MatchedRoute) error {
{{- if .IsArray }}
{{- if .HasSliceValidations }}
{{- template "sliceparamvalidator" . }}
@@ -633,4 +633,4 @@ func ({{ .ReceiverName }} *{{ $className }}Params) validate{{ pascalize .ID }}Bo
{{- end }}
{{- end }}
{{- end }}
{{ end }}
{{ end }}
4 changes: 2 additions & 2 deletions generator/templates/validation/customformat.gotmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ if ne .SwaggerFormat "byte" -}}
{{- if .IsAliased }}
if err := validate.FormatOf({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ printf "%q" .SwaggerFormat }}, {{ .AliasedType }}({{.ValueExpression }}).String(), formats); err != nil {
if err := validate.FormatOf({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ printf "%q" .SwaggerFormat }}, {{ .AliasedType }}({{.ValueExpression }}).String(), route.Formats); err != nil {
{{- else }}
if err := validate.FormatOf({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ printf "%q" .SwaggerFormat }}, {{.ValueExpression }}.String(), formats); err != nil {
if err := validate.FormatOf({{ if .Path }}{{ .Path }}{{ else }}""{{ end }}, {{ printf "%q" .Location }}, {{ printf "%q" .SwaggerFormat }}, {{.ValueExpression }}.String(), route.Formats); err != nil {
{{- end }}
return err
}