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