Blame vendor/github.com/deepmap/oapi-codegen/pkg/codegen/templates/templates.gen.go

Packit Service 3a6627
package templates
Packit Service 3a6627
Packit Service 3a6627
import "text/template"
Packit Service 3a6627
Packit Service 3a6627
var templates = map[string]string{"additional-properties.tmpl": `{{range .Types}}{{$addType := .Schema.AdditionalPropertiesType.TypeDecl}}
Packit Service 3a6627
Packit Service 3a6627
// Getter for additional properties for {{.TypeName}}. Returns the specified
Packit Service 3a6627
// element and whether it was found
Packit Service 3a6627
func (a {{.TypeName}}) Get(fieldName string) (value {{$addType}}, found bool) {
Packit Service 3a6627
    if a.AdditionalProperties != nil {
Packit Service 3a6627
        value, found = a.AdditionalProperties[fieldName]
Packit Service 3a6627
    }
Packit Service 3a6627
    return
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Setter for additional properties for {{.TypeName}}
Packit Service 3a6627
func (a *{{.TypeName}}) Set(fieldName string, value {{$addType}}) {
Packit Service 3a6627
    if a.AdditionalProperties == nil {
Packit Service 3a6627
        a.AdditionalProperties = make(map[string]{{$addType}})
Packit Service 3a6627
    }
Packit Service 3a6627
    a.AdditionalProperties[fieldName] = value
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Override default JSON handling for {{.TypeName}} to handle AdditionalProperties
Packit Service 3a6627
func (a *{{.TypeName}}) UnmarshalJSON(b []byte) error {
Packit Service 3a6627
    object := make(map[string]json.RawMessage)
Packit Service 3a6627
	err := json.Unmarshal(b, &object)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
{{range .Schema.Properties}}
Packit Service 3a6627
    if raw, found := object["{{.JsonFieldName}}"]; found {
Packit Service 3a6627
        err = json.Unmarshal(raw, &a.{{.GoFieldName}})
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
            return errors.Wrap(err, "error reading '{{.JsonFieldName}}'")
Packit Service 3a6627
        }
Packit Service 3a6627
        delete(object, "{{.JsonFieldName}}")
Packit Service 3a6627
    }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
    if len(object) != 0 {
Packit Service 3a6627
        a.AdditionalProperties = make(map[string]{{$addType}})
Packit Service 3a6627
        for fieldName, fieldBuf := range object {
Packit Service 3a6627
            var fieldVal {{$addType}}
Packit Service 3a6627
            err := json.Unmarshal(fieldBuf, &fieldVal)
Packit Service 3a6627
            if err != nil {
Packit Service 3a6627
                return errors.Wrap(err, fmt.Sprintf("error unmarshaling field %s", fieldName))
Packit Service 3a6627
            }
Packit Service 3a6627
            a.AdditionalProperties[fieldName] = fieldVal
Packit Service 3a6627
        }
Packit Service 3a6627
    }
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Override default JSON handling for {{.TypeName}} to handle AdditionalProperties
Packit Service 3a6627
func (a {{.TypeName}}) MarshalJSON() ([]byte, error) {
Packit Service 3a6627
    var err error
Packit Service 3a6627
    object := make(map[string]json.RawMessage)
Packit Service 3a6627
{{range .Schema.Properties}}
Packit Service 3a6627
{{if not .Required}}if a.{{.GoFieldName}} != nil { {{end}}
Packit Service 3a6627
    object["{{.JsonFieldName}}"], err = json.Marshal(a.{{.GoFieldName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, errors.Wrap(err, fmt.Sprintf("error marshaling '{{.JsonFieldName}}'"))
Packit Service 3a6627
    }
Packit Service 3a6627
{{if not .Required}} }{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
    for fieldName, field := range a.AdditionalProperties {
Packit Service 3a6627
		object[fieldName], err = json.Marshal(field)
Packit Service 3a6627
		if err != nil {
Packit Service 3a6627
			return nil, errors.Wrap(err, fmt.Sprintf("error marshaling '%s'", fieldName))
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
	return json.Marshal(object)
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"chi-handler.tmpl": `// Handler creates http.Handler with routing matching OpenAPI spec.
Packit Service 3a6627
func Handler(si ServerInterface) http.Handler {
Packit Service 3a6627
  return HandlerFromMux(si, chi.NewRouter())
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
Packit Service 3a6627
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
Packit Service 3a6627
{{if .}}wrapper := ServerInterfaceWrapper{
Packit Service 3a6627
        Handler: si,
Packit Service 3a6627
    }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{range .}}r.Group(func(r chi.Router) {
Packit Service 3a6627
  r.{{.Method | lower | title }}("{{.Path | swaggerUriToChiUri}}", wrapper.{{.OperationId}})
Packit Service 3a6627
})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
  return r
Packit Service 3a6627
}
Packit Service 3a6627
`,
Packit Service 3a6627
	"chi-interface.tmpl": `// ServerInterface represents all server handlers.
