diff options
Diffstat (limited to 'vendor/github.com/go-swagger/go-swagger/generator/templates/client/parameter.gotmpl')
| -rw-r--r-- | vendor/github.com/go-swagger/go-swagger/generator/templates/client/parameter.gotmpl | 406 |
1 files changed, 0 insertions, 406 deletions
diff --git a/vendor/github.com/go-swagger/go-swagger/generator/templates/client/parameter.gotmpl b/vendor/github.com/go-swagger/go-swagger/generator/templates/client/parameter.gotmpl deleted file mode 100644 index 3546fa273..000000000 --- a/vendor/github.com/go-swagger/go-swagger/generator/templates/client/parameter.gotmpl +++ /dev/null @@ -1,406 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - - -{{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }} - - -package {{ .Package }} - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "context" - "fmt" - "net/http" - "time" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - cr "github.com/go-openapi/runtime/client" - "github.com/go-openapi/strfmt" - "github.com/go-openapi/swag" - "github.com/go-openapi/validate" - - {{ imports .DefaultImports }} - {{ imports .Imports }} -) - -// New{{ pascalize .Name }}Params creates a new {{ pascalize .Name }}Params object, -// with the default timeout for this client. -// -// Default values are not hydrated, since defaults are normally applied by the API server side. -// -// To enforce default values in parameter, use SetDefaults or WithDefaults. -func New{{ pascalize .Name }}Params() *{{ pascalize .Name }}Params { - return &{{ pascalize .Name}}Params{ - {{ camelize .TimeoutName }}: cr.DefaultTimeout, - } -} - -// New{{ pascalize .Name }}ParamsWithTimeout creates a new {{ pascalize .Name }}Params object -// with the ability to set a timeout on a request. -func New{{ pascalize .Name }}ParamsWithTimeout(timeout time.Duration) *{{ pascalize .Name }}Params { - return &{{ pascalize .Name}}Params{ - {{ camelize .TimeoutName }}: timeout, - } -} - -// New{{ pascalize .Name }}ParamsWithContext creates a new {{ pascalize .Name }}Params object -// with the ability to set a context for a request. -func New{{ pascalize .Name }}ParamsWithContext(ctx context.Context) *{{ pascalize .Name }}Params { - return &{{ pascalize .Name}}Params{ - Context: ctx, - } -} - -// New{{ pascalize .Name }}ParamsWithHTTPClient creates a new {{ pascalize .Name }}Params object -// with the ability to set a custom HTTPClient for a request. -func New{{ pascalize .Name }}ParamsWithHTTPClient(client *http.Client) *{{ pascalize .Name }}Params { - return &{{ pascalize .Name}}Params{ - HTTPClient: client, - } -} - -/* {{ pascalize .Name }}Params contains all the parameters to send to the API endpoint - for the {{ humanize .Name }} operation. - - Typically these are written to a http.Request. -*/ -type {{ pascalize .Name }}Params struct { - {{- range .Params }} - {{- if .Description }} - - /* {{ pascalize .Name }}. - - {{ blockcomment .Description }} - {{- if or .SwaggerFormat .Default }} - {{ print "" }} - {{- if .SwaggerFormat }} - Format: {{ .SwaggerFormat }} - {{- end }} - {{- if .Default }} - Default: {{ json .Default }} - {{- end }} - {{- end }} - */ - {{- else }} - - // {{ pascalize .Name }}. - {{- if or .SwaggerFormat .Default }} - // - {{- if .SwaggerFormat }} - // Format: {{ .SwaggerFormat }} - {{- end }} - {{- if .Default }} - // Default: {{ json .Default }} - {{- end }} - {{- end }} - {{- end }} - {{ pascalize .ID }} {{ if and (not .IsArray) (not .IsMap) (not .HasDiscriminator) (not .IsInterface) (not .IsStream) (or .IsNullable ) }}*{{ end }}{{ if not .IsFileParam }}{{ .GoType }}{{ else }}runtime.NamedReadCloser{{ end }} - {{- end }} - - {{ camelize .TimeoutName }} time.Duration - Context context.Context - HTTPClient *http.Client -} - -// WithDefaults hydrates default values in the {{ humanize .Name }} params (not the query body). -// -// All values with no default are reset to their zero value. -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WithDefaults() *{{ pascalize .Name }}Params { - {{ .ReceiverName }}.SetDefaults() - return {{ .ReceiverName }} -} - -// SetDefaults hydrates default values in the {{ humanize .Name }} params (not the query body). -// -// All values with no default are reset to their zero value. -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) SetDefaults() { -{{- if .Params.HasSomeDefaults }} - var ( - {{- range .Params }} - {{- if .HasDefault }} - {{- if .IsFileParam }} - // NOTE: no default supported for file parameter {{ .ID }} - {{- else if .IsStream }} - // NOTE: no default supported for stream parameter {{ .ID }} - {{- else if not .IsBodyParam }} - {{ template "simpleschemaDefaultsvar" . }} - {{- end }} - {{- end }} - {{- end }} - ) - {{- range .Params }} - {{- if and .HasDefault (not .IsFileParam) (not .IsStream) (not .IsBodyParam) }} - {{ template "simpleschemaDefaultsinit" . }} - {{- end }} - {{- end }} - - val := {{ pascalize .Name }}Params{ - {{- range .Params }} - {{- if and .HasDefault (not .IsFileParam) (not .IsStream) (not .IsBodyParam) }} - {{ pascalize .ID }}: {{ if and (not .IsArray) (not .IsMap) (not .HasDiscriminator) (or .IsNullable ) }}&{{ end }}{{ varname .ID }}Default, - {{- end }} - {{- end }} - } - - val.{{ camelize .TimeoutName }} = {{ .ReceiverName }}.{{ camelize .TimeoutName }} - val.Context = {{ .ReceiverName }}.Context - val.HTTPClient = {{ .ReceiverName }}.HTTPClient - *{{ .ReceiverName }} = val -{{- else }} - // no default values defined for this parameter -{{- end }} -} - -// With{{ pascalize .TimeoutName }} adds the timeout to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) With{{ pascalize .TimeoutName }}(timeout time.Duration) *{{ pascalize .Name }}Params { - {{ .ReceiverName }}.Set{{ pascalize .TimeoutName }}(timeout) - return {{ .ReceiverName }} -} - -// Set{{ pascalize .TimeoutName }} adds the timeout to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) Set{{ pascalize .TimeoutName }}(timeout time.Duration) { - {{ .ReceiverName }}.{{ camelize .TimeoutName }} = timeout -} - -// WithContext adds the context to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WithContext(ctx context.Context) *{{ pascalize .Name }}Params { - {{ .ReceiverName }}.SetContext(ctx) - return {{ .ReceiverName }} -} - -// SetContext adds the context to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) SetContext(ctx context.Context) { - {{ .ReceiverName }}.Context = ctx -} - -// WithHTTPClient adds the HTTPClient to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WithHTTPClient(client *http.Client) *{{ pascalize .Name }}Params { - {{ .ReceiverName }}.SetHTTPClient(client) - return {{ .ReceiverName }} -} - -// SetHTTPClient adds the HTTPClient to the {{ humanize .Name }} params -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) SetHTTPClient(client *http.Client) { - {{ .ReceiverName }}.HTTPClient = client -} - -{{- range .Params }} - -// With{{ pascalize .ID }} adds the {{ varname .Name }} to the {{ humanize $.Name }} params -func ({{ $.ReceiverName }} *{{ pascalize $.Name }}Params) With{{ pascalize .ID }}({{ varname .Name }} {{ if and (not .IsArray) (not .IsMap) (not .HasDiscriminator) (not .IsStream) (or .IsNullable ) }}*{{ end }}{{ if not .IsFileParam }}{{ .GoType }}{{ else }}runtime.NamedReadCloser{{ end }}) *{{ pascalize $.Name }}Params { - {{ $.ReceiverName }}.Set{{ pascalize .ID }}({{ varname .Name }}) - return {{ .ReceiverName }} -} - -// Set{{ pascalize .ID }} adds the {{ camelize .Name }} to the {{ humanize $.Name }} params -func ({{ $.ReceiverName }} *{{ pascalize $.Name }}Params) Set{{ pascalize .ID }}({{ varname .Name }} {{ if and (not .IsArray) (not .IsMap) (not .HasDiscriminator) (not .IsStream) (or .IsNullable ) }}*{{ end }}{{ if not .IsFileParam }}{{ .GoType }}{{ else }}runtime.NamedReadCloser{{ end }}) { - {{ $.ReceiverName }}.{{ pascalize .ID }} = {{ varname .Name }} -} -{{- end }} - -// WriteToRequest writes these params to a swagger request -func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { - - if err := r.SetTimeout({{ .ReceiverName }}.{{ camelize .TimeoutName }}); err != nil { - return err - } - var res []error - {{- range .Params }} - {{- if not (or .IsArray .IsMap .IsBodyParam) }} - {{- if and .IsNullable (not .AllowEmptyValue) }} - - if {{ .ValueExpression }} != nil { - {{- end}} - - {{- if .IsQueryParam }} - - // query param {{ .Name }} - {{- if .IsNullable }} - var qr{{ pascalize .Name }} {{ .GoType }} - - if {{ .ValueExpression }} != nil { - qr{{ pascalize .Name }} = *{{ .ValueExpression }} - } - {{- else }} - qr{{ pascalize .Name }} := {{ .ValueExpression }} - {{- end}} - q{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(qr{{ pascalize .Name }}){{ else }}qr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}} - {{- if not .AllowEmptyValue }} - if q{{ pascalize .Name }} != "" { - {{- end }} - - if err := r.SetQueryParam({{ printf "%q" .Name }}, q{{ pascalize .Name }}); err != nil { - return err - } - {{- if not .AllowEmptyValue }} - } - {{- end }} - - {{- else if .IsPathParam }} - - // path param {{ .Name }} - if err := r.SetPathParam({{ printf "%q" .Name }}, {{ if .Formatter }}{{ .Formatter }}({{ if .IsNullable }}*{{end}}{{ .ValueExpression }}){{ else }}{{ if and (not .IsCustomFormatter) .IsNullable }}*{{end}}{{ .ValueExpression }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}); err != nil { - return err - } - - {{- else if .IsHeaderParam }} - - // header param {{ .Name }} - if err := r.SetHeaderParam({{ printf "%q" .Name }}, {{ if .Formatter }}{{ .Formatter }}({{ if .IsNullable }}*{{end}}{{ .ValueExpression }}){{ else }}{{ if and (not .IsCustomFormatter) .IsNullable }}*{{end}}{{ .ValueExpression }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}); err != nil { - return err - } - {{- else if .IsFormParam }} - {{- if .IsFileParam }} - {{- if .IsNullable }} - - if {{ .ValueExpression }} != nil { - {{- end }} - // form file param {{ .Name }} - if err := r.SetFileParam({{ printf "%q" .Name }}, {{ .ValueExpression }}); err != nil { - return err - } - {{- if .IsNullable}} - } - {{- end }} - {{- else }} - - // form param {{ .Name }} - {{- if .IsNullable }} - var fr{{ pascalize .Name }} {{ .GoType }} - if {{ .ValueExpression }} != nil { - fr{{ pascalize .Name }} = *{{ .ValueExpression }} - } - {{- else }} - fr{{ pascalize .Name }} := {{ .ValueExpression }} - {{- end}} - f{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(fr{{ pascalize .Name }}){{ else }}fr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}} - {{- if not .AllowEmptyValue }} - if f{{ pascalize .Name }} != "" { - {{- end }} - if err := r.SetFormParam({{ printf "%q" .Name }}, f{{ pascalize .Name }}); err != nil { - return err - } - {{- if not .AllowEmptyValue }} - } - {{- end }} - {{- end }} - {{- end }} - {{- if and .IsNullable (not .AllowEmptyValue) }} - } - {{- end }} - {{- else if .IsArray }} - - {{- if not .IsBodyParam }} - - if {{ .ValueExpression }} != nil { - - {{- if .Child }}{{/* bind complex parameters (arrays and nested structures) */}} - - // binding items for {{ .Name }} - joined{{ pascalize .Name }} := {{ .ReceiverName }}.bindParam{{ pascalize .Name }}(reg) - {{- else }} - values{{ pascalize .Name }} := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }} - joined{{ pascalize .Name}} := swag.JoinByFormat(values{{ pascalize .Name }}, "{{.CollectionFormat}}") - {{- end }} - - {{- if .IsQueryParam }} - - // query array param {{ .Name }} - if err := r.SetQueryParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}...); err != nil { - return err - } - - {{- else if and .IsFormParam }} - - // form array param {{ .Name }} - if err := r.SetFormParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}...); err != nil { - return err - } - - {{- else if and .IsPathParam }} - - // path array param {{ .Name }} - // SetPathParam does not support variadic arguments, since we used JoinByFormat - // we can send the first item in the array as it's all the items of the previous - // array joined together - if len(joined{{ pascalize .Name }}) > 0 { - if err := r.SetPathParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}[0]); err != nil { - return err - } - } - - {{- else if .IsHeaderParam }} - - // header array param {{ .Name }} - if len(joined{{ pascalize .Name }}) > 0 { - if err := r.SetHeaderParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}[0]); err != nil { - return err - } - } - {{- end }} - } - {{- end }} - {{- end }} - - {{- if .IsBodyParam }} - {{- if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }} - if {{ .ValueExpression }} != nil { - {{- end }} - if err := r.SetBodyParam({{ .ValueExpression }}); err != nil { - return err - } - {{- if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }} - } - {{- end }} - {{- end }} - - {{- end }} - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} - -{{- range .Params }} - {{- if and (not .IsBodyParam) (not .IsFileParam) .IsArray }} -// bindParam{{ pascalize $.Name }} binds the parameter {{ .Name }} -func ({{ .ReceiverName }} *{{ pascalize $.Name }}Params) bindParam{{ pascalize .Name }}(formats strfmt.Registry) []string { - {{ varname .Child.ValueExpression }}R := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }} - - {{ template "sliceclientparambinder" . }} - - return {{ varname .Child.ValueExpression }}S -} - {{- end }} -{{- end }} -{{- define "sliceclientparambinder" }} - {{- if .IsArray }} - var {{ varname .Child.ValueExpression }}C []string - for _, {{ varname .Child.ValueExpression }}IR := range {{ varname .Child.ValueExpression }}R { // explode {{ .GoType }} - {{ template "sliceclientparambinder" .Child }} - {{ varname .Child.ValueExpression }}C = append({{ varname .Child.ValueExpression }}C, {{ varname .Child.ValueExpression }}IV) - } - - // {{ .Child.ItemsDepth }}CollectionFormat: {{ printf "%q" .CollectionFormat }} - {{ varname .Child.ValueExpression }}S := swag.JoinByFormat({{ varname .Child.ValueExpression }}C, {{ printf "%q" .CollectionFormat }}) - {{- if .Child.Parent }}{{/* NOTE: we cannot expect a "multi" CollectionFormat within an inner array */}} - {{ varname .Child.ValueExpression }}V := {{ varname .Child.ValueExpression }}S[0] - {{- end }} - - {{- else }} - {{ varname .ValueExpression }}IV := - {{- if .IsCustomFormatter }} - {{- print " " }}{{ varname .ValueExpression }}IR.String() - {{- else if eq .GoType "string" }} - {{- print " " }}{{ varname .ValueExpression }}IR - {{- else if .Formatter }} - {{- print " "}}{{ .Formatter }}({{ varname .ValueExpression }}IR) - {{- else }} - {{- print " " }}fmt.Sprintf("%v", {{ varname .ValueExpression }}IR) - {{- end }} // {{ .GoType }} as string - {{- end }} -{{- end }} |
