github.com/circl-dev/go-swagger@v0.31.0/examples/generated/restapi/operations/petstore_api.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package operations
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"fmt"
    10  	"net/http"
    11  	"strings"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/circl-dev/runtime"
    17  	"github.com/circl-dev/runtime/middleware"
    18  	"github.com/circl-dev/runtime/security"
    19  	"github.com/circl-dev/spec"
    20  	"github.com/circl-dev/loads"
    21  
    22  	"github.com/circl-dev/go-swagger/examples/generated/restapi/operations/pet"
    23  	"github.com/circl-dev/go-swagger/examples/generated/restapi/operations/store"
    24  	"github.com/circl-dev/go-swagger/examples/generated/restapi/operations/user"
    25  )
    26  
    27  // NewPetstoreAPI creates a new Petstore instance
    28  func NewPetstoreAPI(spec *loads.Document) *PetstoreAPI {
    29  	return &PetstoreAPI{
    30  		handlers:            make(map[string]map[string]http.Handler),
    31  		formats:             strfmt.Default,
    32  		defaultConsumes:     "application/json",
    33  		defaultProduces:     "application/json",
    34  		customConsumers:     make(map[string]runtime.Consumer),
    35  		customProducers:     make(map[string]runtime.Producer),
    36  		PreServerShutdown:   func() {},
    37  		ServerShutdown:      func() {},
    38  		spec:                spec,
    39  		useSwaggerUI:        false,
    40  		ServeError:          errors.ServeError,
    41  		BasicAuthenticator:  security.BasicAuth,
    42  		APIKeyAuthenticator: security.APIKeyAuth,
    43  		BearerAuthenticator: security.BearerAuth,
    44  
    45  		JSONConsumer:    runtime.JSONConsumer(),
    46  		UrlformConsumer: runtime.DiscardConsumer,
    47  		XMLConsumer:     runtime.XMLConsumer(),
    48  
    49  		JSONProducer: runtime.JSONProducer(),
    50  		XMLProducer:  runtime.XMLProducer(),
    51  
    52  		PetAddPetHandler: pet.AddPetHandlerFunc(func(params pet.AddPetParams, principal interface{}) middleware.Responder {
    53  			return middleware.NotImplemented("operation pet.AddPet has not yet been implemented")
    54  		}),
    55  		UserCreateUserHandler: user.CreateUserHandlerFunc(func(params user.CreateUserParams) middleware.Responder {
    56  			return middleware.NotImplemented("operation user.CreateUser has not yet been implemented")
    57  		}),
    58  		UserCreateUsersWithArrayInputHandler: user.CreateUsersWithArrayInputHandlerFunc(func(params user.CreateUsersWithArrayInputParams) middleware.Responder {
    59  			return middleware.NotImplemented("operation user.CreateUsersWithArrayInput has not yet been implemented")
    60  		}),
    61  		UserCreateUsersWithListInputHandler: user.CreateUsersWithListInputHandlerFunc(func(params user.CreateUsersWithListInputParams) middleware.Responder {
    62  			return middleware.NotImplemented("operation user.CreateUsersWithListInput has not yet been implemented")
    63  		}),
    64  		StoreDeleteOrderHandler: store.DeleteOrderHandlerFunc(func(params store.DeleteOrderParams) middleware.Responder {
    65  			return middleware.NotImplemented("operation store.DeleteOrder has not yet been implemented")
    66  		}),
    67  		PetDeletePetHandler: pet.DeletePetHandlerFunc(func(params pet.DeletePetParams, principal interface{}) middleware.Responder {
    68  			return middleware.NotImplemented("operation pet.DeletePet has not yet been implemented")
    69  		}),
    70  		UserDeleteUserHandler: user.DeleteUserHandlerFunc(func(params user.DeleteUserParams) middleware.Responder {
    71  			return middleware.NotImplemented("operation user.DeleteUser has not yet been implemented")
    72  		}),
    73  		PetFindPetsByStatusHandler: pet.FindPetsByStatusHandlerFunc(func(params pet.FindPetsByStatusParams, principal interface{}) middleware.Responder {
    74  			return middleware.NotImplemented("operation pet.FindPetsByStatus has not yet been implemented")
    75  		}),
    76  		PetFindPetsByTagsHandler: pet.FindPetsByTagsHandlerFunc(func(params pet.FindPetsByTagsParams, principal interface{}) middleware.Responder {
    77  			return middleware.NotImplemented("operation pet.FindPetsByTags has not yet been implemented")
    78  		}),
    79  		StoreGetOrderByIDHandler: store.GetOrderByIDHandlerFunc(func(params store.GetOrderByIDParams) middleware.Responder {
    80  			return middleware.NotImplemented("operation store.GetOrderByID has not yet been implemented")
    81  		}),
    82  		PetGetPetByIDHandler: pet.GetPetByIDHandlerFunc(func(params pet.GetPetByIDParams, principal interface{}) middleware.Responder {
    83  			return middleware.NotImplemented("operation pet.GetPetByID has not yet been implemented")
    84  		}),
    85  		UserGetUserByNameHandler: user.GetUserByNameHandlerFunc(func(params user.GetUserByNameParams) middleware.Responder {
    86  			return middleware.NotImplemented("operation user.GetUserByName has not yet been implemented")
    87  		}),
    88  		UserLoginUserHandler: user.LoginUserHandlerFunc(func(params user.LoginUserParams) middleware.Responder {
    89  			return middleware.NotImplemented("operation user.LoginUser has not yet been implemented")
    90  		}),
    91  		UserLogoutUserHandler: user.LogoutUserHandlerFunc(func(params user.LogoutUserParams) middleware.Responder {
    92  			return middleware.NotImplemented("operation user.LogoutUser has not yet been implemented")
    93  		}),
    94  		StorePlaceOrderHandler: store.PlaceOrderHandlerFunc(func(params store.PlaceOrderParams) middleware.Responder {
    95  			return middleware.NotImplemented("operation store.PlaceOrder has not yet been implemented")
    96  		}),
    97  		PetUpdatePetHandler: pet.UpdatePetHandlerFunc(func(params pet.UpdatePetParams, principal interface{}) middleware.Responder {
    98  			return middleware.NotImplemented("operation pet.UpdatePet has not yet been implemented")
    99  		}),
   100  		PetUpdatePetWithFormHandler: pet.UpdatePetWithFormHandlerFunc(func(params pet.UpdatePetWithFormParams, principal interface{}) middleware.Responder {
   101  			return middleware.NotImplemented("operation pet.UpdatePetWithForm has not yet been implemented")
   102  		}),
   103  		UserUpdateUserHandler: user.UpdateUserHandlerFunc(func(params user.UpdateUserParams) middleware.Responder {
   104  			return middleware.NotImplemented("operation user.UpdateUser has not yet been implemented")
   105  		}),
   106  
   107  		// Applies when the "api_key" header is set
   108  		APIKeyAuth: func(token string) (interface{}, error) {
   109  			return nil, errors.NotImplemented("api key auth (api_key) api_key from header param [api_key] has not yet been implemented")
   110  		},
   111  		PetstoreAuthAuth: func(token string, scopes []string) (interface{}, error) {
   112  			return nil, errors.NotImplemented("oauth2 bearer auth (petstore_auth) has not yet been implemented")
   113  		},
   114  		// default authorizer is authorized meaning no requests are blocked
   115  		APIAuthorizer: security.Authorized(),
   116  	}
   117  }
   118  
   119  /*PetstoreAPI This is a sample server Petstore server.
   120  
   121  [Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel '#swagger' on irc.freenode.net.
   122  
   123  For this sample, you can use the api key 'special-key' to test the authorization filters
   124  */
   125  type PetstoreAPI struct {
   126  	spec            *loads.Document
   127  	context         *middleware.Context
   128  	handlers        map[string]map[string]http.Handler
   129  	formats         strfmt.Registry
   130  	customConsumers map[string]runtime.Consumer
   131  	customProducers map[string]runtime.Producer
   132  	defaultConsumes string
   133  	defaultProduces string
   134  	Middleware      func(middleware.Builder) http.Handler
   135  	useSwaggerUI    bool
   136  
   137  	// BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
   138  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   139  	BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
   140  
   141  	// APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
   142  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   143  	APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
   144  
   145  	// BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
   146  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   147  	BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
   148  
   149  	// JSONConsumer registers a consumer for the following mime types:
   150  	//   - application/json
   151  	JSONConsumer runtime.Consumer
   152  	// UrlformConsumer registers a consumer for the following mime types:
   153  	//   - application/x-www-form-urlencoded
   154  	UrlformConsumer runtime.Consumer
   155  	// XMLConsumer registers a consumer for the following mime types:
   156  	//   - application/xml
   157  	XMLConsumer runtime.Consumer
   158  
   159  	// JSONProducer registers a producer for the following mime types:
   160  	//   - application/json
   161  	JSONProducer runtime.Producer
   162  	// XMLProducer registers a producer for the following mime types:
   163  	//   - application/xml
   164  	XMLProducer runtime.Producer
   165  
   166  	// APIKeyAuth registers a function that takes a token and returns a principal
   167  	// it performs authentication based on an api key api_key provided in the header
   168  	APIKeyAuth func(string) (interface{}, error)
   169  
   170  	// PetstoreAuthAuth registers a function that takes an access token and a collection of required scopes and returns a principal
   171  	// it performs authentication based on an oauth2 bearer token provided in the request
   172  	PetstoreAuthAuth func(string, []string) (interface{}, error)
   173  
   174  	// APIAuthorizer provides access control (ACL/RBAC/ABAC) by providing access to the request and authenticated principal
   175  	APIAuthorizer runtime.Authorizer
   176  
   177  	// PetAddPetHandler sets the operation handler for the add pet operation
   178  	PetAddPetHandler pet.AddPetHandler
   179  	// UserCreateUserHandler sets the operation handler for the create user operation
   180  	UserCreateUserHandler user.CreateUserHandler
   181  	// UserCreateUsersWithArrayInputHandler sets the operation handler for the create users with array input operation
   182  	UserCreateUsersWithArrayInputHandler user.CreateUsersWithArrayInputHandler
   183  	// UserCreateUsersWithListInputHandler sets the operation handler for the create users with list input operation
   184  	UserCreateUsersWithListInputHandler user.CreateUsersWithListInputHandler
   185  	// StoreDeleteOrderHandler sets the operation handler for the delete order operation
   186  	StoreDeleteOrderHandler store.DeleteOrderHandler
   187  	// PetDeletePetHandler sets the operation handler for the delete pet operation
   188  	PetDeletePetHandler pet.DeletePetHandler
   189  	// UserDeleteUserHandler sets the operation handler for the delete user operation
   190  	UserDeleteUserHandler user.DeleteUserHandler
   191  	// PetFindPetsByStatusHandler sets the operation handler for the find pets by status operation
   192  	PetFindPetsByStatusHandler pet.FindPetsByStatusHandler
   193  	// PetFindPetsByTagsHandler sets the operation handler for the find pets by tags operation
   194  	PetFindPetsByTagsHandler pet.FindPetsByTagsHandler
   195  	// StoreGetOrderByIDHandler sets the operation handler for the get order by Id operation
   196  	StoreGetOrderByIDHandler store.GetOrderByIDHandler
   197  	// PetGetPetByIDHandler sets the operation handler for the get pet by Id operation
   198  	PetGetPetByIDHandler pet.GetPetByIDHandler
   199  	// UserGetUserByNameHandler sets the operation handler for the get user by name operation
   200  	UserGetUserByNameHandler user.GetUserByNameHandler
   201  	// UserLoginUserHandler sets the operation handler for the login user operation
   202  	UserLoginUserHandler user.LoginUserHandler
   203  	// UserLogoutUserHandler sets the operation handler for the logout user operation
   204  	UserLogoutUserHandler user.LogoutUserHandler
   205  	// StorePlaceOrderHandler sets the operation handler for the place order operation
   206  	StorePlaceOrderHandler store.PlaceOrderHandler
   207  	// PetUpdatePetHandler sets the operation handler for the update pet operation
   208  	PetUpdatePetHandler pet.UpdatePetHandler
   209  	// PetUpdatePetWithFormHandler sets the operation handler for the update pet with form operation
   210  	PetUpdatePetWithFormHandler pet.UpdatePetWithFormHandler
   211  	// UserUpdateUserHandler sets the operation handler for the update user operation
   212  	UserUpdateUserHandler user.UpdateUserHandler
   213  
   214  	// ServeError is called when an error is received, there is a default handler
   215  	// but you can set your own with this
   216  	ServeError func(http.ResponseWriter, *http.Request, error)
   217  
   218  	// PreServerShutdown is called before the HTTP(S) server is shutdown
   219  	// This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
   220  	PreServerShutdown func()
   221  
   222  	// ServerShutdown is called when the HTTP(S) server is shut down and done
   223  	// handling all active connections and does not accept connections any more
   224  	ServerShutdown func()
   225  
   226  	// Custom command line argument groups with their descriptions
   227  	CommandLineOptionsGroups []swag.CommandLineOptionsGroup
   228  
   229  	// User defined logger function.
   230  	Logger func(string, ...interface{})
   231  }
   232  
   233  // UseRedoc for documentation at /docs
   234  func (o *PetstoreAPI) UseRedoc() {
   235  	o.useSwaggerUI = false
   236  }
   237  
   238  // UseSwaggerUI for documentation at /docs
   239  func (o *PetstoreAPI) UseSwaggerUI() {
   240  	o.useSwaggerUI = true
   241  }
   242  
   243  // SetDefaultProduces sets the default produces media type
   244  func (o *PetstoreAPI) SetDefaultProduces(mediaType string) {
   245  	o.defaultProduces = mediaType
   246  }
   247  
   248  // SetDefaultConsumes returns the default consumes media type
   249  func (o *PetstoreAPI) SetDefaultConsumes(mediaType string) {
   250  	o.defaultConsumes = mediaType
   251  }
   252  
   253  // SetSpec sets a spec that will be served for the clients.
   254  func (o *PetstoreAPI) SetSpec(spec *loads.Document) {
   255  	o.spec = spec
   256  }
   257  
   258  // DefaultProduces returns the default produces media type
   259  func (o *PetstoreAPI) DefaultProduces() string {
   260  	return o.defaultProduces
   261  }
   262  
   263  // DefaultConsumes returns the default consumes media type
   264  func (o *PetstoreAPI) DefaultConsumes() string {
   265  	return o.defaultConsumes
   266  }
   267  
   268  // Formats returns the registered string formats
   269  func (o *PetstoreAPI) Formats() strfmt.Registry {
   270  	return o.formats
   271  }
   272  
   273  // RegisterFormat registers a custom format validator
   274  func (o *PetstoreAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
   275  	o.formats.Add(name, format, validator)
   276  }
   277  
   278  // Validate validates the registrations in the PetstoreAPI
   279  func (o *PetstoreAPI) Validate() error {
   280  	var unregistered []string
   281  
   282  	if o.JSONConsumer == nil {
   283  		unregistered = append(unregistered, "JSONConsumer")
   284  	}
   285  	if o.UrlformConsumer == nil {
   286  		unregistered = append(unregistered, "UrlformConsumer")
   287  	}
   288  	if o.XMLConsumer == nil {
   289  		unregistered = append(unregistered, "XMLConsumer")
   290  	}
   291  
   292  	if o.JSONProducer == nil {
   293  		unregistered = append(unregistered, "JSONProducer")
   294  	}
   295  	if o.XMLProducer == nil {
   296  		unregistered = append(unregistered, "XMLProducer")
   297  	}
   298  
   299  	if o.APIKeyAuth == nil {
   300  		unregistered = append(unregistered, "APIKeyAuth")
   301  	}
   302  	if o.PetstoreAuthAuth == nil {
   303  		unregistered = append(unregistered, "PetstoreAuthAuth")
   304  	}
   305  
   306  	if o.PetAddPetHandler == nil {
   307  		unregistered = append(unregistered, "pet.AddPetHandler")
   308  	}
   309  	if o.UserCreateUserHandler == nil {
   310  		unregistered = append(unregistered, "user.CreateUserHandler")
   311  	}
   312  	if o.UserCreateUsersWithArrayInputHandler == nil {
   313  		unregistered = append(unregistered, "user.CreateUsersWithArrayInputHandler")
   314  	}
   315  	if o.UserCreateUsersWithListInputHandler == nil {
   316  		unregistered = append(unregistered, "user.CreateUsersWithListInputHandler")
   317  	}
   318  	if o.StoreDeleteOrderHandler == nil {
   319  		unregistered = append(unregistered, "store.DeleteOrderHandler")
   320  	}
   321  	if o.PetDeletePetHandler == nil {
   322  		unregistered = append(unregistered, "pet.DeletePetHandler")
   323  	}
   324  	if o.UserDeleteUserHandler == nil {
   325  		unregistered = append(unregistered, "user.DeleteUserHandler")
   326  	}
   327  	if o.PetFindPetsByStatusHandler == nil {
   328  		unregistered = append(unregistered, "pet.FindPetsByStatusHandler")
   329  	}
   330  	if o.PetFindPetsByTagsHandler == nil {
   331  		unregistered = append(unregistered, "pet.FindPetsByTagsHandler")
   332  	}
   333  	if o.StoreGetOrderByIDHandler == nil {
   334  		unregistered = append(unregistered, "store.GetOrderByIDHandler")
   335  	}
   336  	if o.PetGetPetByIDHandler == nil {
   337  		unregistered = append(unregistered, "pet.GetPetByIDHandler")
   338  	}
   339  	if o.UserGetUserByNameHandler == nil {
   340  		unregistered = append(unregistered, "user.GetUserByNameHandler")
   341  	}
   342  	if o.UserLoginUserHandler == nil {
   343  		unregistered = append(unregistered, "user.LoginUserHandler")
   344  	}
   345  	if o.UserLogoutUserHandler == nil {
   346  		unregistered = append(unregistered, "user.LogoutUserHandler")
   347  	}
   348  	if o.StorePlaceOrderHandler == nil {
   349  		unregistered = append(unregistered, "store.PlaceOrderHandler")
   350  	}
   351  	if o.PetUpdatePetHandler == nil {
   352  		unregistered = append(unregistered, "pet.UpdatePetHandler")
   353  	}
   354  	if o.PetUpdatePetWithFormHandler == nil {
   355  		unregistered = append(unregistered, "pet.UpdatePetWithFormHandler")
   356  	}
   357  	if o.UserUpdateUserHandler == nil {
   358  		unregistered = append(unregistered, "user.UpdateUserHandler")
   359  	}
   360  
   361  	if len(unregistered) > 0 {
   362  		return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
   363  	}
   364  
   365  	return nil
   366  }
   367  
   368  // ServeErrorFor gets a error handler for a given operation id
   369  func (o *PetstoreAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
   370  	return o.ServeError
   371  }
   372  
   373  // AuthenticatorsFor gets the authenticators for the specified security schemes
   374  func (o *PetstoreAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
   375  	result := make(map[string]runtime.Authenticator)
   376  	for name := range schemes {
   377  		switch name {
   378  		case "api_key":
   379  			scheme := schemes[name]
   380  			result[name] = o.APIKeyAuthenticator(scheme.Name, scheme.In, o.APIKeyAuth)
   381  
   382  		case "petstore_auth":
   383  			result[name] = o.BearerAuthenticator(name, o.PetstoreAuthAuth)
   384  
   385  		}
   386  	}
   387  	return result
   388  }
   389  
   390  // Authorizer returns the registered authorizer
   391  func (o *PetstoreAPI) Authorizer() runtime.Authorizer {
   392  	return o.APIAuthorizer
   393  }
   394  
   395  // ConsumersFor gets the consumers for the specified media types.
   396  // MIME type parameters are ignored here.
   397  func (o *PetstoreAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
   398  	result := make(map[string]runtime.Consumer, len(mediaTypes))
   399  	for _, mt := range mediaTypes {
   400  		switch mt {
   401  		case "application/json":
   402  			result["application/json"] = o.JSONConsumer
   403  		case "application/x-www-form-urlencoded":
   404  			result["application/x-www-form-urlencoded"] = o.UrlformConsumer
   405  		case "application/xml":
   406  			result["application/xml"] = o.XMLConsumer
   407  		}
   408  
   409  		if c, ok := o.customConsumers[mt]; ok {
   410  			result[mt] = c
   411  		}
   412  	}
   413  	return result
   414  }
   415  
   416  // ProducersFor gets the producers for the specified media types.
   417  // MIME type parameters are ignored here.
   418  func (o *PetstoreAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
   419  	result := make(map[string]runtime.Producer, len(mediaTypes))
   420  	for _, mt := range mediaTypes {
   421  		switch mt {
   422  		case "application/json":
   423  			result["application/json"] = o.JSONProducer
   424  		case "application/xml":
   425  			result["application/xml"] = o.XMLProducer
   426  		}
   427  
   428  		if p, ok := o.customProducers[mt]; ok {
   429  			result[mt] = p
   430  		}
   431  	}
   432  	return result
   433  }
   434  
   435  // HandlerFor gets a http.Handler for the provided operation method and path
   436  func (o *PetstoreAPI) HandlerFor(method, path string) (http.Handler, bool) {
   437  	if o.handlers == nil {
   438  		return nil, false
   439  	}
   440  	um := strings.ToUpper(method)
   441  	if _, ok := o.handlers[um]; !ok {
   442  		return nil, false
   443  	}
   444  	if path == "/" {
   445  		path = ""
   446  	}
   447  	h, ok := o.handlers[um][path]
   448  	return h, ok
   449  }
   450  
   451  // Context returns the middleware context for the petstore API
   452  func (o *PetstoreAPI) Context() *middleware.Context {
   453  	if o.context == nil {
   454  		o.context = middleware.NewRoutableContext(o.spec, o, nil)
   455  	}
   456  
   457  	return o.context
   458  }
   459  
   460  func (o *PetstoreAPI) initHandlerCache() {
   461  	o.Context() // don't care about the result, just that the initialization happened
   462  	if o.handlers == nil {
   463  		o.handlers = make(map[string]map[string]http.Handler)
   464  	}
   465  
   466  	if o.handlers["POST"] == nil {
   467  		o.handlers["POST"] = make(map[string]http.Handler)
   468  	}
   469  	o.handlers["POST"]["/pets"] = pet.NewAddPet(o.context, o.PetAddPetHandler)
   470  	if o.handlers["POST"] == nil {
   471  		o.handlers["POST"] = make(map[string]http.Handler)
   472  	}
   473  	o.handlers["POST"]["/users"] = user.NewCreateUser(o.context, o.UserCreateUserHandler)
   474  	if o.handlers["POST"] == nil {
   475  		o.handlers["POST"] = make(map[string]http.Handler)
   476  	}
   477  	o.handlers["POST"]["/users/createWithArray"] = user.NewCreateUsersWithArrayInput(o.context, o.UserCreateUsersWithArrayInputHandler)
   478  	if o.handlers["POST"] == nil {
   479  		o.handlers["POST"] = make(map[string]http.Handler)
   480  	}
   481  	o.handlers["POST"]["/users/createWithList"] = user.NewCreateUsersWithListInput(o.context, o.UserCreateUsersWithListInputHandler)
   482  	if o.handlers["DELETE"] == nil {
   483  		o.handlers["DELETE"] = make(map[string]http.Handler)
   484  	}
   485  	o.handlers["DELETE"]["/stores/order/{orderId}"] = store.NewDeleteOrder(o.context, o.StoreDeleteOrderHandler)
   486  	if o.handlers["DELETE"] == nil {
   487  		o.handlers["DELETE"] = make(map[string]http.Handler)
   488  	}
   489  	o.handlers["DELETE"]["/pets/{petId}"] = pet.NewDeletePet(o.context, o.PetDeletePetHandler)
   490  	if o.handlers["DELETE"] == nil {
   491  		o.handlers["DELETE"] = make(map[string]http.Handler)
   492  	}
   493  	o.handlers["DELETE"]["/users/{username}"] = user.NewDeleteUser(o.context, o.UserDeleteUserHandler)
   494  	if o.handlers["GET"] == nil {
   495  		o.handlers["GET"] = make(map[string]http.Handler)
   496  	}
   497  	o.handlers["GET"]["/pets/findByStatus"] = pet.NewFindPetsByStatus(o.context, o.PetFindPetsByStatusHandler)
   498  	if o.handlers["GET"] == nil {
   499  		o.handlers["GET"] = make(map[string]http.Handler)
   500  	}
   501  	o.handlers["GET"]["/pets/findByTags"] = pet.NewFindPetsByTags(o.context, o.PetFindPetsByTagsHandler)
   502  	if o.handlers["GET"] == nil {
   503  		o.handlers["GET"] = make(map[string]http.Handler)
   504  	}
   505  	o.handlers["GET"]["/stores/order/{orderId}"] = store.NewGetOrderByID(o.context, o.StoreGetOrderByIDHandler)
   506  	if o.handlers["GET"] == nil {
   507  		o.handlers["GET"] = make(map[string]http.Handler)
   508  	}
   509  	o.handlers["GET"]["/pets/{petId}"] = pet.NewGetPetByID(o.context, o.PetGetPetByIDHandler)
   510  	if o.handlers["GET"] == nil {
   511  		o.handlers["GET"] = make(map[string]http.Handler)
   512  	}
   513  	o.handlers["GET"]["/users/{username}"] = user.NewGetUserByName(o.context, o.UserGetUserByNameHandler)
   514  	if o.handlers["GET"] == nil {
   515  		o.handlers["GET"] = make(map[string]http.Handler)
   516  	}
   517  	o.handlers["GET"]["/users/login"] = user.NewLoginUser(o.context, o.UserLoginUserHandler)
   518  	if o.handlers["GET"] == nil {
   519  		o.handlers["GET"] = make(map[string]http.Handler)
   520  	}
   521  	o.handlers["GET"]["/users/logout"] = user.NewLogoutUser(o.context, o.UserLogoutUserHandler)
   522  	if o.handlers["POST"] == nil {
   523  		o.handlers["POST"] = make(map[string]http.Handler)
   524  	}
   525  	o.handlers["POST"]["/stores/order"] = store.NewPlaceOrder(o.context, o.StorePlaceOrderHandler)
   526  	if o.handlers["PUT"] == nil {
   527  		o.handlers["PUT"] = make(map[string]http.Handler)
   528  	}
   529  	o.handlers["PUT"]["/pets"] = pet.NewUpdatePet(o.context, o.PetUpdatePetHandler)
   530  	if o.handlers["POST"] == nil {
   531  		o.handlers["POST"] = make(map[string]http.Handler)
   532  	}
   533  	o.handlers["POST"]["/pets/{petId}"] = pet.NewUpdatePetWithForm(o.context, o.PetUpdatePetWithFormHandler)
   534  	if o.handlers["PUT"] == nil {
   535  		o.handlers["PUT"] = make(map[string]http.Handler)
   536  	}
   537  	o.handlers["PUT"]["/users/{username}"] = user.NewUpdateUser(o.context, o.UserUpdateUserHandler)
   538  }
   539  
   540  // Serve creates a http handler to serve the API over HTTP
   541  // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
   542  func (o *PetstoreAPI) Serve(builder middleware.Builder) http.Handler {
   543  	o.Init()
   544  
   545  	if o.Middleware != nil {
   546  		return o.Middleware(builder)
   547  	}
   548  	if o.useSwaggerUI {
   549  		return o.context.APIHandlerSwaggerUI(builder)
   550  	}
   551  	return o.context.APIHandler(builder)
   552  }
   553  
   554  // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
   555  func (o *PetstoreAPI) Init() {
   556  	if len(o.handlers) == 0 {
   557  		o.initHandlerCache()
   558  	}
   559  }
   560  
   561  // RegisterConsumer allows you to add (or override) a consumer for a media type.
   562  func (o *PetstoreAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
   563  	o.customConsumers[mediaType] = consumer
   564  }
   565  
   566  // RegisterProducer allows you to add (or override) a producer for a media type.
   567  func (o *PetstoreAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
   568  	o.customProducers[mediaType] = producer
   569  }
   570  
   571  // AddMiddlewareFor adds a http middleware to existing handler
   572  func (o *PetstoreAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
   573  	um := strings.ToUpper(method)
   574  	if path == "/" {
   575  		path = ""
   576  	}
   577  	o.Init()
   578  	if h, ok := o.handlers[um][path]; ok {
   579  		o.handlers[method][path] = builder(h)
   580  	}
   581  }