[go-server] Change Routes type from []Route to map[string]Route (#15084)

* Change Routes to map[string]Route

* Fix linting issues

* Regenerate samples
This commit is contained in:
Ween Jiann 2023-04-11 15:40:06 +08:00 committed by GitHub
parent b6d2e0d222
commit 792c49a0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 334 additions and 464 deletions

View File

@ -48,13 +48,16 @@ func New{{classname}}Controller(s {{classname}}Servicer, opts ...{{classname}}Op
// Routes returns all the api routes for the {{classname}}Controller // Routes returns all the api routes for the {{classname}}Controller
func (c *{{classname}}Controller) Routes() Routes { func (c *{{classname}}Controller) Routes() Routes {
return Routes{ {{#operations}}{{#operation}} return Routes{
{ {{#operations}}
"{{operationId}}", {{#operation}}
"{{operationId}}": Route{
strings.ToUpper("{{httpMethod}}"), strings.ToUpper("{{httpMethod}}"),
"{{{basePathWithoutHost}}}{{{path}}}", "{{{basePathWithoutHost}}}{{{path}}}",
c.{{operationId}}, c.{{operationId}},
},{{/operation}}{{/operations}} },
{{/operation}}
{{/operations}}
} }
}{{#operations}}{{#operation}} }{{#operations}}{{#operation}}
@ -234,5 +237,4 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code,{{#addResponseHeaders}} result.Headers,{{/addResponseHeaders}} w) EncodeJSONResponse(result.Body, &result.Code,{{#addResponseHeaders}} result.Headers,{{/addResponseHeaders}} w)
}{{/operation}}{{/operations}} }{{/operation}}{{/operations}}

View File

@ -1,7 +1,7 @@
{{>partial_header}} {{>partial_header}}
package {{packageName}} package {{packageName}}
// ImplResponse response defines an error code with the associated body // ImplResponse defines an implementation response with error code and the associated body
type ImplResponse struct { type ImplResponse struct {
Code int Code int
{{#addResponseHeaders}} {{#addResponseHeaders}}

View File

@ -29,14 +29,13 @@ import (
// A Route defines the parameters for an api endpoint // A Route defines the parameters for an api endpoint
type Route struct { type Route struct {
Name string
Method string Method string
Pattern string Pattern string
HandlerFunc http.HandlerFunc HandlerFunc http.HandlerFunc
} }
// Routes are a collection of defined api endpoints // Routes is a map of defined api endpoints
type Routes []Route type Routes map[string]Route
// Router defines the required methods for retrieving api routes // Router defines the required methods for retrieving api routes
type Router interface { type Router interface {
@ -60,12 +59,12 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi}
{{/chi}} {{/chi}}
{{/routers}} {{/routers}}
for _, api := range routers { for _, api := range routers {
for _, route := range api.Routes() { for name, route := range api.Routes() {
var handler http.Handler var handler http.Handler
handler = route.HandlerFunc handler = route.HandlerFunc
{{#routers}} {{#routers}}
{{#mux}} {{#mux}}
handler = Logger(handler, route.Name) handler = Logger(handler, name)
{{#featureCORS}} {{#featureCORS}}
handler = handlers.CORS()(handler) handler = handlers.CORS()(handler)
{{/featureCORS}} {{/featureCORS}}
@ -73,7 +72,7 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi}
router. router.
Methods(route.Method). Methods(route.Method).
Path(route.Pattern). Path(route.Pattern).
Name(route.Name). Name(name).
Handler(handler) Handler(handler)
{{/mux}} {{/mux}}
{{#chi}} {{#chi}}
@ -90,13 +89,11 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi}
func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} headers map[string][]string,{{/addResponseHeaders}} w http.ResponseWriter) error { func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} headers map[string][]string,{{/addResponseHeaders}} w http.ResponseWriter) error {
{{#addResponseHeaders}} {{#addResponseHeaders}}
wHeader := w.Header() wHeader := w.Header()
if headers != nil {
for key, values := range headers { for key, values := range headers {
for _, value := range values { for _, value := range values {
wHeader.Add(key, value) wHeader.Add(key, value)
} }
} }
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8") wHeader.Set("Content-Type", "application/json; charset=UTF-8")
{{/addResponseHeaders}} {{/addResponseHeaders}}
{{^addResponseHeaders}} {{^addResponseHeaders}}

View File

@ -29,13 +29,13 @@ func (s *{{classname}}Service) {{nickname}}(ctx context.Context{{#allParams}}, {
{{#responses}} {{#responses}}
{{#dataType}} {{#dataType}}
//TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ...
//return Response({{code}}, {{dataType}}{}), nil // return Response({{code}}, {{dataType}}{}), nil
{{/dataType}} {{/dataType}}
{{^dataType}} {{^dataType}}
//TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ...
//return Response({{code}}, nil),nil // return Response({{code}}, nil),nil
{{/dataType}} {{/dataType}}
{{/responses}} {{/responses}}

View File

@ -50,50 +50,42 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
// Routes returns all the api routes for the PetApiController // Routes returns all the api routes for the PetApiController
func (c *PetApiController) Routes() Routes { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ "AddPet": Route{
"AddPet",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet", "/v2/pet",
c.AddPet, c.AddPet,
}, },
{ "DeletePet": Route{
"DeletePet",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.DeletePet, c.DeletePet,
}, },
{ "FindPetsByStatus": Route{
"FindPetsByStatus",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByStatus", "/v2/pet/findByStatus",
c.FindPetsByStatus, c.FindPetsByStatus,
}, },
{ "FindPetsByTags": Route{
"FindPetsByTags",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByTags", "/v2/pet/findByTags",
c.FindPetsByTags, c.FindPetsByTags,
}, },
{ "GetPetById": Route{
"GetPetById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.GetPetById, c.GetPetById,
}, },
{ "UpdatePet": Route{
"UpdatePet",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/pet", "/v2/pet",
c.UpdatePet, c.UpdatePet,
}, },
{ "UpdatePetWithForm": Route{
"UpdatePetWithForm",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.UpdatePetWithForm, c.UpdatePetWithForm,
}, },
{ "UploadFile": Route{
"UploadFile",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}/uploadImage", "/v2/pet/{petId}/uploadImage",
c.UploadFile, c.UploadFile,
@ -122,7 +114,6 @@ func (c *PetApiController) AddPet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeletePet - Deletes a pet // DeletePet - Deletes a pet
@ -143,7 +134,6 @@ func (c *PetApiController) DeletePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByStatus - Finds Pets by status // FindPetsByStatus - Finds Pets by status
@ -158,7 +148,6 @@ func (c *PetApiController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByTags - Finds Pets by tags // FindPetsByTags - Finds Pets by tags
@ -174,7 +163,6 @@ func (c *PetApiController) FindPetsByTags(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetPetById - Find pet by ID // GetPetById - Find pet by ID
@ -194,7 +182,6 @@ func (c *PetApiController) GetPetById(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePet - Update an existing pet // UpdatePet - Update an existing pet
@ -218,7 +205,6 @@ func (c *PetApiController) UpdatePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePetWithForm - Updates a pet in the store with form data // UpdatePetWithForm - Updates a pet in the store with form data
@ -244,7 +230,6 @@ func (c *PetApiController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UploadFile - uploads an image // UploadFile - uploads an image
@ -275,5 +260,4 @@ func (c *PetApiController) UploadFile(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -32,11 +32,11 @@ func (s *PetApiService) AddPet(ctx context.Context, pet Pet) (ImplResponse, erro
// TODO - update AddPet with the required logic for this service method. // TODO - update AddPet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented")
} }
@ -46,8 +46,8 @@ func (s *PetApiService) DeletePet(ctx context.Context, petId int64, apiKey strin
// TODO - update DeletePet with the required logic for this service method. // TODO - update DeletePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented")
} }
@ -57,11 +57,11 @@ func (s *PetApiService) FindPetsByStatus(ctx context.Context, status []string) (
// TODO - update FindPetsByStatus with the required logic for this service method. // TODO - update FindPetsByStatus with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented")
} }
@ -72,11 +72,11 @@ func (s *PetApiService) FindPetsByTags(ctx context.Context, tags []string) (Impl
// TODO - update FindPetsByTags with the required logic for this service method. // TODO - update FindPetsByTags with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented")
} }
@ -86,14 +86,14 @@ func (s *PetApiService) GetPetById(ctx context.Context, petId int64) (ImplRespon
// TODO - update GetPetById with the required logic for this service method. // TODO - update GetPetById with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented")
} }
@ -103,17 +103,17 @@ func (s *PetApiService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, e
// TODO - update UpdatePet with the required logic for this service method. // TODO - update UpdatePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented")
} }
@ -123,8 +123,8 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
// TODO - update UpdatePetWithForm with the required logic for this service method. // TODO - update UpdatePetWithForm with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented")
} }
@ -134,8 +134,8 @@ func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalM
// TODO - update UploadFile with the required logic for this service method. // TODO - update UploadFile with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ...
//return Response(200, ApiResponse{}), nil // return Response(200, ApiResponse{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented")
} }

View File

@ -50,26 +50,22 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
// Routes returns all the api routes for the StoreApiController // Routes returns all the api routes for the StoreApiController
func (c *StoreApiController) Routes() Routes { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ "DeleteOrder": Route{
"DeleteOrder",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.DeleteOrder, c.DeleteOrder,
}, },
{ "GetInventory": Route{
"GetInventory",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/inventory", "/v2/store/inventory",
c.GetInventory, c.GetInventory,
}, },
{ "GetOrderById": Route{
"GetOrderById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.GetOrderById, c.GetOrderById,
}, },
{ "PlaceOrder": Route{
"PlaceOrder",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/store/order", "/v2/store/order",
c.PlaceOrder, c.PlaceOrder,
@ -90,7 +86,6 @@ func (c *StoreApiController) DeleteOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetInventory - Returns pet inventories by status // GetInventory - Returns pet inventories by status
@ -103,7 +98,6 @@ func (c *StoreApiController) GetInventory(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetOrderById - Find purchase order by ID // GetOrderById - Find purchase order by ID
@ -123,7 +117,6 @@ func (c *StoreApiController) GetOrderById(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// PlaceOrder - Place an order for a pet // PlaceOrder - Place an order for a pet
@ -147,5 +140,4 @@ func (c *StoreApiController) PlaceOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,11 +31,11 @@ func (s *StoreApiService) DeleteOrder(ctx context.Context, orderId string) (Impl
// TODO - update DeleteOrder with the required logic for this service method. // TODO - update DeleteOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented")
} }
@ -45,8 +45,8 @@ func (s *StoreApiService) GetInventory(ctx context.Context) (ImplResponse, error
// TODO - update GetInventory with the required logic for this service method. // TODO - update GetInventory with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ...
//return Response(200, map[string]int32{}), nil // return Response(200, map[string]int32{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented")
} }
@ -56,14 +56,14 @@ func (s *StoreApiService) GetOrderById(ctx context.Context, orderId int64) (Impl
// TODO - update GetOrderById with the required logic for this service method. // TODO - update GetOrderById with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented")
} }
@ -73,11 +73,11 @@ func (s *StoreApiService) PlaceOrder(ctx context.Context, order Order) (ImplResp
// TODO - update PlaceOrder with the required logic for this service method. // TODO - update PlaceOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented")
} }

View File

@ -50,50 +50,42 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
// Routes returns all the api routes for the UserApiController // Routes returns all the api routes for the UserApiController
func (c *UserApiController) Routes() Routes { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ "CreateUser": Route{
"CreateUser",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user", "/v2/user",
c.CreateUser, c.CreateUser,
}, },
{ "CreateUsersWithArrayInput": Route{
"CreateUsersWithArrayInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithArray", "/v2/user/createWithArray",
c.CreateUsersWithArrayInput, c.CreateUsersWithArrayInput,
}, },
{ "CreateUsersWithListInput": Route{
"CreateUsersWithListInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithList", "/v2/user/createWithList",
c.CreateUsersWithListInput, c.CreateUsersWithListInput,
}, },
{ "DeleteUser": Route{
"DeleteUser",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/user/{username}", "/v2/user/{username}",
c.DeleteUser, c.DeleteUser,
}, },
{ "GetUserByName": Route{
"GetUserByName",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/{username}", "/v2/user/{username}",
c.GetUserByName, c.GetUserByName,
}, },
{ "LoginUser": Route{
"LoginUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/login", "/v2/user/login",
c.LoginUser, c.LoginUser,
}, },
{ "LogoutUser": Route{
"LogoutUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/logout", "/v2/user/logout",
c.LogoutUser, c.LogoutUser,
}, },
{ "UpdateUser": Route{
"UpdateUser",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/user/{username}", "/v2/user/{username}",
c.UpdateUser, c.UpdateUser,
@ -122,7 +114,6 @@ func (c *UserApiController) CreateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithArrayInput - Creates list of users with given input array // CreateUsersWithArrayInput - Creates list of users with given input array
@ -148,7 +139,6 @@ func (c *UserApiController) CreateUsersWithArrayInput(w http.ResponseWriter, r *
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithListInput - Creates list of users with given input array // CreateUsersWithListInput - Creates list of users with given input array
@ -174,7 +164,6 @@ func (c *UserApiController) CreateUsersWithListInput(w http.ResponseWriter, r *h
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeleteUser - Delete user // DeleteUser - Delete user
@ -190,7 +179,6 @@ func (c *UserApiController) DeleteUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetUserByName - Get user by user name // GetUserByName - Get user by user name
@ -206,7 +194,6 @@ func (c *UserApiController) GetUserByName(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LoginUser - Logs user into the system // LoginUser - Logs user into the system
@ -222,7 +209,6 @@ func (c *UserApiController) LoginUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LogoutUser - Logs out current logged in user session // LogoutUser - Logs out current logged in user session
@ -235,7 +221,6 @@ func (c *UserApiController) LogoutUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdateUser - Updated user // UpdateUser - Updated user
@ -262,5 +247,4 @@ func (c *UserApiController) UpdateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,8 +31,8 @@ func (s *UserApiService) CreateUser(ctx context.Context, user User) (ImplRespons
// TODO - update CreateUser with the required logic for this service method. // TODO - update CreateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented")
} }
@ -42,8 +42,8 @@ func (s *UserApiService) CreateUsersWithArrayInput(ctx context.Context, user []U
// TODO - update CreateUsersWithArrayInput with the required logic for this service method. // TODO - update CreateUsersWithArrayInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented")
} }
@ -53,8 +53,8 @@ func (s *UserApiService) CreateUsersWithListInput(ctx context.Context, user []Us
// TODO - update CreateUsersWithListInput with the required logic for this service method. // TODO - update CreateUsersWithListInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented")
} }
@ -64,11 +64,11 @@ func (s *UserApiService) DeleteUser(ctx context.Context, username string) (ImplR
// TODO - update DeleteUser with the required logic for this service method. // TODO - update DeleteUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented")
} }
@ -78,14 +78,14 @@ func (s *UserApiService) GetUserByName(ctx context.Context, username string) (Im
// TODO - update GetUserByName with the required logic for this service method. // TODO - update GetUserByName with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ...
//return Response(200, User{}), nil // return Response(200, User{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented")
} }
@ -95,11 +95,11 @@ func (s *UserApiService) LoginUser(ctx context.Context, username string, passwor
// TODO - update LoginUser with the required logic for this service method. // TODO - update LoginUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ...
//return Response(200, string{}), nil // return Response(200, string{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented")
} }
@ -109,8 +109,8 @@ func (s *UserApiService) LogoutUser(ctx context.Context) (ImplResponse, error) {
// TODO - update LogoutUser with the required logic for this service method. // TODO - update LogoutUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented")
} }
@ -120,11 +120,11 @@ func (s *UserApiService) UpdateUser(ctx context.Context, username string, user U
// TODO - update UpdateUser with the required logic for this service method. // TODO - update UpdateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented")
} }

View File

@ -9,7 +9,7 @@
package petstoreserver package petstoreserver
// ImplResponse response defines an error code with the associated body // ImplResponse defines an implementation response with error code and the associated body
type ImplResponse struct { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string

View File

@ -23,14 +23,13 @@ import (
// A Route defines the parameters for an api endpoint // A Route defines the parameters for an api endpoint
type Route struct { type Route struct {
Name string
Method string Method string
Pattern string Pattern string
HandlerFunc http.HandlerFunc HandlerFunc http.HandlerFunc
} }
// Routes are a collection of defined api endpoints // Routes is a map of defined api endpoints
type Routes []Route type Routes map[string]Route
// Router defines the required methods for retrieving api routes // Router defines the required methods for retrieving api routes
type Router interface { type Router interface {
@ -43,15 +42,15 @@ const errMsgRequiredMissing = "required parameter is missing"
func NewRouter(routers ...Router) *mux.Router { func NewRouter(routers ...Router) *mux.Router {
router := mux.NewRouter().StrictSlash(true) router := mux.NewRouter().StrictSlash(true)
for _, api := range routers { for _, api := range routers {
for _, route := range api.Routes() { for name, route := range api.Routes() {
var handler http.Handler var handler http.Handler
handler = route.HandlerFunc handler = route.HandlerFunc
handler = Logger(handler, route.Name) handler = Logger(handler, name)
router. router.
Methods(route.Method). Methods(route.Method).
Path(route.Pattern). Path(route.Pattern).
Name(route.Name). Name(name).
Handler(handler) Handler(handler)
} }
} }
@ -62,13 +61,11 @@ func NewRouter(routers ...Router) *mux.Router {
// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code // EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error { func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error {
wHeader := w.Header() wHeader := w.Header()
if headers != nil {
for key, values := range headers { for key, values := range headers {
for _, value := range values { for _, value := range values {
wHeader.Add(key, value) wHeader.Add(key, value)
} }
} }
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8") wHeader.Set("Content-Type", "application/json; charset=UTF-8")
if status != nil { if status != nil {
w.WriteHeader(*status) w.WriteHeader(*status)

View File

@ -50,50 +50,42 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
// Routes returns all the api routes for the PetApiController // Routes returns all the api routes for the PetApiController
func (c *PetApiController) Routes() Routes { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ "AddPet": Route{
"AddPet",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet", "/v2/pet",
c.AddPet, c.AddPet,
}, },
{ "DeletePet": Route{
"DeletePet",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.DeletePet, c.DeletePet,
}, },
{ "FindPetsByStatus": Route{
"FindPetsByStatus",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByStatus", "/v2/pet/findByStatus",
c.FindPetsByStatus, c.FindPetsByStatus,
}, },
{ "FindPetsByTags": Route{
"FindPetsByTags",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByTags", "/v2/pet/findByTags",
c.FindPetsByTags, c.FindPetsByTags,
}, },
{ "GetPetById": Route{
"GetPetById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.GetPetById, c.GetPetById,
}, },
{ "UpdatePet": Route{
"UpdatePet",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/pet", "/v2/pet",
c.UpdatePet, c.UpdatePet,
}, },
{ "UpdatePetWithForm": Route{
"UpdatePetWithForm",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.UpdatePetWithForm, c.UpdatePetWithForm,
}, },
{ "UploadFile": Route{
"UploadFile",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}/uploadImage", "/v2/pet/{petId}/uploadImage",
c.UploadFile, c.UploadFile,
@ -122,7 +114,6 @@ func (c *PetApiController) AddPet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeletePet - Deletes a pet // DeletePet - Deletes a pet
@ -142,7 +133,6 @@ func (c *PetApiController) DeletePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByStatus - Finds Pets by status // FindPetsByStatus - Finds Pets by status
@ -157,7 +147,6 @@ func (c *PetApiController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByTags - Finds Pets by tags // FindPetsByTags - Finds Pets by tags
@ -173,7 +162,6 @@ func (c *PetApiController) FindPetsByTags(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetPetById - Find pet by ID // GetPetById - Find pet by ID
@ -192,7 +180,6 @@ func (c *PetApiController) GetPetById(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePet - Update an existing pet // UpdatePet - Update an existing pet
@ -216,7 +203,6 @@ func (c *PetApiController) UpdatePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePetWithForm - Updates a pet in the store with form data // UpdatePetWithForm - Updates a pet in the store with form data
@ -241,7 +227,6 @@ func (c *PetApiController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UploadFile - uploads an image // UploadFile - uploads an image
@ -271,5 +256,4 @@ func (c *PetApiController) UploadFile(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -32,11 +32,11 @@ func (s *PetApiService) AddPet(ctx context.Context, pet Pet) (ImplResponse, erro
// TODO - update AddPet with the required logic for this service method. // TODO - update AddPet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented")
} }
@ -46,8 +46,8 @@ func (s *PetApiService) DeletePet(ctx context.Context, petId int64, apiKey strin
// TODO - update DeletePet with the required logic for this service method. // TODO - update DeletePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented")
} }
@ -57,11 +57,11 @@ func (s *PetApiService) FindPetsByStatus(ctx context.Context, status []string) (
// TODO - update FindPetsByStatus with the required logic for this service method. // TODO - update FindPetsByStatus with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented")
} }
@ -72,11 +72,11 @@ func (s *PetApiService) FindPetsByTags(ctx context.Context, tags []string) (Impl
// TODO - update FindPetsByTags with the required logic for this service method. // TODO - update FindPetsByTags with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented")
} }
@ -86,14 +86,14 @@ func (s *PetApiService) GetPetById(ctx context.Context, petId int64) (ImplRespon
// TODO - update GetPetById with the required logic for this service method. // TODO - update GetPetById with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented")
} }
@ -103,17 +103,17 @@ func (s *PetApiService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, e
// TODO - update UpdatePet with the required logic for this service method. // TODO - update UpdatePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented")
} }
@ -123,8 +123,8 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
// TODO - update UpdatePetWithForm with the required logic for this service method. // TODO - update UpdatePetWithForm with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented")
} }
@ -134,8 +134,8 @@ func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalM
// TODO - update UploadFile with the required logic for this service method. // TODO - update UploadFile with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ...
//return Response(200, ApiResponse{}), nil // return Response(200, ApiResponse{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented")
} }

View File

@ -50,26 +50,22 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
// Routes returns all the api routes for the StoreApiController // Routes returns all the api routes for the StoreApiController
func (c *StoreApiController) Routes() Routes { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ "DeleteOrder": Route{
"DeleteOrder",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.DeleteOrder, c.DeleteOrder,
}, },
{ "GetInventory": Route{
"GetInventory",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/inventory", "/v2/store/inventory",
c.GetInventory, c.GetInventory,
}, },
{ "GetOrderById": Route{
"GetOrderById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.GetOrderById, c.GetOrderById,
}, },
{ "PlaceOrder": Route{
"PlaceOrder",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/store/order", "/v2/store/order",
c.PlaceOrder, c.PlaceOrder,
@ -89,7 +85,6 @@ func (c *StoreApiController) DeleteOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetInventory - Returns pet inventories by status // GetInventory - Returns pet inventories by status
@ -102,7 +97,6 @@ func (c *StoreApiController) GetInventory(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetOrderById - Find purchase order by ID // GetOrderById - Find purchase order by ID
@ -121,7 +115,6 @@ func (c *StoreApiController) GetOrderById(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// PlaceOrder - Place an order for a pet // PlaceOrder - Place an order for a pet
@ -145,5 +138,4 @@ func (c *StoreApiController) PlaceOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,11 +31,11 @@ func (s *StoreApiService) DeleteOrder(ctx context.Context, orderId string) (Impl
// TODO - update DeleteOrder with the required logic for this service method. // TODO - update DeleteOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented")
} }
@ -45,8 +45,8 @@ func (s *StoreApiService) GetInventory(ctx context.Context) (ImplResponse, error
// TODO - update GetInventory with the required logic for this service method. // TODO - update GetInventory with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ...
//return Response(200, map[string]int32{}), nil // return Response(200, map[string]int32{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented")
} }
@ -56,14 +56,14 @@ func (s *StoreApiService) GetOrderById(ctx context.Context, orderId int64) (Impl
// TODO - update GetOrderById with the required logic for this service method. // TODO - update GetOrderById with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented")
} }
@ -73,11 +73,11 @@ func (s *StoreApiService) PlaceOrder(ctx context.Context, order Order) (ImplResp
// TODO - update PlaceOrder with the required logic for this service method. // TODO - update PlaceOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented")
} }

View File

@ -50,50 +50,42 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
// Routes returns all the api routes for the UserApiController // Routes returns all the api routes for the UserApiController
func (c *UserApiController) Routes() Routes { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ "CreateUser": Route{
"CreateUser",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user", "/v2/user",
c.CreateUser, c.CreateUser,
}, },
{ "CreateUsersWithArrayInput": Route{
"CreateUsersWithArrayInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithArray", "/v2/user/createWithArray",
c.CreateUsersWithArrayInput, c.CreateUsersWithArrayInput,
}, },
{ "CreateUsersWithListInput": Route{
"CreateUsersWithListInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithList", "/v2/user/createWithList",
c.CreateUsersWithListInput, c.CreateUsersWithListInput,
}, },
{ "DeleteUser": Route{
"DeleteUser",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/user/{username}", "/v2/user/{username}",
c.DeleteUser, c.DeleteUser,
}, },
{ "GetUserByName": Route{
"GetUserByName",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/{username}", "/v2/user/{username}",
c.GetUserByName, c.GetUserByName,
}, },
{ "LoginUser": Route{
"LoginUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/login", "/v2/user/login",
c.LoginUser, c.LoginUser,
}, },
{ "LogoutUser": Route{
"LogoutUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/logout", "/v2/user/logout",
c.LogoutUser, c.LogoutUser,
}, },
{ "UpdateUser": Route{
"UpdateUser",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/user/{username}", "/v2/user/{username}",
c.UpdateUser, c.UpdateUser,
@ -122,7 +114,6 @@ func (c *UserApiController) CreateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithArrayInput - Creates list of users with given input array // CreateUsersWithArrayInput - Creates list of users with given input array
@ -148,7 +139,6 @@ func (c *UserApiController) CreateUsersWithArrayInput(w http.ResponseWriter, r *
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithListInput - Creates list of users with given input array // CreateUsersWithListInput - Creates list of users with given input array
@ -174,7 +164,6 @@ func (c *UserApiController) CreateUsersWithListInput(w http.ResponseWriter, r *h
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeleteUser - Delete user // DeleteUser - Delete user
@ -189,7 +178,6 @@ func (c *UserApiController) DeleteUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetUserByName - Get user by user name // GetUserByName - Get user by user name
@ -204,7 +192,6 @@ func (c *UserApiController) GetUserByName(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LoginUser - Logs user into the system // LoginUser - Logs user into the system
@ -220,7 +207,6 @@ func (c *UserApiController) LoginUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LogoutUser - Logs out current logged in user session // LogoutUser - Logs out current logged in user session
@ -233,7 +219,6 @@ func (c *UserApiController) LogoutUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdateUser - Updated user // UpdateUser - Updated user
@ -259,5 +244,4 @@ func (c *UserApiController) UpdateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,8 +31,8 @@ func (s *UserApiService) CreateUser(ctx context.Context, user User) (ImplRespons
// TODO - update CreateUser with the required logic for this service method. // TODO - update CreateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented")
} }
@ -42,8 +42,8 @@ func (s *UserApiService) CreateUsersWithArrayInput(ctx context.Context, user []U
// TODO - update CreateUsersWithArrayInput with the required logic for this service method. // TODO - update CreateUsersWithArrayInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented")
} }
@ -53,8 +53,8 @@ func (s *UserApiService) CreateUsersWithListInput(ctx context.Context, user []Us
// TODO - update CreateUsersWithListInput with the required logic for this service method. // TODO - update CreateUsersWithListInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented")
} }
@ -64,11 +64,11 @@ func (s *UserApiService) DeleteUser(ctx context.Context, username string) (ImplR
// TODO - update DeleteUser with the required logic for this service method. // TODO - update DeleteUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented")
} }
@ -78,14 +78,14 @@ func (s *UserApiService) GetUserByName(ctx context.Context, username string) (Im
// TODO - update GetUserByName with the required logic for this service method. // TODO - update GetUserByName with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ...
//return Response(200, User{}), nil // return Response(200, User{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented")
} }
@ -95,11 +95,11 @@ func (s *UserApiService) LoginUser(ctx context.Context, username string, passwor
// TODO - update LoginUser with the required logic for this service method. // TODO - update LoginUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ...
//return Response(200, string{}), nil // return Response(200, string{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented")
} }
@ -109,8 +109,8 @@ func (s *UserApiService) LogoutUser(ctx context.Context) (ImplResponse, error) {
// TODO - update LogoutUser with the required logic for this service method. // TODO - update LogoutUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented")
} }
@ -120,11 +120,11 @@ func (s *UserApiService) UpdateUser(ctx context.Context, username string, user U
// TODO - update UpdateUser with the required logic for this service method. // TODO - update UpdateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented")
} }

View File

@ -9,7 +9,7 @@
package petstoreserver package petstoreserver
// ImplResponse response defines an error code with the associated body // ImplResponse defines an implementation response with error code and the associated body
type ImplResponse struct { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string

View File

@ -24,14 +24,13 @@ import (
// A Route defines the parameters for an api endpoint // A Route defines the parameters for an api endpoint
type Route struct { type Route struct {
Name string
Method string Method string
Pattern string Pattern string
HandlerFunc http.HandlerFunc HandlerFunc http.HandlerFunc
} }
// Routes are a collection of defined api endpoints // Routes is a map of defined api endpoints
type Routes []Route type Routes map[string]Route
// Router defines the required methods for retrieving api routes // Router defines the required methods for retrieving api routes
type Router interface { type Router interface {
@ -45,7 +44,7 @@ func NewRouter(routers ...Router) chi.Router {
router := chi.NewRouter() router := chi.NewRouter()
router.Use(middleware.Logger) router.Use(middleware.Logger)
for _, api := range routers { for _, api := range routers {
for _, route := range api.Routes() { for name, route := range api.Routes() {
var handler http.Handler var handler http.Handler
handler = route.HandlerFunc handler = route.HandlerFunc
router.Method(route.Method, route.Pattern, handler) router.Method(route.Method, route.Pattern, handler)
@ -58,13 +57,11 @@ func NewRouter(routers ...Router) chi.Router {
// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code // EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error { func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error {
wHeader := w.Header() wHeader := w.Header()
if headers != nil {
for key, values := range headers { for key, values := range headers {
for _, value := range values { for _, value := range values {
wHeader.Add(key, value) wHeader.Add(key, value)
} }
} }
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8") wHeader.Set("Content-Type", "application/json; charset=UTF-8")
if status != nil { if status != nil {
w.WriteHeader(*status) w.WriteHeader(*status)

View File

@ -50,50 +50,42 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
// Routes returns all the api routes for the PetApiController // Routes returns all the api routes for the PetApiController
func (c *PetApiController) Routes() Routes { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ "AddPet": Route{
"AddPet",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet", "/v2/pet",
c.AddPet, c.AddPet,
}, },
{ "DeletePet": Route{
"DeletePet",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.DeletePet, c.DeletePet,
}, },
{ "FindPetsByStatus": Route{
"FindPetsByStatus",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByStatus", "/v2/pet/findByStatus",
c.FindPetsByStatus, c.FindPetsByStatus,
}, },
{ "FindPetsByTags": Route{
"FindPetsByTags",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/findByTags", "/v2/pet/findByTags",
c.FindPetsByTags, c.FindPetsByTags,
}, },
{ "GetPetById": Route{
"GetPetById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.GetPetById, c.GetPetById,
}, },
{ "UpdatePet": Route{
"UpdatePet",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/pet", "/v2/pet",
c.UpdatePet, c.UpdatePet,
}, },
{ "UpdatePetWithForm": Route{
"UpdatePetWithForm",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}", "/v2/pet/{petId}",
c.UpdatePetWithForm, c.UpdatePetWithForm,
}, },
{ "UploadFile": Route{
"UploadFile",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/pet/{petId}/uploadImage", "/v2/pet/{petId}/uploadImage",
c.UploadFile, c.UploadFile,
@ -122,7 +114,6 @@ func (c *PetApiController) AddPet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeletePet - Deletes a pet // DeletePet - Deletes a pet
@ -142,7 +133,6 @@ func (c *PetApiController) DeletePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByStatus - Finds Pets by status // FindPetsByStatus - Finds Pets by status
@ -157,7 +147,6 @@ func (c *PetApiController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// FindPetsByTags - Finds Pets by tags // FindPetsByTags - Finds Pets by tags
@ -173,7 +162,6 @@ func (c *PetApiController) FindPetsByTags(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetPetById - Find pet by ID // GetPetById - Find pet by ID
@ -192,7 +180,6 @@ func (c *PetApiController) GetPetById(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePet - Update an existing pet // UpdatePet - Update an existing pet
@ -216,7 +203,6 @@ func (c *PetApiController) UpdatePet(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdatePetWithForm - Updates a pet in the store with form data // UpdatePetWithForm - Updates a pet in the store with form data
@ -241,7 +227,6 @@ func (c *PetApiController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UploadFile - uploads an image // UploadFile - uploads an image
@ -271,5 +256,4 @@ func (c *PetApiController) UploadFile(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -32,11 +32,11 @@ func (s *PetApiService) AddPet(ctx context.Context, pet Pet) (ImplResponse, erro
// TODO - update AddPet with the required logic for this service method. // TODO - update AddPet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented")
} }
@ -46,8 +46,8 @@ func (s *PetApiService) DeletePet(ctx context.Context, petId int64, apiKey strin
// TODO - update DeletePet with the required logic for this service method. // TODO - update DeletePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented")
} }
@ -57,11 +57,11 @@ func (s *PetApiService) FindPetsByStatus(ctx context.Context, status []string) (
// TODO - update FindPetsByStatus with the required logic for this service method. // TODO - update FindPetsByStatus with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented")
} }
@ -72,11 +72,11 @@ func (s *PetApiService) FindPetsByTags(ctx context.Context, tags []string) (Impl
// TODO - update FindPetsByTags with the required logic for this service method. // TODO - update FindPetsByTags with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ...
//return Response(200, []Pet{}), nil // return Response(200, []Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented")
} }
@ -86,14 +86,14 @@ func (s *PetApiService) GetPetById(ctx context.Context, petId int64) (ImplRespon
// TODO - update GetPetById with the required logic for this service method. // TODO - update GetPetById with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented")
} }
@ -103,17 +103,17 @@ func (s *PetApiService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, e
// TODO - update UpdatePet with the required logic for this service method. // TODO - update UpdatePet with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ...
//return Response(200, Pet{}), nil // return Response(200, Pet{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented")
} }
@ -123,8 +123,8 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
// TODO - update UpdatePetWithForm with the required logic for this service method. // TODO - update UpdatePetWithForm with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ...
//return Response(405, nil),nil // return Response(405, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented")
} }
@ -134,8 +134,8 @@ func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalM
// TODO - update UploadFile with the required logic for this service method. // TODO - update UploadFile with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ...
//return Response(200, ApiResponse{}), nil // return Response(200, ApiResponse{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented")
} }

View File

@ -50,26 +50,22 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
// Routes returns all the api routes for the StoreApiController // Routes returns all the api routes for the StoreApiController
func (c *StoreApiController) Routes() Routes { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ "DeleteOrder": Route{
"DeleteOrder",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.DeleteOrder, c.DeleteOrder,
}, },
{ "GetInventory": Route{
"GetInventory",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/inventory", "/v2/store/inventory",
c.GetInventory, c.GetInventory,
}, },
{ "GetOrderById": Route{
"GetOrderById",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/store/order/{orderId}", "/v2/store/order/{orderId}",
c.GetOrderById, c.GetOrderById,
}, },
{ "PlaceOrder": Route{
"PlaceOrder",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/store/order", "/v2/store/order",
c.PlaceOrder, c.PlaceOrder,
@ -89,7 +85,6 @@ func (c *StoreApiController) DeleteOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetInventory - Returns pet inventories by status // GetInventory - Returns pet inventories by status
@ -102,7 +97,6 @@ func (c *StoreApiController) GetInventory(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetOrderById - Find purchase order by ID // GetOrderById - Find purchase order by ID
@ -121,7 +115,6 @@ func (c *StoreApiController) GetOrderById(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// PlaceOrder - Place an order for a pet // PlaceOrder - Place an order for a pet
@ -145,5 +138,4 @@ func (c *StoreApiController) PlaceOrder(w http.ResponseWriter, r *http.Request)
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,11 +31,11 @@ func (s *StoreApiService) DeleteOrder(ctx context.Context, orderId string) (Impl
// TODO - update DeleteOrder with the required logic for this service method. // TODO - update DeleteOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteOrder method not implemented")
} }
@ -45,8 +45,8 @@ func (s *StoreApiService) GetInventory(ctx context.Context) (ImplResponse, error
// TODO - update GetInventory with the required logic for this service method. // TODO - update GetInventory with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, map[string]int32{}) or use other options such as http.Ok ...
//return Response(200, map[string]int32{}), nil // return Response(200, map[string]int32{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented")
} }
@ -56,14 +56,14 @@ func (s *StoreApiService) GetOrderById(ctx context.Context, orderId int64) (Impl
// TODO - update GetOrderById with the required logic for this service method. // TODO - update GetOrderById with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented")
} }
@ -73,11 +73,11 @@ func (s *StoreApiService) PlaceOrder(ctx context.Context, order Order) (ImplResp
// TODO - update PlaceOrder with the required logic for this service method. // TODO - update PlaceOrder with the required logic for this service method.
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ...
//return Response(200, Order{}), nil // return Response(200, Order{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented")
} }

View File

@ -50,50 +50,42 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
// Routes returns all the api routes for the UserApiController // Routes returns all the api routes for the UserApiController
func (c *UserApiController) Routes() Routes { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ "CreateUser": Route{
"CreateUser",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user", "/v2/user",
c.CreateUser, c.CreateUser,
}, },
{ "CreateUsersWithArrayInput": Route{
"CreateUsersWithArrayInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithArray", "/v2/user/createWithArray",
c.CreateUsersWithArrayInput, c.CreateUsersWithArrayInput,
}, },
{ "CreateUsersWithListInput": Route{
"CreateUsersWithListInput",
strings.ToUpper("Post"), strings.ToUpper("Post"),
"/v2/user/createWithList", "/v2/user/createWithList",
c.CreateUsersWithListInput, c.CreateUsersWithListInput,
}, },
{ "DeleteUser": Route{
"DeleteUser",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/v2/user/{username}", "/v2/user/{username}",
c.DeleteUser, c.DeleteUser,
}, },
{ "GetUserByName": Route{
"GetUserByName",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/{username}", "/v2/user/{username}",
c.GetUserByName, c.GetUserByName,
}, },
{ "LoginUser": Route{
"LoginUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/login", "/v2/user/login",
c.LoginUser, c.LoginUser,
}, },
{ "LogoutUser": Route{
"LogoutUser",
strings.ToUpper("Get"), strings.ToUpper("Get"),
"/v2/user/logout", "/v2/user/logout",
c.LogoutUser, c.LogoutUser,
}, },
{ "UpdateUser": Route{
"UpdateUser",
strings.ToUpper("Put"), strings.ToUpper("Put"),
"/v2/user/{username}", "/v2/user/{username}",
c.UpdateUser, c.UpdateUser,
@ -122,7 +114,6 @@ func (c *UserApiController) CreateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithArrayInput - Creates list of users with given input array // CreateUsersWithArrayInput - Creates list of users with given input array
@ -148,7 +139,6 @@ func (c *UserApiController) CreateUsersWithArrayInput(w http.ResponseWriter, r *
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// CreateUsersWithListInput - Creates list of users with given input array // CreateUsersWithListInput - Creates list of users with given input array
@ -174,7 +164,6 @@ func (c *UserApiController) CreateUsersWithListInput(w http.ResponseWriter, r *h
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// DeleteUser - Delete user // DeleteUser - Delete user
@ -189,7 +178,6 @@ func (c *UserApiController) DeleteUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// GetUserByName - Get user by user name // GetUserByName - Get user by user name
@ -204,7 +192,6 @@ func (c *UserApiController) GetUserByName(w http.ResponseWriter, r *http.Request
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LoginUser - Logs user into the system // LoginUser - Logs user into the system
@ -220,7 +207,6 @@ func (c *UserApiController) LoginUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// LogoutUser - Logs out current logged in user session // LogoutUser - Logs out current logged in user session
@ -233,7 +219,6 @@ func (c *UserApiController) LogoutUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }
// UpdateUser - Updated user // UpdateUser - Updated user
@ -259,5 +244,4 @@ func (c *UserApiController) UpdateUser(w http.ResponseWriter, r *http.Request) {
} }
// If no error, encode the body and the result code // If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
} }

View File

@ -31,8 +31,8 @@ func (s *UserApiService) CreateUser(ctx context.Context, user User) (ImplRespons
// TODO - update CreateUser with the required logic for this service method. // TODO - update CreateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUser method not implemented")
} }
@ -42,8 +42,8 @@ func (s *UserApiService) CreateUsersWithArrayInput(ctx context.Context, user []U
// TODO - update CreateUsersWithArrayInput with the required logic for this service method. // TODO - update CreateUsersWithArrayInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithArrayInput method not implemented")
} }
@ -53,8 +53,8 @@ func (s *UserApiService) CreateUsersWithListInput(ctx context.Context, user []Us
// TODO - update CreateUsersWithListInput with the required logic for this service method. // TODO - update CreateUsersWithListInput with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented")
} }
@ -64,11 +64,11 @@ func (s *UserApiService) DeleteUser(ctx context.Context, username string) (ImplR
// TODO - update DeleteUser with the required logic for this service method. // TODO - update DeleteUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented")
} }
@ -78,14 +78,14 @@ func (s *UserApiService) GetUserByName(ctx context.Context, username string) (Im
// TODO - update GetUserByName with the required logic for this service method. // TODO - update GetUserByName with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ...
//return Response(200, User{}), nil // return Response(200, User{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented")
} }
@ -95,11 +95,11 @@ func (s *UserApiService) LoginUser(ctx context.Context, username string, passwor
// TODO - update LoginUser with the required logic for this service method. // TODO - update LoginUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ...
//return Response(200, string{}), nil // return Response(200, string{}), nil
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented")
} }
@ -109,8 +109,8 @@ func (s *UserApiService) LogoutUser(ctx context.Context) (ImplResponse, error) {
// TODO - update LogoutUser with the required logic for this service method. // TODO - update LogoutUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(0, {}) or use other options such as http.Ok ...
//return Response(0, nil),nil // return Response(0, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented")
} }
@ -120,11 +120,11 @@ func (s *UserApiService) UpdateUser(ctx context.Context, username string, user U
// TODO - update UpdateUser with the required logic for this service method. // TODO - update UpdateUser with the required logic for this service method.
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
//return Response(400, nil),nil // return Response(400, nil),nil
//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return Response(404, nil),nil // return Response(404, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented")
} }

View File

@ -9,7 +9,7 @@
package petstoreserver package petstoreserver
// ImplResponse response defines an error code with the associated body // ImplResponse defines an implementation response with error code and the associated body
type ImplResponse struct { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string

View File

@ -24,14 +24,13 @@ import (
// A Route defines the parameters for an api endpoint // A Route defines the parameters for an api endpoint
type Route struct { type Route struct {
Name string
Method string Method string
Pattern string Pattern string
HandlerFunc http.HandlerFunc HandlerFunc http.HandlerFunc
} }
// Routes are a collection of defined api endpoints // Routes is a map of defined api endpoints
type Routes []Route type Routes map[string]Route
// Router defines the required methods for retrieving api routes // Router defines the required methods for retrieving api routes
type Router interface { type Router interface {
@ -45,7 +44,7 @@ func NewRouter(routers ...Router) chi.Router {
router := chi.NewRouter() router := chi.NewRouter()
router.Use(middleware.Logger) router.Use(middleware.Logger)
for _, api := range routers { for _, api := range routers {
for _, route := range api.Routes() { for name, route := range api.Routes() {
var handler http.Handler var handler http.Handler
handler = route.HandlerFunc handler = route.HandlerFunc
router.Method(route.Method, route.Pattern, handler) router.Method(route.Method, route.Pattern, handler)
@ -58,13 +57,11 @@ func NewRouter(routers ...Router) chi.Router {
// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code // EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error { func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error {
wHeader := w.Header() wHeader := w.Header()
if headers != nil {
for key, values := range headers { for key, values := range headers {
for _, value := range values { for _, value := range values {
wHeader.Add(key, value) wHeader.Add(key, value)
} }
} }
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8") wHeader.Set("Content-Type", "application/json; charset=UTF-8")
if status != nil { if status != nil {
w.WriteHeader(*status) w.WriteHeader(*status)