Packit Service 3a6627
type ServerInterface interface {
Packit Service 3a6627
{{range .}}{{.SummaryAsComment }}
Packit Service 3a6627
// ({{.Method}} {{.Path}})
Packit Service 3a6627
{{.OperationId}}(w http.ResponseWriter, r *http.Request{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params {{.OperationId}}Params{{end}})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
}
Packit Service 3a6627
`,
Packit Service 3a6627
	"chi-middleware.tmpl": `// ServerInterfaceWrapper converts contexts to parameters.
Packit Service 3a6627
type ServerInterfaceWrapper struct {
Packit Service 3a6627
    Handler ServerInterface
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{range .}}{{$opid := .OperationId}}
Packit Service 3a6627
Packit Service 3a6627
// {{$opid}} operation middleware
Packit Service 3a6627
func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Request) {
Packit Service 3a6627
  ctx := r.Context()
Packit Service 3a6627
  {{if or .RequiresParamObject (gt (len .PathParams) 0) }}
Packit Service 3a6627
  var err error
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
Packit Service 3a6627
  {{range .PathParams}}// ------------- Path parameter "{{.ParamName}}" -------------
Packit Service 3a6627
  var {{$varName := .GoVariableName}}{{$varName}} {{.TypeDef}}
Packit Service 3a6627
Packit Service 3a6627
  {{if .IsPassThrough}}
Packit Service 3a6627
  {{$varName}} = chi.URLParam(r, "{{.ParamName}}")
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
  {{if .IsJson}}
Packit Service 3a6627
  err = json.Unmarshal([]byte(chi.URLParam(r, "{{.ParamName}}")), &{{$varName}})
Packit Service 3a6627
  if err != nil {
Packit Service 3a6627
    http.Error(w, "Error unmarshaling parameter '{{.ParamName}}' as JSON", http.StatusBadRequest)
Packit Service 3a6627
    return
Packit Service 3a6627
  }
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
  {{if .IsStyled}}
Packit Service 3a6627
  err = runtime.BindStyledParameter("{{.Style}}",{{.Explode}}, "{{.ParamName}}", chi.URLParam(r, "{{.ParamName}}"), &{{$varName}})
Packit Service 3a6627
  if err != nil {
Packit Service 3a6627
    http.Error(w, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err), http.StatusBadRequest)
Packit Service 3a6627
    return
Packit Service 3a6627
  }
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
Packit Service 3a6627
{{range .SecurityDefinitions}}
Packit Service 3a6627
  ctx = context.WithValue(ctx, "{{.ProviderName}}.Scopes", {{toStringArray .Scopes}})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
  {{if .RequiresParamObject}}
Packit Service 3a6627
    // Parameter object where we will unmarshal all parameters from the context
Packit Service 3a6627
    var params {{.OperationId}}Params
Packit Service 3a6627
Packit Service 3a6627
    {{range $paramIdx, $param := .QueryParams}}// ------------- {{if .Required}}Required{{else}}Optional{{end}} query parameter "{{.ParamName}}" -------------
Packit Service 3a6627
      if paramValue := r.URL.Query().Get("{{.ParamName}}"); paramValue != "" {
Packit Service 3a6627
Packit Service 3a6627
      {{if .IsPassThrough}}
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}paramValue
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
Packit Service 3a6627
      {{if .IsJson}}
Packit Service 3a6627
        var value {{.TypeDef}}
Packit Service 3a6627
        err = json.Unmarshal([]byte(paramValue), &value)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
          http.Error(w, "Error unmarshaling parameter '{{.ParamName}}' as JSON", http.StatusBadRequest)
Packit Service 3a6627
          return
Packit Service 3a6627
        }
Packit Service 3a6627
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
      }{{if .Required}} else {
Packit Service 3a6627
          http.Error(w, "Query argument {{.ParamName}} is required, but not found", http.StatusBadRequest)
Packit Service 3a6627
          return
Packit Service 3a6627
      }{{end}}
Packit Service 3a6627
      {{if .IsStyled}}
Packit Service 3a6627
      err = runtime.BindQueryParameter("{{.Style}}", {{.Explode}}, {{.Required}}, "{{.ParamName}}", r.URL.Query(), &params.{{.GoName}})
Packit Service 3a6627
      if err != nil {
Packit Service 3a6627
        http.Error(w, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err), http.StatusBadRequest)
Packit Service 3a6627
        return
Packit Service 3a6627
      }
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
Packit Service 3a6627
    {{if .HeaderParams}}
Packit Service 3a6627
      headers := r.Header
Packit Service 3a6627
Packit Service 3a6627
      {{range .HeaderParams}}// ------------- {{if .Required}}Required{{else}}Optional{{end}} header parameter "{{.ParamName}}" -------------
Packit Service 3a6627
        if valueList, found := headers[http.CanonicalHeaderKey("{{.ParamName}}")]; found {
Packit Service 3a6627
          var {{.GoName}} {{.TypeDef}}
Packit Service 3a6627
          n := len(valueList)
Packit Service 3a6627
          if n != 1 {
Packit Service 3a6627
            http.Error(w, fmt.Sprintf("Expected one value for {{.ParamName}}, got %d", n), http.StatusBadRequest)
Packit Service 3a6627
            return
Packit Service 3a6627
          }
Packit Service 3a6627
Packit Service 3a6627
        {{if .IsPassThrough}}
Packit Service 3a6627
          params.{{.GoName}} = {{if not .Required}}&{{end}}valueList[0]
Packit Service 3a6627
        {{end}}
Packit Service 3a6627
Packit Service 3a6627
        {{if .IsJson}}
Packit Service 3a6627
          err = json.Unmarshal([]byte(valueList[0]), &{{.GoName}})
Packit Service 3a6627
          if err != nil {
Packit Service 3a6627
            http.Error(w, "Error unmarshaling parameter '{{.ParamName}}' as JSON", http.StatusBadRequest)
Packit Service 3a6627
            return
Packit Service 3a6627
          }
Packit Service 3a6627
        {{end}}
Packit Service 3a6627
Packit Service 3a6627
        {{if .IsStyled}}
Packit Service 3a6627
          err = runtime.BindStyledParameter("{{.Style}}",{{.Explode}}, "{{.ParamName}}", valueList[0], &{{.GoName}})
Packit Service 3a6627
          if err != nil {
Packit Service 3a6627
            http.Error(w, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err), http.StatusBadRequest)
Packit Service 3a6627
            return
Packit Service 3a6627
          }
