diff --git a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache index 9fb35bb4ecd..765ab782ed9 100644 --- a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache @@ -48,13 +48,16 @@ func New{{classname}}Controller(s {{classname}}Servicer, opts ...{{classname}}Op // Routes returns all the api routes for the {{classname}}Controller func (c *{{classname}}Controller) Routes() Routes { - return Routes{ {{#operations}}{{#operation}} - { - "{{operationId}}", + return Routes{ +{{#operations}} + {{#operation}} + "{{operationId}}": Route{ strings.ToUpper("{{httpMethod}}"), "{{{basePathWithoutHost}}}{{{path}}}", c.{{operationId}}, - },{{/operation}}{{/operations}} + }, + {{/operation}} +{{/operations}} } }{{#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 EncodeJSONResponse(result.Body, &result.Code,{{#addResponseHeaders}} result.Headers,{{/addResponseHeaders}} w) - }{{/operation}}{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/go-server/impl.mustache b/modules/openapi-generator/src/main/resources/go-server/impl.mustache index 81c25ffb973..2263f27fd38 100644 --- a/modules/openapi-generator/src/main/resources/go-server/impl.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/impl.mustache @@ -1,7 +1,7 @@ {{>partial_header}} 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 { Code int {{#addResponseHeaders}} diff --git a/modules/openapi-generator/src/main/resources/go-server/routers.mustache b/modules/openapi-generator/src/main/resources/go-server/routers.mustache index 27ba6151a50..1da7d805895 100644 --- a/modules/openapi-generator/src/main/resources/go-server/routers.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/routers.mustache @@ -29,14 +29,13 @@ import ( // A Route defines the parameters for an api endpoint type Route struct { - Name string Method string Pattern string HandlerFunc http.HandlerFunc } -// Routes are a collection of defined api endpoints -type Routes []Route +// Routes is a map of defined api endpoints +type Routes map[string]Route // Router defines the required methods for retrieving api routes type Router interface { @@ -60,12 +59,12 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi} {{/chi}} {{/routers}} for _, api := range routers { - for _, route := range api.Routes() { + for name, route := range api.Routes() { var handler http.Handler handler = route.HandlerFunc {{#routers}} {{#mux}} - handler = Logger(handler, route.Name) + handler = Logger(handler, name) {{#featureCORS}} handler = handlers.CORS()(handler) {{/featureCORS}} @@ -73,7 +72,7 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi} router. Methods(route.Method). Path(route.Pattern). - Name(route.Name). + Name(name). Handler(handler) {{/mux}} {{#chi}} @@ -90,11 +89,9 @@ 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 { {{#addResponseHeaders}} wHeader := w.Header() - if headers != nil { - for key, values := range headers { - for _, value := range values { - wHeader.Add(key, value) - } + for key, values := range headers { + for _, value := range values { + wHeader.Add(key, value) } } wHeader.Set("Content-Type", "application/json; charset=UTF-8") diff --git a/modules/openapi-generator/src/main/resources/go-server/service.mustache b/modules/openapi-generator/src/main/resources/go-server/service.mustache index baad4df800a..9fb0f66c0b2 100644 --- a/modules/openapi-generator/src/main/resources/go-server/service.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/service.mustache @@ -29,13 +29,13 @@ func (s *{{classname}}Service) {{nickname}}(ctx context.Context{{#allParams}}, { {{#responses}} {{#dataType}} - //TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... - //return Response({{code}}, {{dataType}}{}), nil + // TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... + // return Response({{code}}, {{dataType}}{}), nil {{/dataType}} {{^dataType}} - //TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... - //return Response({{code}}, nil),nil + // TODO: Uncomment the next line to return response Response({{code}}, {{dataType}}{}) or use other options such as http.Ok ... + // return Response({{code}}, nil),nil {{/dataType}} {{/responses}} diff --git a/samples/server/petstore/go-api-server/go/api_pet.go b/samples/server/petstore/go-api-server/go/api_pet.go index fb8041ee730..750a15f2820 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -49,51 +49,43 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { // Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { - return Routes{ - { - "AddPet", + return Routes{ + "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - { - "DeletePet", + "DeletePet": Route{ strings.ToUpper("Delete"), "/v2/pet/{petId}", c.DeletePet, }, - { - "FindPetsByStatus", + "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", c.FindPetsByStatus, }, - { - "FindPetsByTags", + "FindPetsByTags": Route{ strings.ToUpper("Get"), "/v2/pet/findByTags", c.FindPetsByTags, }, - { - "GetPetById", + "GetPetById": Route{ strings.ToUpper("Get"), "/v2/pet/{petId}", c.GetPetById, }, - { - "UpdatePet", + "UpdatePet": Route{ strings.ToUpper("Put"), "/v2/pet", c.UpdatePet, }, - { - "UpdatePetWithForm", + "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, - { - "UploadFile", + "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-api-server/go/api_pet_service.go b/samples/server/petstore/go-api-server/go/api_pet_service.go index 9a390ecef3d..5e39534585f 100644 --- a/samples/server/petstore/go-api-server/go/api_pet_service.go +++ b/samples/server/petstore/go-api-server/go/api_pet_service.go @@ -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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(200, ApiResponse{}), nil + // 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(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") } diff --git a/samples/server/petstore/go-api-server/go/api_store.go b/samples/server/petstore/go-api-server/go/api_store.go index b0df49b92d3..f0898e950de 100644 --- a/samples/server/petstore/go-api-server/go/api_store.go +++ b/samples/server/petstore/go-api-server/go/api_store.go @@ -49,27 +49,23 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { // Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { - return Routes{ - { - "DeleteOrder", + return Routes{ + "DeleteOrder": Route{ strings.ToUpper("Delete"), "/v2/store/order/{orderId}", c.DeleteOrder, }, - { - "GetInventory", + "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, - { - "GetOrderById", + "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - { - "PlaceOrder", + "PlaceOrder": Route{ strings.ToUpper("Post"), "/v2/store/order", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-api-server/go/api_store_service.go b/samples/server/petstore/go-api-server/go/api_store_service.go index 3c91040fa9f..4e3bb1456bd 100644 --- a/samples/server/petstore/go-api-server/go/api_store_service.go +++ b/samples/server/petstore/go-api-server/go/api_store_service.go @@ -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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, map[string]int32{}), nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") } diff --git a/samples/server/petstore/go-api-server/go/api_user.go b/samples/server/petstore/go-api-server/go/api_user.go index 5eb1f57d4be..b5148a45673 100644 --- a/samples/server/petstore/go-api-server/go/api_user.go +++ b/samples/server/petstore/go-api-server/go/api_user.go @@ -49,51 +49,43 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { // Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { - return Routes{ - { - "CreateUser", + return Routes{ + "CreateUser": Route{ strings.ToUpper("Post"), "/v2/user", c.CreateUser, }, - { - "CreateUsersWithArrayInput", + "CreateUsersWithArrayInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithArray", c.CreateUsersWithArrayInput, }, - { - "CreateUsersWithListInput", + "CreateUsersWithListInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithList", c.CreateUsersWithListInput, }, - { - "DeleteUser", + "DeleteUser": Route{ strings.ToUpper("Delete"), "/v2/user/{username}", c.DeleteUser, }, - { - "GetUserByName", + "GetUserByName": Route{ strings.ToUpper("Get"), "/v2/user/{username}", c.GetUserByName, }, - { - "LoginUser", + "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", c.LoginUser, }, - { - "LogoutUser", + "LogoutUser": Route{ strings.ToUpper("Get"), "/v2/user/logout", c.LogoutUser, }, - { - "UpdateUser", + "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-api-server/go/api_user_service.go b/samples/server/petstore/go-api-server/go/api_user_service.go index 6ae5a6d751b..8232b520c9e 100644 --- a/samples/server/petstore/go-api-server/go/api_user_service.go +++ b/samples/server/petstore/go-api-server/go/api_user_service.go @@ -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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, User{}), nil + // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... + // return Response(200, User{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, string{}), nil + // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... + // return Response(200, string{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } diff --git a/samples/server/petstore/go-api-server/go/impl.go b/samples/server/petstore/go-api-server/go/impl.go index 8c72e26a342..7bfb815be5e 100644 --- a/samples/server/petstore/go-api-server/go/impl.go +++ b/samples/server/petstore/go-api-server/go/impl.go @@ -9,7 +9,7 @@ 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 { Code int Headers map[string][]string diff --git a/samples/server/petstore/go-api-server/go/routers.go b/samples/server/petstore/go-api-server/go/routers.go index 6d4416f5654..0fdd72f365d 100644 --- a/samples/server/petstore/go-api-server/go/routers.go +++ b/samples/server/petstore/go-api-server/go/routers.go @@ -23,14 +23,13 @@ import ( // A Route defines the parameters for an api endpoint type Route struct { - Name string Method string Pattern string HandlerFunc http.HandlerFunc } -// Routes are a collection of defined api endpoints -type Routes []Route +// Routes is a map of defined api endpoints +type Routes map[string]Route // Router defines the required methods for retrieving api routes type Router interface { @@ -43,15 +42,15 @@ const errMsgRequiredMissing = "required parameter is missing" func NewRouter(routers ...Router) *mux.Router { router := mux.NewRouter().StrictSlash(true) for _, api := range routers { - for _, route := range api.Routes() { + for name, route := range api.Routes() { var handler http.Handler handler = route.HandlerFunc - handler = Logger(handler, route.Name) + handler = Logger(handler, name) router. Methods(route.Method). Path(route.Pattern). - Name(route.Name). + Name(name). Handler(handler) } } @@ -62,11 +61,9 @@ func NewRouter(routers ...Router) *mux.Router { // 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 { wHeader := w.Header() - if headers != nil { - for key, values := range headers { - for _, value := range values { - wHeader.Add(key, value) - } + for key, values := range headers { + for _, value := range values { + wHeader.Add(key, value) } } wHeader.Set("Content-Type", "application/json; charset=UTF-8") diff --git a/samples/server/petstore/go-chi-server/go/api_pet.go b/samples/server/petstore/go-chi-server/go/api_pet.go index 2202804fb20..9d5b489f708 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -49,51 +49,43 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { // Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { - return Routes{ - { - "AddPet", + return Routes{ + "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - { - "DeletePet", + "DeletePet": Route{ strings.ToUpper("Delete"), "/v2/pet/{petId}", c.DeletePet, }, - { - "FindPetsByStatus", + "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", c.FindPetsByStatus, }, - { - "FindPetsByTags", + "FindPetsByTags": Route{ strings.ToUpper("Get"), "/v2/pet/findByTags", c.FindPetsByTags, }, - { - "GetPetById", + "GetPetById": Route{ strings.ToUpper("Get"), "/v2/pet/{petId}", c.GetPetById, }, - { - "UpdatePet", + "UpdatePet": Route{ strings.ToUpper("Put"), "/v2/pet", c.UpdatePet, }, - { - "UpdatePetWithForm", + "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, - { - "UploadFile", + "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-chi-server/go/api_pet_service.go b/samples/server/petstore/go-chi-server/go/api_pet_service.go index 9a390ecef3d..5e39534585f 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet_service.go +++ b/samples/server/petstore/go-chi-server/go/api_pet_service.go @@ -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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(200, ApiResponse{}), nil + // 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(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") } diff --git a/samples/server/petstore/go-chi-server/go/api_store.go b/samples/server/petstore/go-chi-server/go/api_store.go index 67a30090afb..e3a80162b06 100644 --- a/samples/server/petstore/go-chi-server/go/api_store.go +++ b/samples/server/petstore/go-chi-server/go/api_store.go @@ -49,27 +49,23 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { // Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { - return Routes{ - { - "DeleteOrder", + return Routes{ + "DeleteOrder": Route{ strings.ToUpper("Delete"), "/v2/store/order/{orderId}", c.DeleteOrder, }, - { - "GetInventory", + "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, - { - "GetOrderById", + "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - { - "PlaceOrder", + "PlaceOrder": Route{ strings.ToUpper("Post"), "/v2/store/order", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-chi-server/go/api_store_service.go b/samples/server/petstore/go-chi-server/go/api_store_service.go index 3c91040fa9f..4e3bb1456bd 100644 --- a/samples/server/petstore/go-chi-server/go/api_store_service.go +++ b/samples/server/petstore/go-chi-server/go/api_store_service.go @@ -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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, map[string]int32{}), nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") } diff --git a/samples/server/petstore/go-chi-server/go/api_user.go b/samples/server/petstore/go-chi-server/go/api_user.go index a48ab1c454a..e98906d31ab 100644 --- a/samples/server/petstore/go-chi-server/go/api_user.go +++ b/samples/server/petstore/go-chi-server/go/api_user.go @@ -49,51 +49,43 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { // Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { - return Routes{ - { - "CreateUser", + return Routes{ + "CreateUser": Route{ strings.ToUpper("Post"), "/v2/user", c.CreateUser, }, - { - "CreateUsersWithArrayInput", + "CreateUsersWithArrayInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithArray", c.CreateUsersWithArrayInput, }, - { - "CreateUsersWithListInput", + "CreateUsersWithListInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithList", c.CreateUsersWithListInput, }, - { - "DeleteUser", + "DeleteUser": Route{ strings.ToUpper("Delete"), "/v2/user/{username}", c.DeleteUser, }, - { - "GetUserByName", + "GetUserByName": Route{ strings.ToUpper("Get"), "/v2/user/{username}", c.GetUserByName, }, - { - "LoginUser", + "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", c.LoginUser, }, - { - "LogoutUser", + "LogoutUser": Route{ strings.ToUpper("Get"), "/v2/user/logout", c.LogoutUser, }, - { - "UpdateUser", + "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-chi-server/go/api_user_service.go b/samples/server/petstore/go-chi-server/go/api_user_service.go index 6ae5a6d751b..8232b520c9e 100644 --- a/samples/server/petstore/go-chi-server/go/api_user_service.go +++ b/samples/server/petstore/go-chi-server/go/api_user_service.go @@ -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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, User{}), nil + // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... + // return Response(200, User{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, string{}), nil + // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... + // return Response(200, string{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } diff --git a/samples/server/petstore/go-chi-server/go/impl.go b/samples/server/petstore/go-chi-server/go/impl.go index 8c72e26a342..7bfb815be5e 100644 --- a/samples/server/petstore/go-chi-server/go/impl.go +++ b/samples/server/petstore/go-chi-server/go/impl.go @@ -9,7 +9,7 @@ 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 { Code int Headers map[string][]string diff --git a/samples/server/petstore/go-chi-server/go/routers.go b/samples/server/petstore/go-chi-server/go/routers.go index 5f3463d18c0..01afc3d166f 100644 --- a/samples/server/petstore/go-chi-server/go/routers.go +++ b/samples/server/petstore/go-chi-server/go/routers.go @@ -24,14 +24,13 @@ import ( // A Route defines the parameters for an api endpoint type Route struct { - Name string Method string Pattern string HandlerFunc http.HandlerFunc } -// Routes are a collection of defined api endpoints -type Routes []Route +// Routes is a map of defined api endpoints +type Routes map[string]Route // Router defines the required methods for retrieving api routes type Router interface { @@ -45,7 +44,7 @@ func NewRouter(routers ...Router) chi.Router { router := chi.NewRouter() router.Use(middleware.Logger) for _, api := range routers { - for _, route := range api.Routes() { + for name, route := range api.Routes() { var handler http.Handler handler = route.HandlerFunc router.Method(route.Method, route.Pattern, handler) @@ -58,11 +57,9 @@ func NewRouter(routers ...Router) chi.Router { // 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 { wHeader := w.Header() - if headers != nil { - for key, values := range headers { - for _, value := range values { - wHeader.Add(key, value) - } + for key, values := range headers { + for _, value := range values { + wHeader.Add(key, value) } } wHeader.Set("Content-Type", "application/json; charset=UTF-8") diff --git a/samples/server/petstore/go-server-required/go/api_pet.go b/samples/server/petstore/go-server-required/go/api_pet.go index 2202804fb20..9d5b489f708 100644 --- a/samples/server/petstore/go-server-required/go/api_pet.go +++ b/samples/server/petstore/go-server-required/go/api_pet.go @@ -49,51 +49,43 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { // Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { - return Routes{ - { - "AddPet", + return Routes{ + "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - { - "DeletePet", + "DeletePet": Route{ strings.ToUpper("Delete"), "/v2/pet/{petId}", c.DeletePet, }, - { - "FindPetsByStatus", + "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", c.FindPetsByStatus, }, - { - "FindPetsByTags", + "FindPetsByTags": Route{ strings.ToUpper("Get"), "/v2/pet/findByTags", c.FindPetsByTags, }, - { - "GetPetById", + "GetPetById": Route{ strings.ToUpper("Get"), "/v2/pet/{petId}", c.GetPetById, }, - { - "UpdatePet", + "UpdatePet": Route{ strings.ToUpper("Put"), "/v2/pet", c.UpdatePet, }, - { - "UpdatePetWithForm", + "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, - { - "UploadFile", + "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-server-required/go/api_pet_service.go b/samples/server/petstore/go-server-required/go/api_pet_service.go index 9a390ecef3d..5e39534585f 100644 --- a/samples/server/petstore/go-server-required/go/api_pet_service.go +++ b/samples/server/petstore/go-server-required/go/api_pet_service.go @@ -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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, []Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, []Pet{}) or use other options such as http.Ok ... + // return Response(200, []Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Pet{}), nil + // TODO: Uncomment the next line to return response Response(200, Pet{}) or use other options such as http.Ok ... + // return Response(200, Pet{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - //TODO: Uncomment the next line to return response Response(405, {}) or use other options such as http.Ok ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(405, nil),nil + // 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(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. // 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 ... - //return Response(200, ApiResponse{}), nil + // 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(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") } diff --git a/samples/server/petstore/go-server-required/go/api_store.go b/samples/server/petstore/go-server-required/go/api_store.go index 67a30090afb..e3a80162b06 100644 --- a/samples/server/petstore/go-server-required/go/api_store.go +++ b/samples/server/petstore/go-server-required/go/api_store.go @@ -49,27 +49,23 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { // Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { - return Routes{ - { - "DeleteOrder", + return Routes{ + "DeleteOrder": Route{ strings.ToUpper("Delete"), "/v2/store/order/{orderId}", c.DeleteOrder, }, - { - "GetInventory", + "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, - { - "GetOrderById", + "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - { - "PlaceOrder", + "PlaceOrder": Route{ strings.ToUpper("Post"), "/v2/store/order", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-server-required/go/api_store_service.go b/samples/server/petstore/go-server-required/go/api_store_service.go index 3c91040fa9f..4e3bb1456bd 100644 --- a/samples/server/petstore/go-server-required/go/api_store_service.go +++ b/samples/server/petstore/go-server-required/go/api_store_service.go @@ -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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, map[string]int32{}), nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, Order{}), nil + // TODO: Uncomment the next line to return response Response(200, Order{}) or use other options such as http.Ok ... + // return Response(200, Order{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") } diff --git a/samples/server/petstore/go-server-required/go/api_user.go b/samples/server/petstore/go-server-required/go/api_user.go index a48ab1c454a..e98906d31ab 100644 --- a/samples/server/petstore/go-server-required/go/api_user.go +++ b/samples/server/petstore/go-server-required/go/api_user.go @@ -49,51 +49,43 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { // Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { - return Routes{ - { - "CreateUser", + return Routes{ + "CreateUser": Route{ strings.ToUpper("Post"), "/v2/user", c.CreateUser, }, - { - "CreateUsersWithArrayInput", + "CreateUsersWithArrayInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithArray", c.CreateUsersWithArrayInput, }, - { - "CreateUsersWithListInput", + "CreateUsersWithListInput": Route{ strings.ToUpper("Post"), "/v2/user/createWithList", c.CreateUsersWithListInput, }, - { - "DeleteUser", + "DeleteUser": Route{ strings.ToUpper("Delete"), "/v2/user/{username}", c.DeleteUser, }, - { - "GetUserByName", + "GetUserByName": Route{ strings.ToUpper("Get"), "/v2/user/{username}", c.GetUserByName, }, - { - "LoginUser", + "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", c.LoginUser, }, - { - "LogoutUser", + "LogoutUser": Route{ strings.ToUpper("Get"), "/v2/user/logout", c.LogoutUser, }, - { - "UpdateUser", + "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } // 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 EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) - } diff --git a/samples/server/petstore/go-server-required/go/api_user_service.go b/samples/server/petstore/go-server-required/go/api_user_service.go index 6ae5a6d751b..8232b520c9e 100644 --- a/samples/server/petstore/go-server-required/go/api_user_service.go +++ b/samples/server/petstore/go-server-required/go/api_user_service.go @@ -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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, User{}), nil + // TODO: Uncomment the next line to return response Response(200, User{}) or use other options such as http.Ok ... + // return Response(200, User{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(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. // 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 ... - //return Response(200, string{}), nil + // TODO: Uncomment the next line to return response Response(200, string{}) or use other options such as http.Ok ... + // return Response(200, string{}), nil - //TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... - //return Response(400, nil),nil + // 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(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. // 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 ... - //return Response(0, nil),nil + // 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(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. // 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 ... - //return Response(400, nil),nil + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil - //TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - //return Response(404, nil),nil + // 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(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } diff --git a/samples/server/petstore/go-server-required/go/impl.go b/samples/server/petstore/go-server-required/go/impl.go index 8c72e26a342..7bfb815be5e 100644 --- a/samples/server/petstore/go-server-required/go/impl.go +++ b/samples/server/petstore/go-server-required/go/impl.go @@ -9,7 +9,7 @@ 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 { Code int Headers map[string][]string diff --git a/samples/server/petstore/go-server-required/go/routers.go b/samples/server/petstore/go-server-required/go/routers.go index 5f3463d18c0..01afc3d166f 100644 --- a/samples/server/petstore/go-server-required/go/routers.go +++ b/samples/server/petstore/go-server-required/go/routers.go @@ -24,14 +24,13 @@ import ( // A Route defines the parameters for an api endpoint type Route struct { - Name string Method string Pattern string HandlerFunc http.HandlerFunc } -// Routes are a collection of defined api endpoints -type Routes []Route +// Routes is a map of defined api endpoints +type Routes map[string]Route // Router defines the required methods for retrieving api routes type Router interface { @@ -45,7 +44,7 @@ func NewRouter(routers ...Router) chi.Router { router := chi.NewRouter() router.Use(middleware.Logger) for _, api := range routers { - for _, route := range api.Routes() { + for name, route := range api.Routes() { var handler http.Handler handler = route.HandlerFunc router.Method(route.Method, route.Pattern, handler) @@ -58,11 +57,9 @@ func NewRouter(routers ...Router) chi.Router { // 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 { wHeader := w.Header() - if headers != nil { - for key, values := range headers { - for _, value := range values { - wHeader.Add(key, value) - } + for key, values := range headers { + for _, value := range values { + wHeader.Add(key, value) } } wHeader.Set("Content-Type", "application/json; charset=UTF-8")