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