Packit Service 3a6627
        {{end}}
Packit Service 3a6627
Packit Service 3a6627
          params.{{.GoName}} = {{if not .Required}}&{{end}}{{.GoName}}
Packit Service 3a6627
Packit Service 3a6627
        } {{if .Required}}else {
Packit Service 3a6627
            http.Error(w, fmt.Sprintf("Header parameter {{.ParamName}} is required, but not found: %s", err), http.StatusBadRequest)
Packit Service 3a6627
            return
Packit Service 3a6627
        }{{end}}
Packit Service 3a6627
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
Packit Service 3a6627
    {{range .CookieParams}}
Packit Service 3a6627
      if cookie, err := r.Cookie("{{.ParamName}}"); err == nil {
Packit Service 3a6627
Packit Service 3a6627
      {{- if .IsPassThrough}}
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}cookie.Value
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
Packit Service 3a6627
      {{- if .IsJson}}
Packit Service 3a6627
        var value {{.TypeDef}}
Packit Service 3a6627
        var decoded string
Packit Service 3a6627
        decoded, err := url.QueryUnescape(cookie.Value)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
          http.Error(w, "Error unescaping cookie parameter '{{.ParamName}}'", http.StatusBadRequest)
Packit Service 3a6627
          return
Packit Service 3a6627
        }
Packit Service 3a6627
Packit Service 3a6627
        err = json.Unmarshal([]byte(decoded), &value)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
          http.Error(w, "Error unmarshaling parameter '{{.ParamName}}' as JSON", http.StatusBadRequest)
Packit Service 3a6627
          return
Packit Service 3a6627
        }
Packit Service 3a6627
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
Packit Service 3a6627
      {{- if .IsStyled}}
Packit Service 3a6627
        var value {{.TypeDef}}
Packit Service 3a6627
        err = runtime.BindStyledParameter("simple",{{.Explode}}, "{{.ParamName}}", cookie.Value, &value)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
          http.Error(w, "Invalid format for parameter {{.ParamName}}: %s", http.StatusBadRequest)
Packit Service 3a6627
          return
Packit Service 3a6627
        }
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
      {{end}}
Packit Service 3a6627
Packit Service 3a6627
      }
Packit Service 3a6627
Packit Service 3a6627
      {{- if .Required}} else {
Packit Service 3a6627
        http.Error(w, "Query argument {{.ParamName}} is required, but not found", http.StatusBadRequest)
Packit Service 3a6627
        return
Packit Service 3a6627
      }
Packit Service 3a6627
      {{- end}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
  {{end}}
Packit Service 3a6627
  siw.Handler.{{.OperationId}}(w, r.WithContext(ctx){{genParamNames .PathParams}}{{if .RequiresParamObject}}, params{{end}})
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
Packit Service 3a6627
Packit Service 3a6627
`,
Packit Service 3a6627
	"client-with-responses.tmpl": `// ClientWithResponses builds on ClientInterface to offer response payloads
Packit Service 3a6627
type ClientWithResponses struct {
Packit Service 3a6627
    ClientInterface
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// NewClientWithResponses creates a new ClientWithResponses, which wraps
Packit Service 3a6627
// Client with return type handling
Packit Service 3a6627
func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) {
Packit Service 3a6627
    client, err := NewClient(server, opts...)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    return &ClientWithResponses{client}, nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// WithBaseURL overrides the baseURL.
Packit Service 3a6627
func WithBaseURL(baseURL string) ClientOption {
Packit Service 3a6627
	return func(c *Client) error {
Packit Service 3a6627
		newBaseURL, err := url.Parse(baseURL)
Packit Service 3a6627
		if err != nil {
Packit Service 3a6627
			return err
Packit Service 3a6627
		}
Packit Service 3a6627
		c.Server = newBaseURL.String()
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// ClientWithResponsesInterface is the interface specification for the client with responses above.
Packit Service 3a6627
type ClientWithResponsesInterface interface {
Packit Service 3a6627
{{range . -}}
Packit Service 3a6627
{{$hasParams := .RequiresParamObject -}}
Packit Service 3a6627
{{$pathParams := .PathParams -}}
Packit Service 3a6627
{{$opid := .OperationId -}}
Packit Service 3a6627
    // {{$opid}} request {{if .HasBody}} with any body{{end}}
Packit Service 3a6627
    {{$opid}}{{if .HasBody}}WithBody{{end}}WithResponse(ctx context.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params *{{$opid}}Params{{end}}{{if .HasBody}}, contentType string, body io.Reader{{end}}) (*{{genResponseTypeName $opid}}, error)
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
    {{$opid}}{{.Suffix}}WithResponse(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}, body {{$opid}}{{.NameTag}}RequestBody) (*{{genResponseTypeName $opid}}, error)
Packit Service 3a6627
{{end}}{{/* range .Bodies */}}
Packit Service 3a6627
{{end}}{{/* range . $opid := .OperationId */}}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{range .}}{{$opid := .OperationId}}{{$op := .}}
Packit Service 3a6627
type {{$opid | ucFirst}}Response struct {
Packit Service 3a6627
    Body         []byte
Packit Service 3a6627
	HTTPResponse *http.Response
Packit Service 3a6627
    {{- range getResponseTypeDefinitions .}}
Packit Service 3a6627
    {{.TypeName}} *{{.Schema.TypeDecl}}
Packit Service 3a6627
    {{- end}}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Status returns HTTPResponse.Status
Packit Service 3a6627
func (r {{$opid | ucFirst}}Response) Status() string {
Packit Service 3a6627
    if r.HTTPResponse != nil {
Packit Service 3a6627
        return r.HTTPResponse.Status
Packit Service 3a6627
    }
Packit Service 3a6627
    return http.StatusText(0)
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// StatusCode returns HTTPResponse.StatusCode
Packit Service 3a6627
func (r {{$opid | ucFirst}}Response) StatusCode() int {
Packit Service 3a6627
    if r.HTTPResponse != nil {
Packit Service 3a6627
        return r.HTTPResponse.StatusCode
Packit Service 3a6627
    }
Packit Service 3a6627
    return 0
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
Packit Service 3a6627
{{range .}}
Packit Service 3a6627
{{$opid := .OperationId -}}
Packit Service 3a6627
{{/* Generate client methods (with responses)*/}}
Packit Service 3a6627
Packit Service 3a6627
// {{$opid}}{{if .HasBody}}WithBody{{end}}WithResponse request{{if .HasBody}} with arbitrary body{{end}} returning *{{$opid}}Response
Packit Service 3a6627
func (c *ClientWithResponses) {{$opid}}{{if .HasBody}}WithBody{{end}}WithResponse(ctx context.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params *{{$opid}}Params{{end}}{{if .HasBody}}, contentType string, body io.Reader{{end}}) (*{{genResponseTypeName $opid}}, error){
Packit Service 3a6627
    rsp, err := c.{{$opid}}{{if .HasBody}}WithBody{{end}}(ctx{{genParamNames .PathParams}}{{if .RequiresParamObject}}, params{{end}}{{if .HasBody}}, contentType, body{{end}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    return Parse{{genResponseTypeName $opid | ucFirst}}(rsp)
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{$hasParams := .RequiresParamObject -}}
Packit Service 3a6627
{{$pathParams := .PathParams -}}
Packit Service 3a6627
{{$bodyRequired := .BodyRequired -}}
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
func (c *ClientWithResponses) {{$opid}}{{.Suffix}}WithResponse(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}, body {{$opid}}{{.NameTag}}RequestBody) (*{{genResponseTypeName $opid}}, error) {
Packit Service 3a6627
    rsp, err := c.{{$opid}}{{.Suffix}}(ctx{{genParamNames $pathParams}}{{if $hasParams}}, params{{end}}, body)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    return Parse{{genResponseTypeName $opid | ucFirst}}(rsp)
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{end}}{{/* operations */}}
Packit Service 3a6627
Packit Service 3a6627
{{/* Generate parse functions for responses*/}}
Packit Service 3a6627
{{range .}}{{$opid := .OperationId}}
Packit Service 3a6627
Packit Service 3a6627
// Parse{{genResponseTypeName $opid | ucFirst}} parses an HTTP response from a {{$opid}}WithResponse call
Packit Service 3a6627
func Parse{{genResponseTypeName $opid | ucFirst}}(rsp *http.Response) (*{{genResponseTypeName $opid}}, error) {
Packit Service 3a6627
    bodyBytes, err := ioutil.ReadAll(rsp.Body)
Packit Service 3a6627
    defer rsp.Body.Close()
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
    response := {{genResponsePayload $opid}}
Packit Service 3a6627
Packit Service 3a6627
    {{genResponseUnmarshal .}}
Packit Service 3a6627
Packit Service 3a6627
    return response, nil
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}{{/* range . $opid := .OperationId */}}
Packit Service 3a6627
Packit Service 3a6627
`,
Packit Service 3a6627
	"client.tmpl": `// RequestEditorFn  is the function signature for the RequestEditor callback function
Packit Service 3a6627
type RequestEditorFn func(ctx context.Context, req *http.Request) error
Packit Service 3a6627
Packit Service 3a6627
// Doer performs HTTP requests.
Packit Service 3a6627
//
Packit Service 3a6627
// The standard http.Client implements this interface.
Packit Service 3a6627
type HttpRequestDoer interface {
Packit Service 3a6627
	Do(req *http.Request) (*http.Response, error)
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Client which conforms to the OpenAPI3 specification for this service.
Packit Service 3a6627
type Client struct {
Packit Service 3a6627
	// The endpoint of the server conforming to this interface, with scheme,
Packit Service 3a6627
	// https://api.deepmap.com for example.
Packit Service 3a6627
	Server string
Packit Service 3a6627
Packit Service 3a6627
	// Doer for performing requests, typically a *http.Client with any
Packit Service 3a6627
	// customized settings, such as certificate chains.
Packit Service 3a6627
	Client HttpRequestDoer
Packit Service 3a6627
Packit Service 3a6627
	// A callback for modifying requests which are generated before sending over
Packit Service 3a6627
	// the network.
Packit Service 3a6627
	RequestEditor RequestEditorFn
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// ClientOption allows setting custom parameters during construction
Packit Service 3a6627
type ClientOption func(*Client) error
Packit Service 3a6627
Packit Service 3a6627
// Creates a new Client, with reasonable defaults
Packit Service 3a6627
func NewClient(server string, opts ...ClientOption) (*Client, error) {
Packit Service 3a6627
    // create a client with sane default values
Packit Service 3a6627
    client := Client{
Packit Service 3a6627
        Server: server,
Packit Service 3a6627
    }
Packit Service 3a6627
    // mutate client and add all optional params
Packit Service 3a6627
    for _, o := range opts {
Packit Service 3a6627
        if err := o(&client); err != nil {
Packit Service 3a6627
            return nil, err
Packit Service 3a6627
        }
Packit Service 3a6627
    }
Packit Service 3a6627
    // ensure the server URL always has a trailing slash
Packit Service 3a6627
    if !strings.HasSuffix(client.Server, "/") {
Packit Service 3a6627
        client.Server += "/"
Packit Service 3a6627
    }
Packit Service 3a6627
    // create httpClient, if not already present
Packit Service 3a6627
    if client.Client == nil {
Packit Service 3a6627
        client.Client = http.DefaultClient
Packit Service 3a6627
    }
Packit Service 3a6627
    return &client, nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// WithHTTPClient allows overriding the default Doer, which is
Packit Service 3a6627
// automatically created using http.Client. This is useful for tests.
Packit Service 3a6627
func WithHTTPClient(doer HttpRequestDoer) ClientOption {
Packit Service 3a6627
	return func(c *Client) error {
Packit Service 3a6627
		c.Client = doer
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// WithRequestEditorFn allows setting up a callback function, which will be
Packit Service 3a6627
// called right before sending the request. This can be used to mutate the request.
Packit Service 3a6627
func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
Packit Service 3a6627
	return func(c *Client) error {
Packit Service 3a6627
		c.RequestEditor = fn
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// The interface specification for the client above.
Packit Service 3a6627
type ClientInterface interface {
Packit Service 3a6627
{{range . -}}
Packit Service 3a6627
{{$hasParams := .RequiresParamObject -}}
Packit Service 3a6627
{{$pathParams := .PathParams -}}
Packit Service 3a6627
{{$opid := .OperationId -}}
Packit Service 3a6627
    // {{$opid}} request {{if .HasBody}} with any body{{end}}
Packit Service 3a6627
    {{$opid}}{{if .HasBody}}WithBody{{end}}(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}{{if .HasBody}}, contentType string, body io.Reader{{end}}) (*http.Response, error)
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
    {{$opid}}{{.Suffix}}(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}, body {{$opid}}{{.NameTag}}RequestBody) (*http.Response, error)
Packit Service 3a6627
{{end}}{{/* range .Bodies */}}
Packit Service 3a6627
{{end}}{{/* range . $opid := .OperationId */}}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
Packit Service 3a6627
{{/* Generate client methods */}}
Packit Service 3a6627
{{range . -}}
Packit Service 3a6627
{{$hasParams := .RequiresParamObject -}}
Packit Service 3a6627
{{$pathParams := .PathParams -}}
Packit Service 3a6627
{{$opid := .OperationId -}}
Packit Service 3a6627
Packit Service 3a6627
func (c *Client) {{$opid}}{{if .HasBody}}WithBody{{end}}(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}{{if .HasBody}}, contentType string, body io.Reader{{end}}) (*http.Response, error) {
Packit Service 3a6627
    req, err := New{{$opid}}Request{{if .HasBody}}WithBody{{end}}(c.Server{{genParamNames .PathParams}}{{if $hasParams}}, params{{end}}{{if .HasBody}}, contentType, body{{end}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    req = req.WithContext(ctx)
Packit Service 3a6627
    if c.RequestEditor != nil {
Packit Service 3a6627
        err = c.RequestEditor(ctx, req)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
            return nil, err
Packit Service 3a6627
        }
Packit Service 3a6627
    }
Packit Service 3a6627
    return c.Client.Do(req)
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
func (c *Client) {{$opid}}{{.Suffix}}(ctx context.Context{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}, body {{$opid}}{{.NameTag}}RequestBody) (*http.Response, error) {
Packit Service 3a6627
    req, err := New{{$opid}}{{.Suffix}}Request(c.Server{{genParamNames $pathParams}}{{if $hasParams}}, params{{end}}, body)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    req = req.WithContext(ctx)
Packit Service 3a6627
    if c.RequestEditor != nil {
Packit Service 3a6627
        err = c.RequestEditor(ctx, req)
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
            return nil, err
Packit Service 3a6627
        }
Packit Service 3a6627
    }
Packit Service 3a6627
    return c.Client.Do(req)
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}{{/* range .Bodies */}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{/* Generate request builders */}}
Packit Service 3a6627
{{range .}}
Packit Service 3a6627
{{$hasParams := .RequiresParamObject -}}
Packit Service 3a6627
{{$pathParams := .PathParams -}}
Packit Service 3a6627
{{$bodyRequired := .BodyRequired -}}
Packit Service 3a6627
{{$opid := .OperationId -}}
Packit Service 3a6627
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
// New{{$opid}}Request{{.Suffix}} calls the generic {{$opid}} builder with {{.ContentType}} body
Packit Service 3a6627
func New{{$opid}}Request{{.Suffix}}(server string{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}, body {{$opid}}{{.NameTag}}RequestBody) (*http.Request, error) {
Packit Service 3a6627
    var bodyReader io.Reader
Packit Service 3a6627
    buf, err := json.Marshal(body)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    bodyReader = bytes.NewReader(buf)
Packit Service 3a6627
    return New{{$opid}}RequestWithBody(server{{genParamNames $pathParams}}{{if $hasParams}}, params{{end}}, "{{.ContentType}}", bodyReader)
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
// New{{$opid}}Request{{if .HasBody}}WithBody{{end}} generates requests for {{$opid}}{{if .HasBody}} with any type of body{{end}}
Packit Service 3a6627
func New{{$opid}}Request{{if .HasBody}}WithBody{{end}}(server string{{genParamArgs $pathParams}}{{if $hasParams}}, params *{{$opid}}Params{{end}}{{if .HasBody}}, contentType string, body io.Reader{{end}}) (*http.Request, error) {
Packit Service 3a6627
    var err error
Packit Service 3a6627
{{range $paramIdx, $param := .PathParams}}
Packit Service 3a6627
    var pathParam{{$paramIdx}} string
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    pathParam{{$paramIdx}} = {{.ParamName}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    var pathParamBuf{{$paramIdx}} []byte
Packit Service 3a6627
    pathParamBuf{{$paramIdx}}, err = json.Marshal({{.ParamName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    pathParam{{$paramIdx}} = string(pathParamBuf{{$paramIdx}})
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    pathParam{{$paramIdx}}, err = runtime.StyleParam("{{.Style}}", {{.Explode}}, "{{.ParamName}}", {{.GoVariableName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
    queryUrl, err := url.Parse(server)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
    basePath := fmt.Sprintf("{{genParamFmtString .Path}}"{{range $paramIdx, $param := .PathParams}}, pathParam{{$paramIdx}}{{end}})
Packit Service 3a6627
    if basePath[0] == '/' {
Packit Service 3a6627
        basePath = basePath[1:]
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
    queryUrl, err = queryUrl.Parse(basePath)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
{{if .QueryParams}}
Packit Service 3a6627
    queryValues := queryUrl.Query()
Packit Service 3a6627
{{range $paramIdx, $param := .QueryParams}}
Packit Service 3a6627
    {{if not .Required}} if params.{{.GoName}} != nil { {{end}}
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    queryValues.Add("{{.ParamName}}", {{if not .Required}}*{{end}}params.{{.GoName}})
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    if queryParamBuf, err := json.Marshal({{if not .Required}}*{{end}}params.{{.GoName}}); err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    } else {
Packit Service 3a6627
        queryValues.Add("{{.ParamName}}", string(queryParamBuf))
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    if queryFrag, err := runtime.StyleParam("{{.Style}}", {{.Explode}}, "{{.ParamName}}", {{if not .Required}}*{{end}}params.{{.GoName}}); err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    } else if parsed, err := url.ParseQuery(queryFrag); err != nil {
Packit Service 3a6627
       return nil, err
Packit Service 3a6627
    } else {
Packit Service 3a6627
       for k, v := range parsed {
Packit Service 3a6627
           for _, v2 := range v {
Packit Service 3a6627
               queryValues.Add(k, v2)
Packit Service 3a6627
           }
Packit Service 3a6627
       }
Packit Service 3a6627
    }
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if not .Required}}}{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
    queryUrl.RawQuery = queryValues.Encode()
Packit Service 3a6627
{{end}}{{/* if .QueryParams */}}
Packit Service 3a6627
    req, err := http.NewRequest("{{.Method}}", queryUrl.String(), {{if .HasBody}}body{{else}}nil{{end}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
{{range $paramIdx, $param := .HeaderParams}}
Packit Service 3a6627
    {{if not .Required}} if params.{{.GoName}} != nil { {{end}}
Packit Service 3a6627
    var headerParam{{$paramIdx}} string
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    headerParam{{$paramIdx}} = {{if not .Required}}*{{end}}params.{{.GoName}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    var headerParamBuf{{$paramIdx}} []byte
Packit Service 3a6627
    headerParamBuf{{$paramIdx}}, err = json.Marshal({{if not .Required}}*{{end}}params.{{.GoName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    headerParam{{$paramIdx}} = string(headerParamBuf{{$paramIdx}})
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    headerParam{{$paramIdx}}, err = runtime.StyleParam("{{.Style}}", {{.Explode}}, "{{.ParamName}}", {{if not .Required}}*{{end}}params.{{.GoName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    req.Header.Add("{{.ParamName}}", headerParam{{$paramIdx}})
Packit Service 3a6627
    {{if not .Required}}}{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{range $paramIdx, $param := .CookieParams}}
Packit Service 3a6627
    {{if not .Required}} if params.{{.GoName}} != nil { {{end}}
Packit Service 3a6627
    var cookieParam{{$paramIdx}} string
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    cookieParam{{$paramIdx}} = {{if not .Required}}*{{end}}params.{{.GoName}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    var cookieParamBuf{{$paramIdx}} []byte
Packit Service 3a6627
    cookieParamBuf{{$paramIdx}}, err = json.Marshal({{if not .Required}}*{{end}}params.{{.GoName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    cookieParam{{$paramIdx}} = url.QueryEscape(string(cookieParamBuf{{$paramIdx}}))
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    cookieParam{{$paramIdx}}, err = runtime.StyleParam("simple", {{.Explode}}, "{{.ParamName}}", {{if not .Required}}*{{end}}params.{{.GoName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, err
Packit Service 3a6627
    }
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    cookie{{$paramIdx}} := &http.Cookie{
Packit Service 3a6627
        Name:"{{.ParamName}}",
Packit Service 3a6627
        Value:cookieParam{{$paramIdx}},
Packit Service 3a6627
    }
Packit Service 3a6627
    req.AddCookie(cookie{{$paramIdx}})
Packit Service 3a6627
    {{if not .Required}}}{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
    {{if .HasBody}}req.Header.Add("Content-Type", contentType){{end}}
Packit Service 3a6627
    return req, nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{end}}{{/* Range */}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"imports.tmpl": `// Package {{.PackageName}} provides primitives to interact the openapi HTTP API.
Packit Service 3a6627
//
Packit Service 3a6627
// Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT.
Packit Service 3a6627
package {{.PackageName}}
Packit Service 3a6627
Packit Service 3a6627
{{if .Imports}}
Packit Service 3a6627
import (
Packit Service 3a6627
{{range .Imports}} {{ . }}
Packit Service 3a6627
{{end}})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"inline.tmpl": `// Base64 encoded, gzipped, json marshaled Swagger object
Packit Service 3a6627
var swaggerSpec = []string{
Packit Service 3a6627
{{range .}}
Packit Service 3a6627
    "{{.}}",{{end}}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// GetSwagger returns the Swagger specification corresponding to the generated code
Packit Service 3a6627
// in this file.
Packit Service 3a6627
func GetSwagger() (*openapi3.Swagger, error) {
Packit Service 3a6627
    zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, fmt.Errorf("error base64 decoding spec: %s", err)
Packit Service 3a6627
    }
Packit Service 3a6627
    zr, err := gzip.NewReader(bytes.NewReader(zipped))
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, fmt.Errorf("error decompressing spec: %s", err)
Packit Service 3a6627
    }
Packit Service 3a6627
    var buf bytes.Buffer
Packit Service 3a6627
    _, err = buf.ReadFrom(zr)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, fmt.Errorf("error decompressing spec: %s", err)
Packit Service 3a6627
    }
Packit Service 3a6627
Packit Service 3a6627
    swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(buf.Bytes())
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return nil, fmt.Errorf("error loading Swagger: %s", err)
Packit Service 3a6627
    }
Packit Service 3a6627
    return swagger, nil
Packit Service 3a6627
}
Packit Service 3a6627
`,
Packit Service 3a6627
	"param-types.tmpl": `{{range .}}{{$opid := .OperationId}}
Packit Service 3a6627
{{range .TypeDefinitions}}
Packit Service 3a6627
// {{.TypeName}} defines parameters for {{$opid}}.
Packit Service 3a6627
type {{.TypeName}} {{.Schema.TypeDecl}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"register.tmpl": `
Packit Service 3a6627
Packit Service 3a6627
// This is a simple interface which specifies echo.Route addition functions which
Packit Service 3a6627
// are present on both echo.Echo and echo.Group, since we want to allow using
Packit Service 3a6627
// either of them for path registration
Packit Service 3a6627
type EchoRouter interface {
Packit Service 3a6627
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// RegisterHandlers adds each server route to the EchoRouter.
Packit Service 3a6627
func RegisterHandlers(router EchoRouter, si ServerInterface) {
Packit Service 3a6627
{{if .}}
Packit Service 3a6627
    wrapper := ServerInterfaceWrapper{
Packit Service 3a6627
        Handler: si,
Packit Service 3a6627
    }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{range .}}router.{{.Method}}("{{.Path | swaggerUriToEchoUri}}", wrapper.{{.OperationId}})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
}
Packit Service 3a6627
`,
Packit Service 3a6627
	"request-bodies.tmpl": `{{range .}}{{$opid := .OperationId}}
Packit Service 3a6627
{{range .Bodies}}
Packit Service 3a6627
// {{$opid}}RequestBody defines body for {{$opid}} for application/json ContentType.
Packit Service 3a6627
type {{$opid}}{{.NameTag}}RequestBody {{.TypeDef}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"server-interface.tmpl": `// ServerInterface represents all server handlers.
Packit Service 3a6627
type ServerInterface interface {
Packit Service 3a6627
{{range .}}{{.SummaryAsComment }}
Packit Service 3a6627
// ({{.Method}} {{.Path}})
Packit Service 3a6627
{{.OperationId}}(ctx echo.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params {{.OperationId}}Params{{end}}) error
Packit Service 3a6627
{{end}}
Packit Service 3a6627
}
Packit Service 3a6627
`,
Packit Service 3a6627
	"typedef.tmpl": `{{range .Types}}
Packit Service 3a6627
// {{.TypeName}} defines model for {{.JsonName}}.
Packit Service 3a6627
type {{.TypeName}} {{.Schema.TypeDecl}}
Packit Service 3a6627
{{- if gt (len .Schema.EnumValues) 0 }}
Packit Service 3a6627
// List of {{ .TypeName }}
Packit Service 3a6627
const (
Packit Service 3a6627
	{{- $typeName := .TypeName }}
Packit Service 3a6627
    {{- range $key, $value := .Schema.EnumValues }}
Packit Service 3a6627
    {{ $typeName }}_{{ $key }} {{ $typeName }} = "{{ $value }}"
Packit Service 3a6627
    {{- end }}
Packit Service 3a6627
)
Packit Service 3a6627
{{- end }}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
	"wrappers.tmpl": `// ServerInterfaceWrapper converts echo contexts to parameters.
Packit Service 3a6627
type ServerInterfaceWrapper struct {
Packit Service 3a6627
    Handler ServerInterface
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
{{range .}}{{$opid := .OperationId}}// {{$opid}} converts echo context to params.
Packit Service 3a6627
func (w *ServerInterfaceWrapper) {{.OperationId}} (ctx echo.Context) error {
Packit Service 3a6627
    var err error
Packit Service 3a6627
{{range .PathParams}}// ------------- Path parameter "{{.ParamName}}" -------------
Packit Service 3a6627
    var {{$varName := .GoVariableName}}{{$varName}} {{.TypeDef}}
Packit Service 3a6627
{{if .IsPassThrough}}
Packit Service 3a6627
    {{$varName}} = ctx.Param("{{.ParamName}}")
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{if .IsJson}}
Packit Service 3a6627
    err = json.Unmarshal([]byte(ctx.Param("{{.ParamName}}")), &{{$varName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, "Error unmarshaling parameter '{{.ParamName}}' as JSON")
Packit Service 3a6627
    }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{if .IsStyled}}
Packit Service 3a6627
    err = runtime.BindStyledParameter("{{.Style}}",{{.Explode}}, "{{.ParamName}}", ctx.Param("{{.ParamName}}"), &{{$varName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err))
Packit Service 3a6627
    }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{range .SecurityDefinitions}}
Packit Service 3a6627
    ctx.Set("{{.ProviderName}}.Scopes", {{toStringArray .Scopes}})
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{if .RequiresParamObject}}
Packit Service 3a6627
    // Parameter object where we will unmarshal all parameters from the context
Packit Service 3a6627
    var params {{.OperationId}}Params
Packit Service 3a6627
{{range $paramIdx, $param := .QueryParams}}// ------------- {{if .Required}}Required{{else}}Optional{{end}} query parameter "{{.ParamName}}" -------------
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    err = runtime.BindQueryParameter("{{.Style}}", {{.Explode}}, {{.Required}}, "{{.ParamName}}", ctx.QueryParams(), &params.{{.GoName}})
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err))
Packit Service 3a6627
    }
Packit Service 3a6627
    {{else}}
Packit Service 3a6627
    if paramValue := ctx.QueryParam("{{.ParamName}}"); paramValue != "" {
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    params.{{.GoName}} = {{if not .Required}}&{{end}}paramValue
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    var value {{.TypeDef}}
Packit Service 3a6627
    err = json.Unmarshal([]byte(paramValue), &value)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, "Error unmarshaling parameter '{{.ParamName}}' as JSON")
Packit Service 3a6627
    }
Packit Service 3a6627
    params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    }{{if .Required}} else {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Query argument {{.ParamName}} is required, but not found"))
Packit Service 3a6627
    }{{end}}
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{if .HeaderParams}}
Packit Service 3a6627
    headers := ctx.Request().Header
Packit Service 3a6627
{{range .HeaderParams}}// ------------- {{if .Required}}Required{{else}}Optional{{end}} header parameter "{{.ParamName}}" -------------
Packit Service 3a6627
    if valueList, found := headers[http.CanonicalHeaderKey("{{.ParamName}}")]; found {
Packit Service 3a6627
        var {{.GoName}} {{.TypeDef}}
Packit Service 3a6627
        n := len(valueList)
Packit Service 3a6627
        if n != 1 {
Packit Service 3a6627
            return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for {{.ParamName}}, got %d", n))
Packit Service 3a6627
        }
Packit Service 3a6627
{{if .IsPassThrough}}
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}valueList[0]
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{if .IsJson}}
Packit Service 3a6627
        err = json.Unmarshal([]byte(valueList[0]), &{{.GoName}})
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
            return echo.NewHTTPError(http.StatusBadRequest, "Error unmarshaling parameter '{{.ParamName}}' as JSON")
Packit Service 3a6627
        }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{if .IsStyled}}
Packit Service 3a6627
        err = runtime.BindStyledParameter("{{.Style}}",{{.Explode}}, "{{.ParamName}}", valueList[0], &{{.GoName}})
Packit Service 3a6627
        if err != nil {
Packit Service 3a6627
            return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err))
Packit Service 3a6627
        }
Packit Service 3a6627
{{end}}
Packit Service 3a6627
        params.{{.GoName}} = {{if not .Required}}&{{end}}{{.GoName}}
Packit Service 3a6627
        } {{if .Required}}else {
Packit Service 3a6627
            return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter {{.ParamName}} is required, but not found"))
Packit Service 3a6627
        }{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{range .CookieParams}}
Packit Service 3a6627
    if cookie, err := ctx.Cookie("{{.ParamName}}"); err == nil {
Packit Service 3a6627
    {{if .IsPassThrough}}
Packit Service 3a6627
    params.{{.GoName}} = {{if not .Required}}&{{end}}cookie.Value
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsJson}}
Packit Service 3a6627
    var value {{.TypeDef}}
Packit Service 3a6627
    var decoded string
Packit Service 3a6627
    decoded, err := url.QueryUnescape(cookie.Value)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, "Error unescaping cookie parameter '{{.ParamName}}'")
Packit Service 3a6627
    }
Packit Service 3a6627
    err = json.Unmarshal([]byte(decoded), &value)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, "Error unmarshaling parameter '{{.ParamName}}' as JSON")
Packit Service 3a6627
    }
Packit Service 3a6627
    params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    {{if .IsStyled}}
Packit Service 3a6627
    var value {{.TypeDef}}
Packit Service 3a6627
    err = runtime.BindStyledParameter("simple",{{.Explode}}, "{{.ParamName}}", cookie.Value, &value)
Packit Service 3a6627
    if err != nil {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter {{.ParamName}}: %s", err))
Packit Service 3a6627
    }
Packit Service 3a6627
    params.{{.GoName}} = {{if not .Required}}&{{end}}value
Packit Service 3a6627
    {{end}}
Packit Service 3a6627
    }{{if .Required}} else {
Packit Service 3a6627
        return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Query argument {{.ParamName}} is required, but not found"))
Packit Service 3a6627
    }{{end}}
Packit Service 3a6627
Packit Service 3a6627
{{end}}{{/* .CookieParams */}}
Packit Service 3a6627
Packit Service 3a6627
{{end}}{{/* .RequiresParamObject */}}
Packit Service 3a6627
    // Invoke the callback with all the unmarshalled arguments
Packit Service 3a6627
    err = w.Handler.{{.OperationId}}(ctx{{genParamNames .PathParams}}{{if .RequiresParamObject}}, params{{end}})
Packit Service 3a6627
    return err
Packit Service 3a6627
}
Packit Service 3a6627
{{end}}
Packit Service 3a6627
`,
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
// Parse parses declared templates.
Packit Service 3a6627
func Parse(t *template.Template) (*template.Template, error) {
Packit Service 3a6627
	for name, s := range templates {
Packit Service 3a6627
		var tmpl *template.Template
Packit Service 3a6627
		if t == nil {
Packit Service 3a6627
			t = template.New(name)
Packit Service 3a6627
		}
Packit Service 3a6627
		if name == t.Name() {
Packit Service 3a6627
			tmpl = t
Packit Service 3a6627
		} else {
Packit Service 3a6627
			tmpl = t.New(name)
Packit Service 3a6627
		}
Packit Service 3a6627
		if _, err := tmpl.Parse(s); err != nil {
Packit Service 3a6627
			return nil, err
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
	return t, nil
Packit Service 3a6627
}
Packit Service 3a6627