diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index 1c25a69f5dd3..27cd5b4ab0bd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -256,6 +256,10 @@ public interface CodegenConfig { void setSkipOperationExample(boolean skipOperationExample); + boolean isSkipSortingOperations(); + + void setSkipSortingOperations(boolean skipSortingOperations); + public boolean isHideGenerationTimestamp(); public void setHideGenerationTimestamp(boolean hideGenerationTimestamp); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 6e252298d08a..dbd6ee46d960 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -224,6 +224,8 @@ apiTemplateFiles are for API outputs only (controllers/handlers). @Getter @Setter protected int removeOperationIdPrefixCount = 1; protected boolean skipOperationExample; + // sort operations by default + protected boolean skipSortingOperations = false; protected final static Pattern XML_MIME_PATTERN = Pattern.compile("(?i)application\\/(.*)[+]?xml(;.*)?"); protected final static Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?"); @@ -6154,6 +6156,16 @@ public void setSkipOperationExample(boolean skipOperationExample) { this.skipOperationExample = skipOperationExample; } + @Override + public boolean isSkipSortingOperations() { + return this.skipSortingOperations; + } + + @Override + public void setSkipSortingOperations(boolean skipSortingOperations) { + this.skipSortingOperations = skipSortingOperations; + } + @Override public boolean isHideGenerationTimestamp() { return hideGenerationTimestamp; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index c5d220012155..04e7d06df3c2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -121,6 +121,7 @@ public Generator opts(ClientOptInput opts) { this.opts = opts; this.openAPI = opts.getOpenAPI(); this.config = opts.getConfig(); + List userFiles = opts.getUserDefinedTemplates(); if (userFiles != null) { this.userDefinedTemplates = Collections.unmodifiableList(userFiles); @@ -680,7 +681,10 @@ void generateApis(List files, List allOperations, List ops = paths.get(tag); - ops.sort((one, another) -> ObjectUtils.compare(one.operationId, another.operationId)); + if(!this.config.isSkipSortingOperations()) { + // sort operations by operationId + ops.sort((one, another) -> ObjectUtils.compare(one.operationId, another.operationId)); + } OperationsMap operation = processOperations(config, tag, ops, allModels); URL url = URLPathUtils.getServerURL(openAPI, config.serverVariableOverrides()); operation.put("basePath", basePath); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java index d38c62e5b2b5..1e8012916759 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java @@ -66,6 +66,9 @@ public class GoServerCodegen extends AbstractGoCodegen { public GoServerCodegen() { super(); + // skip sorting of operations to preserve the order found in the OpenAPI spec file + super.setSkipSortingOperations(true); + modifyFeatureSet(features -> features .includeDocumentationFeatures(DocumentationFeature.Readme) .wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML)) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/goserver/GoServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/goserver/GoServerCodegenTest.java new file mode 100644 index 000000000000..f573a8ef0f5a --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/goserver/GoServerCodegenTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * Copyright 2018 SmartBear Software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openapitools.codegen.goserver; + +import org.openapitools.codegen.DefaultGenerator; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.config.CodegenConfigurator; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +public class GoServerCodegenTest { + + @Test + public void verifyGoMod() throws IOException { + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = createDefaultCodegenConfigurator(output) + .setInputSpec("src/test/resources/3_0/go-server/route-order.yaml"); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileExists(Paths.get(output + "/go.mod")); + TestUtils.assertFileContains(Paths.get(output + "/go.mod"), + "module github.com/my-user/my-repo"); + TestUtils.assertFileContains(Paths.get(output + "/go.mod"), + "require github.com/gorilla/mux v1.8.0"); + } + + @Test + public void verifyOrder() throws IOException { + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = createDefaultCodegenConfigurator(output) + .setInputSpec("src/test/resources/3_0/go-server/route-order.yaml"); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileExists(Paths.get(output + "/go/routers.go")); + TestUtils.assertFileContains(Paths.get(output + "/go/routers.go"), + "type Routes map[string]Route"); + + TestUtils.assertFileExists(Paths.get(output + "/go/api_dev.go")); + // verify /getPath/latest is first route + Assert.assertEquals(Files.readAllLines(Paths.get(output + "/go/api_dev.go")).get(52), "\t\t\"GetLatest\": Route{"); + // verify /getPath/{id} is second route + Assert.assertEquals(Files.readAllLines(Paths.get(output + "/go/api_dev.go")).get(57), "\t\t\"GetById\": Route{"); + + } + + private static CodegenConfigurator createDefaultCodegenConfigurator(File output) { + return new CodegenConfigurator() + .setGeneratorName("go-server") + .setGitUserId("my-user") + .setGitRepoId("my-repo") + .setPackageName("mypackage") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + } + +} diff --git a/modules/openapi-generator/src/test/resources/3_0/go-server/route-order.yaml b/modules/openapi-generator/src/test/resources/3_0/go-server/route-order.yaml new file mode 100644 index 000000000000..fcaf8f39d55c --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/go-server/route-order.yaml @@ -0,0 +1,33 @@ +openapi: 3.0.0 + +info: + version: 1.0.0 + title: Simple no path and body param spec + +paths: + /getPath/latest: + get: + tags: + - dev + summary: summary + description: description + operationId: getLatest + responses: + '204': + description: successful operation + /getPath/{id}: + get: + tags: + - dev + summary: summary + description: description + operationId: GetById + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '204': + description: successful operation diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api.go b/samples/openapi3/server/petstore/go/go-petstore/go/api.go index 9fdfee3fcefd..6524cd7a8c23 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api.go @@ -22,24 +22,24 @@ import ( // The PetAPIRouter implementation should parse necessary information from the http request, // pass the data to a PetAPIServicer to perform the required actions, then write the service results to the http response. type PetAPIRouter interface { + UpdatePet(http.ResponseWriter, *http.Request) AddPet(http.ResponseWriter, *http.Request) - DeletePet(http.ResponseWriter, *http.Request) FindPetsByStatus(http.ResponseWriter, *http.Request) // Deprecated FindPetsByTags(http.ResponseWriter, *http.Request) GetPetById(http.ResponseWriter, *http.Request) - UpdatePet(http.ResponseWriter, *http.Request) UpdatePetWithForm(http.ResponseWriter, *http.Request) + DeletePet(http.ResponseWriter, *http.Request) UploadFile(http.ResponseWriter, *http.Request) } // StoreAPIRouter defines the required methods for binding the api requests to a responses for the StoreAPI // The StoreAPIRouter implementation should parse necessary information from the http request, // pass the data to a StoreAPIServicer to perform the required actions, then write the service results to the http response. type StoreAPIRouter interface { - DeleteOrder(http.ResponseWriter, *http.Request) GetInventory(http.ResponseWriter, *http.Request) - GetOrderById(http.ResponseWriter, *http.Request) PlaceOrder(http.ResponseWriter, *http.Request) + GetOrderById(http.ResponseWriter, *http.Request) + DeleteOrder(http.ResponseWriter, *http.Request) } // UserAPIRouter defines the required methods for binding the api requests to a responses for the UserAPI // The UserAPIRouter implementation should parse necessary information from the http request, @@ -48,11 +48,11 @@ type UserAPIRouter interface { CreateUser(http.ResponseWriter, *http.Request) CreateUsersWithArrayInput(http.ResponseWriter, *http.Request) CreateUsersWithListInput(http.ResponseWriter, *http.Request) - DeleteUser(http.ResponseWriter, *http.Request) - GetUserByName(http.ResponseWriter, *http.Request) LoginUser(http.ResponseWriter, *http.Request) LogoutUser(http.ResponseWriter, *http.Request) + GetUserByName(http.ResponseWriter, *http.Request) UpdateUser(http.ResponseWriter, *http.Request) + DeleteUser(http.ResponseWriter, *http.Request) } @@ -61,14 +61,14 @@ type UserAPIRouter interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetAPIServicer interface { + UpdatePet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error) - DeletePet(context.Context, int64, string) (ImplResponse, error) FindPetsByStatus(context.Context, []string) (ImplResponse, error) // Deprecated FindPetsByTags(context.Context, []string) (ImplResponse, error) GetPetById(context.Context, int64) (ImplResponse, error) - UpdatePet(context.Context, Pet) (ImplResponse, error) UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error) + DeletePet(context.Context, int64, string) (ImplResponse, error) UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error) } @@ -78,10 +78,10 @@ type PetAPIServicer interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreAPIServicer interface { - DeleteOrder(context.Context, string) (ImplResponse, error) GetInventory(context.Context) (ImplResponse, error) - GetOrderById(context.Context, int64) (ImplResponse, error) PlaceOrder(context.Context, Order) (ImplResponse, error) + GetOrderById(context.Context, int64) (ImplResponse, error) + DeleteOrder(context.Context, string) (ImplResponse, error) } @@ -93,9 +93,9 @@ type UserAPIServicer interface { CreateUser(context.Context, User) (ImplResponse, error) CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error) CreateUsersWithListInput(context.Context, []User) (ImplResponse, error) - DeleteUser(context.Context, string, bool) (ImplResponse, error) - GetUserByName(context.Context, string) (ImplResponse, error) LoginUser(context.Context, string, string, int32, int64, float32, float64, bool) (ImplResponse, error) LogoutUser(context.Context) (ImplResponse, error) + GetUserByName(context.Context, string) (ImplResponse, error) UpdateUser(context.Context, string, User) (ImplResponse, error) + DeleteUser(context.Context, string, bool) (ImplResponse, error) } diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_pet.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_pet.go index 5b043ad51bcd..25d09e53378b 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_pet.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_pet.go @@ -52,16 +52,16 @@ func NewPetAPIController(s PetAPIServicer, opts ...PetAPIOption) *PetAPIControll // Routes returns all the api routes for the PetAPIController func (c *PetAPIController) Routes() Routes { return Routes{ + "UpdatePet": Route{ + strings.ToUpper("Put"), + "/v2/pet", + c.UpdatePet, + }, "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - "DeletePet": Route{ - strings.ToUpper("Delete"), - "/v2/pet/{petId}", - c.DeletePet, - }, "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", @@ -77,16 +77,16 @@ func (c *PetAPIController) Routes() Routes { "/v2/pet/{petId}", c.GetPetById, }, - "UpdatePet": Route{ - strings.ToUpper("Put"), - "/v2/pet", - c.UpdatePet, - }, "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, + "DeletePet": Route{ + strings.ToUpper("Delete"), + "/v2/pet/{petId}", + c.DeletePet, + }, "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", @@ -95,8 +95,8 @@ func (c *PetAPIController) Routes() Routes { } } -// AddPet - Add a new pet to the store -func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { +// UpdatePet - Update an existing pet +func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { petParam := Pet{} d := json.NewDecoder(r.Body) d.DisallowUnknownFields() @@ -112,7 +112,7 @@ func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, err, nil) return } - result, err := c.service.AddPet(r.Context(), petParam) + result, err := c.service.UpdatePet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -122,18 +122,24 @@ func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// DeletePet - Deletes a pet -func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { - petIdParam, err := parseNumericParameter[int64]( - chi.URLParam(r, "petId"), - WithRequire[int64](parseInt64), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) +// AddPet - Add a new pet to the store +func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { + petParam := Pet{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&petParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - apiKeyParam := r.Header.Get("api_key") - result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) + if err := AssertPetRequired(petParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + if err := AssertPetConstraints(petParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.AddPet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -206,24 +212,27 @@ func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePet - Update an existing pet -func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { - petParam := Pet{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&petParam); err != nil { +// UpdatePetWithForm - Updates a pet in the store with form data +func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - if err := AssertPetRequired(petParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertPetConstraints(petParam); err != nil { - c.errorHandler(w, r, err, nil) + petIdParam, err := parseNumericParameter[int64]( + chi.URLParam(r, "petId"), + WithRequire[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - result, err := c.service.UpdatePet(r.Context(), petParam) + + + nameParam := r.FormValue("name") + + + statusParam := r.FormValue("status") + result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -233,12 +242,8 @@ func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePetWithForm - Updates a pet in the store with form data -func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { - if err := r.ParseForm(); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } +// DeletePet - Deletes a pet +func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { petIdParam, err := parseNumericParameter[int64]( chi.URLParam(r, "petId"), WithRequire[int64](parseInt64), @@ -247,13 +252,8 @@ func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - - - nameParam := r.FormValue("name") - - - statusParam := r.FormValue("status") - result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) + apiKeyParam := r.Header.Get("api_key") + result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_pet_service.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_pet_service.go index cea78ae519a5..b7730e3980ec 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_pet_service.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_pet_service.go @@ -28,29 +28,38 @@ func NewPetAPIService() *PetAPIService { return &PetAPIService{} } -// AddPet - Add a new pet to the store -func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, error) { - // TODO - update AddPet with the required logic for this service method. +// UpdatePet - Update an existing pet +func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { + // 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(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(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") + return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented") } -// DeletePet - Deletes a pet -func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { - // TODO - update DeletePet with the required logic for this service method. +// AddPet - Add a new pet to the store +func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, error) { + // 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(400, {}) or use other options such as http.Ok ... - // return Response(400, nil),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 - return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") + // 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") } // FindPetsByStatus - Finds Pets by status @@ -99,35 +108,26 @@ func (s *PetAPIService) GetPetById(ctx context.Context, petId int64) (ImplRespon return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") } -// UpdatePet - Update an existing pet -func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { - // TODO - update UpdatePet with the required logic for this service method. +// UpdatePetWithForm - Updates a pet in the store with form data +func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { + // 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(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(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 - return Response(http.StatusNotImplemented, nil), errors.New("UpdatePet method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") } -// UpdatePetWithForm - Updates a pet in the store with form data -func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { - // TODO - update UpdatePetWithForm with the required logic for this service method. +// DeletePet - Deletes a pet +func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { + // 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(405, {}) or use other options such as http.Ok ... - // return Response(405, 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("UpdatePetWithForm method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") } // UploadFile - uploads an image diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_store.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_store.go index e364efe39889..be4a6289e97a 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_store.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_store.go @@ -51,37 +51,32 @@ func NewStoreAPIController(s StoreAPIServicer, opts ...StoreAPIOption) *StoreAPI // Routes returns all the api routes for the StoreAPIController func (c *StoreAPIController) Routes() Routes { return Routes{ - "DeleteOrder": Route{ - strings.ToUpper("Delete"), - "/v2/store/order/{orderId}", - c.DeleteOrder, - }, "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, + "PlaceOrder": Route{ + strings.ToUpper("Post"), + "/v2/store/order", + c.PlaceOrder, + }, "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - "PlaceOrder": Route{ - strings.ToUpper("Post"), - "/v2/store/order", - c.PlaceOrder, + "DeleteOrder": Route{ + strings.ToUpper("Delete"), + "/v2/store/order/{orderId}", + c.DeleteOrder, }, } } -// DeleteOrder - Delete purchase order by ID -func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { - orderIdParam := chi.URLParam(r, "orderId") - if orderIdParam == "" { - c.errorHandler(w, r, &RequiredError{"orderId"}, nil) - return - } - result, err := c.service.DeleteOrder(r.Context(), orderIdParam) +// GetInventory - Returns pet inventories by status +func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { + result, err := c.service.GetInventory(r.Context()) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -91,9 +86,24 @@ func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetInventory - Returns pet inventories by status -func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { - result, err := c.service.GetInventory(r.Context()) +// PlaceOrder - Place an order for a pet +func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { + orderParam := Order{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&orderParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + if err := AssertOrderRequired(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + if err := AssertOrderConstraints(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.PlaceOrder(r.Context(), orderParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -125,24 +135,14 @@ func (c *StoreAPIController) GetOrderById(w http.ResponseWriter, r *http.Request _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// PlaceOrder - Place an order for a pet -func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { - orderParam := Order{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&orderParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertOrderRequired(orderParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertOrderConstraints(orderParam); err != nil { - c.errorHandler(w, r, err, nil) +// DeleteOrder - Delete purchase order by ID +func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { + orderIdParam := chi.URLParam(r, "orderId") + if orderIdParam == "" { + c.errorHandler(w, r, &RequiredError{"orderId"}, nil) return } - result, err := c.service.PlaceOrder(r.Context(), orderParam) + result, err := c.service.DeleteOrder(r.Context(), orderIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_store_service.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_store_service.go index 46671f7a9fd9..b42eb74efb91 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_store_service.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_store_service.go @@ -27,20 +27,6 @@ func NewStoreAPIService() *StoreAPIService { return &StoreAPIService{} } -// DeleteOrder - Delete purchase order by ID -func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { - // 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(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") -} - // GetInventory - Returns pet inventories by status func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error) { // TODO - update GetInventory with the required logic for this service method. @@ -52,6 +38,20 @@ func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") } +// PlaceOrder - Place an order for a pet +func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { + // 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(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") +} + // GetOrderById - Find purchase order by ID func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (ImplResponse, error) { // TODO - update GetOrderById with the required logic for this service method. @@ -69,16 +69,16 @@ func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (Impl return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") } -// PlaceOrder - Place an order for a pet -func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { - // TODO - update PlaceOrder with the required logic for this service method. +// DeleteOrder - Delete purchase order by ID +func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") + // 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") } diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_user.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_user.go index 1d28ab73b753..37cebbe7117d 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_user.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_user.go @@ -66,16 +66,6 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/createWithList", c.CreateUsersWithListInput, }, - "DeleteUser": Route{ - strings.ToUpper("Delete"), - "/v2/user/{username}", - c.DeleteUser, - }, - "GetUserByName": Route{ - strings.ToUpper("Get"), - "/v2/user/{username}", - c.GetUserByName, - }, "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", @@ -86,11 +76,21 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/logout", c.LogoutUser, }, + "GetUserByName": Route{ + strings.ToUpper("Get"), + "/v2/user/{username}", + c.GetUserByName, + }, "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", c.UpdateUser, }, + "DeleteUser": Route{ + strings.ToUpper("Delete"), + "/v2/user/{username}", + c.DeleteUser, + }, } } @@ -171,59 +171,6 @@ func (c *UserAPIController) CreateUsersWithListInput(w http.ResponseWriter, r *h _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// DeleteUser - Delete user -func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) - if err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - usernameParam := chi.URLParam(r, "username") - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - var booleanTestParam bool - if query.Has("boolean_test") { - param, err := parseBoolParameter( - query.Get("boolean_test"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "boolean_test", Err: err}, nil) - return - } - - booleanTestParam = param - } else { - } - result, err := c.service.DeleteUser(r.Context(), usernameParam, booleanTestParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// GetUserByName - Get user by user name -func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { - usernameParam := chi.URLParam(r, "username") - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - result, err := c.service.GetUserByName(r.Context(), usernameParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - // LoginUser - Logs user into the system func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { query, err := parseQuery(r.URL.RawQuery) @@ -341,6 +288,23 @@ func (c *UserAPIController) LogoutUser(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// GetUserByName - Get user by user name +func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { + usernameParam := chi.URLParam(r, "username") + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + result, err := c.service.GetUserByName(r.Context(), usernameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + // UpdateUser - Updated user func (c *UserAPIController) UpdateUser(w http.ResponseWriter, r *http.Request) { usernameParam := chi.URLParam(r, "username") @@ -372,3 +336,39 @@ 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) } + +// DeleteUser - Delete user +func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + usernameParam := chi.URLParam(r, "username") + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + var booleanTestParam bool + if query.Has("boolean_test") { + param, err := parseBoolParameter( + query.Get("boolean_test"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "boolean_test", Err: err}, nil) + return + } + + booleanTestParam = param + } else { + } + result, err := c.service.DeleteUser(r.Context(), usernameParam, booleanTestParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/api_user_service.go b/samples/openapi3/server/petstore/go/go-petstore/go/api_user_service.go index 4be92131dc0b..c758b0ef57ba 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/api_user_service.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/api_user_service.go @@ -60,18 +60,29 @@ func (s *UserAPIService) CreateUsersWithListInput(ctx context.Context, user []Us return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") } -// DeleteUser - Delete user -func (s *UserAPIService) DeleteUser(ctx context.Context, username string, booleanTest bool) (ImplResponse, error) { - // TODO - update DeleteUser with the required logic for this service method. +// LoginUser - Logs user into the system +func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, int32Test int32, int64Test int64, float32Test float32, float64Test float64, booleanTest bool) (ImplResponse, error) { + // 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(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 + return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") +} - return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") +// LogoutUser - Logs out current logged in user session +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 + + return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") } // GetUserByName - Get user by user name @@ -91,34 +102,23 @@ func (s *UserAPIService) GetUserByName(ctx context.Context, username string) (Im return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") } -// LoginUser - Logs user into the system -func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, int32Test int32, int64Test int64, float32Test float32, float64Test float64, booleanTest bool) (ImplResponse, error) { - // TODO - update LoginUser with the required logic for this service method. +// UpdateUser - Updated user +func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") -} - -// LogoutUser - Logs out current logged in user session -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(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } -// UpdateUser - Updated user -func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { - // TODO - update UpdateUser with the required logic for this service method. +// DeleteUser - Delete user +func (s *UserAPIService) DeleteUser(ctx context.Context, username string, booleanTest bool) (ImplResponse, error) { + // 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 ... @@ -127,5 +127,5 @@ func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user U // 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") + return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") } diff --git a/samples/server/petstore/go-api-server/go/api.go b/samples/server/petstore/go-api-server/go/api.go index 23d5213c5a63..b6f9945682d4 100644 --- a/samples/server/petstore/go-api-server/go/api.go +++ b/samples/server/petstore/go-api-server/go/api.go @@ -23,30 +23,30 @@ import ( // The PetAPIRouter implementation should parse necessary information from the http request, // pass the data to a PetAPIServicer to perform the required actions, then write the service results to the http response. type PetAPIRouter interface { + UpdatePet(http.ResponseWriter, *http.Request) AddPet(http.ResponseWriter, *http.Request) - DeletePet(http.ResponseWriter, *http.Request) - FilterPetsByCategory(http.ResponseWriter, *http.Request) FindPetsByStatus(http.ResponseWriter, *http.Request) + SearchPet(http.ResponseWriter, *http.Request) // Deprecated FindPetsByTags(http.ResponseWriter, *http.Request) + FilterPetsByCategory(http.ResponseWriter, *http.Request) GetPetById(http.ResponseWriter, *http.Request) - GetPetImageById(http.ResponseWriter, *http.Request) - GetPetsByTime(http.ResponseWriter, *http.Request) - GetPetsUsingBooleanQueryParameters(http.ResponseWriter, *http.Request) - SearchPet(http.ResponseWriter, *http.Request) - UpdatePet(http.ResponseWriter, *http.Request) UpdatePetWithForm(http.ResponseWriter, *http.Request) + DeletePet(http.ResponseWriter, *http.Request) + GetPetImageById(http.ResponseWriter, *http.Request) UploadFile(http.ResponseWriter, *http.Request) UploadFileArrayOfFiles(http.ResponseWriter, *http.Request) + GetPetsUsingBooleanQueryParameters(http.ResponseWriter, *http.Request) + GetPetsByTime(http.ResponseWriter, *http.Request) } // StoreAPIRouter defines the required methods for binding the api requests to a responses for the StoreAPI // The StoreAPIRouter implementation should parse necessary information from the http request, // pass the data to a StoreAPIServicer to perform the required actions, then write the service results to the http response. type StoreAPIRouter interface { - DeleteOrder(http.ResponseWriter, *http.Request) GetInventory(http.ResponseWriter, *http.Request) - GetOrderById(http.ResponseWriter, *http.Request) PlaceOrder(http.ResponseWriter, *http.Request) + GetOrderById(http.ResponseWriter, *http.Request) + DeleteOrder(http.ResponseWriter, *http.Request) } // UserAPIRouter defines the required methods for binding the api requests to a responses for the UserAPI // The UserAPIRouter implementation should parse necessary information from the http request, @@ -55,11 +55,11 @@ type UserAPIRouter interface { CreateUser(http.ResponseWriter, *http.Request) CreateUsersWithArrayInput(http.ResponseWriter, *http.Request) CreateUsersWithListInput(http.ResponseWriter, *http.Request) - DeleteUser(http.ResponseWriter, *http.Request) - GetUserByName(http.ResponseWriter, *http.Request) LoginUser(http.ResponseWriter, *http.Request) LogoutUser(http.ResponseWriter, *http.Request) + GetUserByName(http.ResponseWriter, *http.Request) UpdateUser(http.ResponseWriter, *http.Request) + DeleteUser(http.ResponseWriter, *http.Request) } @@ -68,21 +68,21 @@ type UserAPIRouter interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetAPIServicer interface { + UpdatePet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error) - DeletePet(context.Context, int64, string) (ImplResponse, error) - FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error) FindPetsByStatus(context.Context, []string, string, string, int32, float32, string) (ImplResponse, error) + SearchPet(context.Context, *int64, *float32, *time.Time, *bool) (ImplResponse, error) // Deprecated FindPetsByTags(context.Context, []string, time.Time, time.Time, Colour) (ImplResponse, error) + FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error) GetPetById(context.Context, int64) (ImplResponse, error) - GetPetImageById(context.Context, int64) (ImplResponse, error) - GetPetsByTime(context.Context, time.Time) (ImplResponse, error) - GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) - SearchPet(context.Context, *int64, *float32, *time.Time, *bool) (ImplResponse, error) - UpdatePet(context.Context, Pet) (ImplResponse, error) UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error) + DeletePet(context.Context, int64, string) (ImplResponse, error) + GetPetImageById(context.Context, int64) (ImplResponse, error) UploadFile(context.Context, int64, string, []string, *os.File) (ImplResponse, error) UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error) + GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) + GetPetsByTime(context.Context, time.Time) (ImplResponse, error) } @@ -91,10 +91,10 @@ type PetAPIServicer interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreAPIServicer interface { - DeleteOrder(context.Context, string) (ImplResponse, error) GetInventory(context.Context) (ImplResponse, error) - GetOrderById(context.Context, int64) (ImplResponse, error) PlaceOrder(context.Context, Order) (ImplResponse, error) + GetOrderById(context.Context, int64) (ImplResponse, error) + DeleteOrder(context.Context, string) (ImplResponse, error) } @@ -106,9 +106,9 @@ type UserAPIServicer interface { CreateUser(context.Context, User) (ImplResponse, error) CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error) CreateUsersWithListInput(context.Context, []User) (ImplResponse, error) - DeleteUser(context.Context, string, bool) (ImplResponse, error) - GetUserByName(context.Context, string) (ImplResponse, error) LoginUser(context.Context, string, string, bool) (ImplResponse, error) LogoutUser(context.Context) (ImplResponse, error) + GetUserByName(context.Context, string) (ImplResponse, error) UpdateUser(context.Context, string, User) (ImplResponse, error) + DeleteUser(context.Context, string, bool) (ImplResponse, error) } 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 8451d4cf8922..68f4fd031de0 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -53,66 +53,56 @@ func NewPetAPIController(s PetAPIServicer, opts ...PetAPIOption) *PetAPIControll // Routes returns all the api routes for the PetAPIController func (c *PetAPIController) Routes() Routes { return Routes{ + "UpdatePet": Route{ + strings.ToUpper("Put"), + "/v2/pet", + c.UpdatePet, + }, "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - "DeletePet": Route{ - strings.ToUpper("Delete"), - "/v2/pet/{petId}", - c.DeletePet, - }, - "FilterPetsByCategory": Route{ - strings.ToUpper("Get"), - "/v2/pet/filterPets/{gender}", - c.FilterPetsByCategory, - }, "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", c.FindPetsByStatus, }, + "SearchPet": Route{ + strings.ToUpper("Get"), + "/v2/pet/searchPetWithManyFilters", + c.SearchPet, + }, "FindPetsByTags": Route{ strings.ToUpper("Get"), "/v2/pet/findByTags", c.FindPetsByTags, }, + "FilterPetsByCategory": Route{ + strings.ToUpper("Get"), + "/v2/pet/filterPets/{gender}", + c.FilterPetsByCategory, + }, "GetPetById": Route{ strings.ToUpper("Get"), "/v2/pet/{petId}", c.GetPetById, }, - "GetPetImageById": Route{ - strings.ToUpper("Get"), - "/v2/pet/{petId}/uploadImage", - c.GetPetImageById, - }, - "GetPetsByTime": Route{ - strings.ToUpper("Get"), - "/v2/pets/byTime/{createdTime}", - c.GetPetsByTime, - }, - "GetPetsUsingBooleanQueryParameters": Route{ - strings.ToUpper("Get"), - "/v2/pets/boolean/parsing", - c.GetPetsUsingBooleanQueryParameters, - }, - "SearchPet": Route{ - strings.ToUpper("Get"), - "/v2/pet/searchPetWithManyFilters", - c.SearchPet, - }, - "UpdatePet": Route{ - strings.ToUpper("Put"), - "/v2/pet", - c.UpdatePet, - }, "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, + "DeletePet": Route{ + strings.ToUpper("Delete"), + "/v2/pet/{petId}", + c.DeletePet, + }, + "GetPetImageById": Route{ + strings.ToUpper("Get"), + "/v2/pet/{petId}/uploadImage", + c.GetPetImageById, + }, "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", @@ -123,11 +113,21 @@ func (c *PetAPIController) Routes() Routes { "/v2/fake/uploadImage/array of_file", c.UploadFileArrayOfFiles, }, + "GetPetsUsingBooleanQueryParameters": Route{ + strings.ToUpper("Get"), + "/v2/pets/boolean/parsing", + c.GetPetsUsingBooleanQueryParameters, + }, + "GetPetsByTime": Route{ + strings.ToUpper("Get"), + "/v2/pets/byTime/{createdTime}", + c.GetPetsByTime, + }, } } -// AddPet - Add a new pet to the store -func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { +// UpdatePet - Update an existing pet +func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { petParam := Pet{} d := json.NewDecoder(r.Body) d.DisallowUnknownFields() @@ -143,29 +143,7 @@ func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, err, nil) return } - result, err := c.service.AddPet(r.Context(), petParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// DeletePet - Deletes a pet -func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - petIdParam, err := parseNumericParameter[int64]( - params["petId"], - WithRequire[int64](parseInt64), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) - return - } - apiKeyParam := r.Header.Get("api_key") - result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) + result, err := c.service.UpdatePet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -175,42 +153,24 @@ func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// FilterPetsByCategory - Finds Pets -func (c *PetAPIController) FilterPetsByCategory(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - query, err := parseQuery(r.URL.RawQuery) - if err != nil { +// AddPet - Add a new pet to the store +func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { + petParam := Pet{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&petParam); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - genderParam, err := NewGenderFromValue(params["gender"]) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "gender", Err: err}, nil) + if err := AssertPetRequired(petParam); err != nil { + c.errorHandler(w, r, err, nil) return } - var speciesParam Species - if query.Has("species") { - param := Species(query.Get("species")) - - speciesParam = param - } else { - c.errorHandler(w, r, &RequiredError{Field: "species"}, nil) + if err := AssertPetConstraints(petParam); err != nil { + c.errorHandler(w, r, err, nil) return } - var notSpeciesParam []Species - if query.Has("notSpecies") { - paramSplits := strings.Split(query.Get("notSpecies"), ",") - notSpeciesParam = make([]Species, 0, len(paramSplits)) - for _, param := range paramSplits { - paramEnum, err := NewSpeciesFromValue(param) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "notSpecies", Err: err}, nil) - return - } - notSpeciesParam = append(notSpeciesParam, paramEnum) - } - } - result, err := c.service.FilterPetsByCategory(r.Context(), genderParam, speciesParam, notSpeciesParam) + result, err := c.service.AddPet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -295,6 +255,76 @@ func (c *PetAPIController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// SearchPet - Search Pets by filters +func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + var ageParam *int64 + if query.Has("age") { + param, err := parseNumericParameter[int64]( + query.Get("age"), + WithParse[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "age", Err: err}, nil) + return + } + + ageParam = ¶m + } else { + } + var priceParam *float32 + if query.Has("price") { + param, err := parseNumericParameter[float32]( + query.Get("price"), + WithParse[float32](parseFloat32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "price", Err: err}, nil) + return + } + + priceParam = ¶m + } else { + } + var bornAfterParam *time.Time + if query.Has("bornAfter"){ + param, err := parseTime(query.Get("bornAfter")) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "bornAfter", Err: err}, nil) + return + } + + bornAfterParam = ¶m + } else { + } + var oldParam *bool + if query.Has("old") { + param, err := parseBoolParameter( + query.Get("old"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "old", Err: err}, nil) + return + } + + oldParam = ¶m + } else { + } + result, err := c.service.SearchPet(r.Context(), ageParam, priceParam, bornAfterParam, oldParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + // FindPetsByTags - Finds Pets by tags // Deprecated func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request) { @@ -348,18 +378,42 @@ func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetById - Find pet by ID -func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { +// FilterPetsByCategory - Finds Pets +func (c *PetAPIController) FilterPetsByCategory(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) - petIdParam, err := parseNumericParameter[int64]( - params["petId"], - WithRequire[int64](parseInt64), - ) + query, err := parseQuery(r.URL.RawQuery) if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) + c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - result, err := c.service.GetPetById(r.Context(), petIdParam) + genderParam, err := NewGenderFromValue(params["gender"]) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "gender", Err: err}, nil) + return + } + var speciesParam Species + if query.Has("species") { + param := Species(query.Get("species")) + + speciesParam = param + } else { + c.errorHandler(w, r, &RequiredError{Field: "species"}, nil) + return + } + var notSpeciesParam []Species + if query.Has("notSpecies") { + paramSplits := strings.Split(query.Get("notSpecies"), ",") + notSpeciesParam = make([]Species, 0, len(paramSplits)) + for _, param := range paramSplits { + paramEnum, err := NewSpeciesFromValue(param) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "notSpecies", Err: err}, nil) + return + } + notSpeciesParam = append(notSpeciesParam, paramEnum) + } + } + result, err := c.service.FilterPetsByCategory(r.Context(), genderParam, speciesParam, notSpeciesParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -369,8 +423,8 @@ func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetImageById - Returns the image for the Pet that has been previously uploaded -func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { +// GetPetById - Find pet by ID +func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) petIdParam, err := parseNumericParameter[int64]( params["petId"], @@ -380,7 +434,7 @@ func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Reques c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - result, err := c.service.GetPetImageById(r.Context(), petIdParam) + result, err := c.service.GetPetById(r.Context(), petIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -390,148 +444,28 @@ func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Reques _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetsByTime - Get the pets by time -func (c *PetAPIController) GetPetsByTime(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - createdTimeParam, err := parseTime(params["createdTime"]) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "createdTime", Err: err}, nil) - return - } - result, err := c.service.GetPetsByTime(r.Context(), createdTimeParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters -func (c *PetAPIController) GetPetsUsingBooleanQueryParameters(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) - if err != nil { +// UpdatePetWithForm - Updates a pet in the store with form data +func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - var exprParam bool - if query.Has("expr") { - param, err := parseBoolParameter( - query.Get("expr"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "expr", Err: err}, nil) - return - } - - exprParam = param - } else { - c.errorHandler(w, r, &RequiredError{Field: "expr"}, nil) - return - } - var groupingParam bool - if query.Has("grouping") { - param, err := parseBoolParameter( - query.Get("grouping"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "grouping", Err: err}, nil) - return - } - - groupingParam = param - } else { - } - var inactiveParam bool - if query.Has("inactive") { - param, err := parseBoolParameter( - query.Get("inactive"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "inactive", Err: err}, nil) - return - } - - inactiveParam = param - } else { - var param bool = false - inactiveParam = param - } - result, err := c.service.GetPetsUsingBooleanQueryParameters(r.Context(), exprParam, groupingParam, inactiveParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// SearchPet - Search Pets by filters -func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) + params := mux.Vars(r) + petIdParam, err := parseNumericParameter[int64]( + params["petId"], + WithRequire[int64](parseInt64), + ) if err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) + c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - var ageParam *int64 - if query.Has("age") { - param, err := parseNumericParameter[int64]( - query.Get("age"), - WithParse[int64](parseInt64), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "age", Err: err}, nil) - return - } - - ageParam = ¶m - } else { - } - var priceParam *float32 - if query.Has("price") { - param, err := parseNumericParameter[float32]( - query.Get("price"), - WithParse[float32](parseFloat32), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "price", Err: err}, nil) - return - } - - priceParam = ¶m - } else { - } - var bornAfterParam *time.Time - if query.Has("bornAfter"){ - param, err := parseTime(query.Get("bornAfter")) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "bornAfter", Err: err}, nil) - return - } - - bornAfterParam = ¶m - } else { - } - var oldParam *bool - if query.Has("old") { - param, err := parseBoolParameter( - query.Get("old"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "old", Err: err}, nil) - return - } - - oldParam = ¶m - } else { - } - result, err := c.service.SearchPet(r.Context(), ageParam, priceParam, bornAfterParam, oldParam) + + + nameParam := r.FormValue("name") + + + statusParam := r.FormValue("status") + result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -541,24 +475,19 @@ func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePet - Update an existing pet -func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { - petParam := Pet{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&petParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertPetRequired(petParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertPetConstraints(petParam); err != nil { - c.errorHandler(w, r, err, nil) +// DeletePet - Deletes a pet +func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + petIdParam, err := parseNumericParameter[int64]( + params["petId"], + WithRequire[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - result, err := c.service.UpdatePet(r.Context(), petParam) + apiKeyParam := r.Header.Get("api_key") + result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -568,12 +497,8 @@ func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePetWithForm - Updates a pet in the store with form data -func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { - if err := r.ParseForm(); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) petIdParam, err := parseNumericParameter[int64]( params["petId"], @@ -583,13 +508,7 @@ func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - - - nameParam := r.FormValue("name") - - - statusParam := r.FormValue("status") - result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) + result, err := c.service.GetPetImageById(r.Context(), petIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -681,3 +600,84 @@ func (c *PetAPIController) UploadFileArrayOfFiles(w http.ResponseWriter, r *http // If no error, encode the body and the result code _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } + +// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters +func (c *PetAPIController) GetPetsUsingBooleanQueryParameters(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + var exprParam bool + if query.Has("expr") { + param, err := parseBoolParameter( + query.Get("expr"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "expr", Err: err}, nil) + return + } + + exprParam = param + } else { + c.errorHandler(w, r, &RequiredError{Field: "expr"}, nil) + return + } + var groupingParam bool + if query.Has("grouping") { + param, err := parseBoolParameter( + query.Get("grouping"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "grouping", Err: err}, nil) + return + } + + groupingParam = param + } else { + } + var inactiveParam bool + if query.Has("inactive") { + param, err := parseBoolParameter( + query.Get("inactive"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "inactive", Err: err}, nil) + return + } + + inactiveParam = param + } else { + var param bool = false + inactiveParam = param + } + result, err := c.service.GetPetsUsingBooleanQueryParameters(r.Context(), exprParam, groupingParam, inactiveParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + +// GetPetsByTime - Get the pets by time +func (c *PetAPIController) GetPetsByTime(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + createdTimeParam, err := parseTime(params["createdTime"]) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "createdTime", Err: err}, nil) + return + } + result, err := c.service.GetPetsByTime(r.Context(), createdTimeParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // 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 9786bd5f71ab..4c6abe83dec7 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 @@ -29,6 +29,26 @@ func NewPetAPIService() *PetAPIService { return &PetAPIService{} } +// UpdatePet - Update an existing pet +func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { + // 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(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(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") +} + // AddPet - Add a new pet to the store func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, error) { // TODO - update AddPet with the required logic for this service method. @@ -43,34 +63,35 @@ func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, erro return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented") } -// DeletePet - Deletes a pet -func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { - // TODO - update DeletePet with the required logic for this service method. +// FindPetsByStatus - Finds Pets by status +func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string, defaultInt int32, defaultNum float32, defaultStr string) (ImplResponse, error) { + // 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(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") + return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented") } -// FilterPetsByCategory - Finds Pets -func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, species Species, notSpecies []Species) (ImplResponse, error) { - // TODO - update FilterPetsByCategory with the required logic for this service method. +// SearchPet - Search Pets by filters +func (s *PetAPIService) SearchPet(ctx context.Context, age *int64, price *float32, bornAfter *time.Time, old *bool) (ImplResponse, error) { + // TODO - update SearchPet 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(400, {}) or use other options such as http.Ok ... - // return Response(400, nil),nil - - return Response(http.StatusNotImplemented, nil), errors.New("FilterPetsByCategory method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("SearchPet method not implemented") } -// FindPetsByStatus - Finds Pets by status -func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string, defaultInt int32, defaultNum float32, defaultStr string) (ImplResponse, error) { - // TODO - update FindPetsByStatus with the required logic for this service method. +// FindPetsByTags - Finds Pets by tags +// Deprecated +func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time, colour Colour) (ImplResponse, error) { + // 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 ... @@ -79,13 +100,12 @@ func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, i // 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") + return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented") } -// FindPetsByTags - Finds Pets by tags -// Deprecated -func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time, colour Colour) (ImplResponse, error) { - // TODO - update FindPetsByTags with the required logic for this service method. +// FilterPetsByCategory - Finds Pets +func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, species Species, notSpecies []Species) (ImplResponse, error) { + // TODO - update FilterPetsByCategory 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 ... @@ -94,7 +114,7 @@ func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornA // 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") + return Response(http.StatusNotImplemented, nil), errors.New("FilterPetsByCategory method not implemented") } // GetPetById - Find pet by ID @@ -114,6 +134,28 @@ func (s *PetAPIService) GetPetById(ctx context.Context, petId int64) (ImplRespon return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") } +// UpdatePetWithForm - Updates a pet in the store with form data +func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { + // 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 + + return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") +} + +// DeletePet - Deletes a pet +func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { + // 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 + + return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") +} + // GetPetImageById - Returns the image for the Pet that has been previously uploaded func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplResponse, error) { // TODO - update GetPetImageById with the required logic for this service method. @@ -131,88 +173,46 @@ func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplR return Response(http.StatusNotImplemented, nil), errors.New("GetPetImageById method not implemented") } -// GetPetsByTime - Get the pets by time -func (s *PetAPIService) GetPetsByTime(ctx context.Context, createdTime time.Time) (ImplResponse, error) { - // TODO - update GetPetsByTime with the required logic for this service method. +// UploadFile - uploads an image +func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, extraOptionalMetadata []string, file *os.File) (ImplResponse, error) { + // 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 - return Response(http.StatusNotImplemented, nil), errors.New("GetPetsByTime method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") } -// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters -func (s *PetAPIService) GetPetsUsingBooleanQueryParameters(ctx context.Context, expr bool, grouping bool, inactive bool) (ImplResponse, error) { - // TODO - update GetPetsUsingBooleanQueryParameters with the required logic for this service method. +// UploadFileArrayOfFiles - uploads images (array of files) +func (s *PetAPIService) UploadFileArrayOfFiles(ctx context.Context, petId int64, additionalMetadata string, files []*os.File) (ImplResponse, error) { + // TODO - update UploadFileArrayOfFiles 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 - return Response(http.StatusNotImplemented, nil), errors.New("GetPetsUsingBooleanQueryParameters method not implemented") -} - -// SearchPet - Search Pets by filters -func (s *PetAPIService) SearchPet(ctx context.Context, age *int64, price *float32, bornAfter *time.Time, old *bool) (ImplResponse, error) { - // TODO - update SearchPet 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 - - return Response(http.StatusNotImplemented, nil), errors.New("SearchPet method not implemented") -} - -// UpdatePet - Update an existing pet -func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { - // 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(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(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") -} - -// UpdatePetWithForm - Updates a pet in the store with form data -func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { - // 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 - - return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UploadFileArrayOfFiles method not implemented") } -// UploadFile - uploads an image -func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, extraOptionalMetadata []string, file *os.File) (ImplResponse, error) { - // TODO - update UploadFile with the required logic for this service method. +// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters +func (s *PetAPIService) GetPetsUsingBooleanQueryParameters(ctx context.Context, expr bool, grouping bool, inactive bool) (ImplResponse, error) { + // TODO - update GetPetsUsingBooleanQueryParameters 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 - return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("GetPetsUsingBooleanQueryParameters method not implemented") } -// UploadFileArrayOfFiles - uploads images (array of files) -func (s *PetAPIService) UploadFileArrayOfFiles(ctx context.Context, petId int64, additionalMetadata string, files []*os.File) (ImplResponse, error) { - // TODO - update UploadFileArrayOfFiles with the required logic for this service method. +// GetPetsByTime - Get the pets by time +func (s *PetAPIService) GetPetsByTime(ctx context.Context, createdTime time.Time) (ImplResponse, error) { + // TODO - update GetPetsByTime 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 - return Response(http.StatusNotImplemented, nil), errors.New("UploadFileArrayOfFiles method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("GetPetsByTime 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 cc1caead0e8d..d8b75d9ec99b 100644 --- a/samples/server/petstore/go-api-server/go/api_store.go +++ b/samples/server/petstore/go-api-server/go/api_store.go @@ -51,38 +51,32 @@ func NewStoreAPIController(s StoreAPIServicer, opts ...StoreAPIOption) *StoreAPI // Routes returns all the api routes for the StoreAPIController func (c *StoreAPIController) Routes() Routes { return Routes{ - "DeleteOrder": Route{ - strings.ToUpper("Delete"), - "/v2/store/order/{orderId}", - c.DeleteOrder, - }, "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, + "PlaceOrder": Route{ + strings.ToUpper("Post"), + "/v2/store/order", + c.PlaceOrder, + }, "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - "PlaceOrder": Route{ - strings.ToUpper("Post"), - "/v2/store/order", - c.PlaceOrder, + "DeleteOrder": Route{ + strings.ToUpper("Delete"), + "/v2/store/order/{orderId}", + c.DeleteOrder, }, } } -// DeleteOrder - Delete purchase order by ID -func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - orderIdParam := params["orderId"] - if orderIdParam == "" { - c.errorHandler(w, r, &RequiredError{"orderId"}, nil) - return - } - result, err := c.service.DeleteOrder(r.Context(), orderIdParam) +// GetInventory - Returns pet inventories by status +func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { + result, err := c.service.GetInventory(r.Context()) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -92,9 +86,24 @@ func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetInventory - Returns pet inventories by status -func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { - result, err := c.service.GetInventory(r.Context()) +// PlaceOrder - Place an order for a pet +func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { + orderParam := Order{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&orderParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + if err := AssertOrderRequired(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + if err := AssertOrderConstraints(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.PlaceOrder(r.Context(), orderParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -127,24 +136,15 @@ func (c *StoreAPIController) GetOrderById(w http.ResponseWriter, r *http.Request _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// PlaceOrder - Place an order for a pet -func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { - orderParam := Order{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&orderParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertOrderRequired(orderParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertOrderConstraints(orderParam); err != nil { - c.errorHandler(w, r, err, nil) +// DeleteOrder - Delete purchase order by ID +func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + orderIdParam := params["orderId"] + if orderIdParam == "" { + c.errorHandler(w, r, &RequiredError{"orderId"}, nil) return } - result, err := c.service.PlaceOrder(r.Context(), orderParam) + result, err := c.service.DeleteOrder(r.Context(), orderIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) 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 46671f7a9fd9..b42eb74efb91 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 @@ -27,20 +27,6 @@ func NewStoreAPIService() *StoreAPIService { return &StoreAPIService{} } -// DeleteOrder - Delete purchase order by ID -func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { - // 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(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") -} - // GetInventory - Returns pet inventories by status func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error) { // TODO - update GetInventory with the required logic for this service method. @@ -52,6 +38,20 @@ func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") } +// PlaceOrder - Place an order for a pet +func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { + // 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(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") +} + // GetOrderById - Find purchase order by ID func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (ImplResponse, error) { // TODO - update GetOrderById with the required logic for this service method. @@ -69,16 +69,16 @@ func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (Impl return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") } -// PlaceOrder - Place an order for a pet -func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { - // TODO - update PlaceOrder with the required logic for this service method. +// DeleteOrder - Delete purchase order by ID +func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") + // 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") } 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 f1917fa9b785..6486c8b720f9 100644 --- a/samples/server/petstore/go-api-server/go/api_user.go +++ b/samples/server/petstore/go-api-server/go/api_user.go @@ -66,16 +66,6 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/createWithList", c.CreateUsersWithListInput, }, - "DeleteUser": Route{ - strings.ToUpper("Delete"), - "/v2/user/{username}", - c.DeleteUser, - }, - "GetUserByName": Route{ - strings.ToUpper("Get"), - "/v2/user/{username}", - c.GetUserByName, - }, "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", @@ -86,11 +76,21 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/logout", c.LogoutUser, }, + "GetUserByName": Route{ + strings.ToUpper("Get"), + "/v2/user/{username}", + c.GetUserByName, + }, "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", c.UpdateUser, }, + "DeleteUser": Route{ + strings.ToUpper("Delete"), + "/v2/user/{username}", + c.DeleteUser, + }, } } @@ -171,61 +171,6 @@ func (c *UserAPIController) CreateUsersWithListInput(w http.ResponseWriter, r *h _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// DeleteUser - Delete user -func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - query, err := parseQuery(r.URL.RawQuery) - if err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - usernameParam := params["username"] - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - var confirmationParam bool - if query.Has("confirmation") { - param, err := parseBoolParameter( - query.Get("confirmation"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "confirmation", Err: err}, nil) - return - } - - confirmationParam = param - } else { - } - result, err := c.service.DeleteUser(r.Context(), usernameParam, confirmationParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// GetUserByName - Get user by user name -func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - usernameParam := params["username"] - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - result, err := c.service.GetUserByName(r.Context(), usernameParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - // LoginUser - Logs user into the system func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { query, err := parseQuery(r.URL.RawQuery) @@ -287,6 +232,24 @@ func (c *UserAPIController) LogoutUser(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// GetUserByName - Get user by user name +func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + usernameParam := params["username"] + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + result, err := c.service.GetUserByName(r.Context(), usernameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + // UpdateUser - Updated user func (c *UserAPIController) UpdateUser(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) @@ -319,3 +282,40 @@ 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) } + +// DeleteUser - Delete user +func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + usernameParam := params["username"] + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + var confirmationParam bool + if query.Has("confirmation") { + param, err := parseBoolParameter( + query.Get("confirmation"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "confirmation", Err: err}, nil) + return + } + + confirmationParam = param + } else { + } + result, err := c.service.DeleteUser(r.Context(), usernameParam, confirmationParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // 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 62332a09da48..f117afb35ef9 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 @@ -60,18 +60,29 @@ func (s *UserAPIService) CreateUsersWithListInput(ctx context.Context, user []Us return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") } -// DeleteUser - Delete user -func (s *UserAPIService) DeleteUser(ctx context.Context, username string, confirmation bool) (ImplResponse, error) { - // TODO - update DeleteUser with the required logic for this service method. +// LoginUser - Logs user into the system +func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, rememberMe bool) (ImplResponse, error) { + // 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(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 + return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") +} - return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") +// LogoutUser - Logs out current logged in user session +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 + + return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") } // GetUserByName - Get user by user name @@ -91,34 +102,23 @@ func (s *UserAPIService) GetUserByName(ctx context.Context, username string) (Im return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") } -// LoginUser - Logs user into the system -func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, rememberMe bool) (ImplResponse, error) { - // TODO - update LoginUser with the required logic for this service method. +// UpdateUser - Updated user +func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") -} - -// LogoutUser - Logs out current logged in user session -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(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } -// UpdateUser - Updated user -func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { - // TODO - update UpdateUser with the required logic for this service method. +// DeleteUser - Delete user +func (s *UserAPIService) DeleteUser(ctx context.Context, username string, confirmation bool) (ImplResponse, error) { + // 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 ... @@ -127,5 +127,5 @@ func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user U // 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") + return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") } diff --git a/samples/server/petstore/go-chi-server/go/api.go b/samples/server/petstore/go-chi-server/go/api.go index 23d5213c5a63..b6f9945682d4 100644 --- a/samples/server/petstore/go-chi-server/go/api.go +++ b/samples/server/petstore/go-chi-server/go/api.go @@ -23,30 +23,30 @@ import ( // The PetAPIRouter implementation should parse necessary information from the http request, // pass the data to a PetAPIServicer to perform the required actions, then write the service results to the http response. type PetAPIRouter interface { + UpdatePet(http.ResponseWriter, *http.Request) AddPet(http.ResponseWriter, *http.Request) - DeletePet(http.ResponseWriter, *http.Request) - FilterPetsByCategory(http.ResponseWriter, *http.Request) FindPetsByStatus(http.ResponseWriter, *http.Request) + SearchPet(http.ResponseWriter, *http.Request) // Deprecated FindPetsByTags(http.ResponseWriter, *http.Request) + FilterPetsByCategory(http.ResponseWriter, *http.Request) GetPetById(http.ResponseWriter, *http.Request) - GetPetImageById(http.ResponseWriter, *http.Request) - GetPetsByTime(http.ResponseWriter, *http.Request) - GetPetsUsingBooleanQueryParameters(http.ResponseWriter, *http.Request) - SearchPet(http.ResponseWriter, *http.Request) - UpdatePet(http.ResponseWriter, *http.Request) UpdatePetWithForm(http.ResponseWriter, *http.Request) + DeletePet(http.ResponseWriter, *http.Request) + GetPetImageById(http.ResponseWriter, *http.Request) UploadFile(http.ResponseWriter, *http.Request) UploadFileArrayOfFiles(http.ResponseWriter, *http.Request) + GetPetsUsingBooleanQueryParameters(http.ResponseWriter, *http.Request) + GetPetsByTime(http.ResponseWriter, *http.Request) } // StoreAPIRouter defines the required methods for binding the api requests to a responses for the StoreAPI // The StoreAPIRouter implementation should parse necessary information from the http request, // pass the data to a StoreAPIServicer to perform the required actions, then write the service results to the http response. type StoreAPIRouter interface { - DeleteOrder(http.ResponseWriter, *http.Request) GetInventory(http.ResponseWriter, *http.Request) - GetOrderById(http.ResponseWriter, *http.Request) PlaceOrder(http.ResponseWriter, *http.Request) + GetOrderById(http.ResponseWriter, *http.Request) + DeleteOrder(http.ResponseWriter, *http.Request) } // UserAPIRouter defines the required methods for binding the api requests to a responses for the UserAPI // The UserAPIRouter implementation should parse necessary information from the http request, @@ -55,11 +55,11 @@ type UserAPIRouter interface { CreateUser(http.ResponseWriter, *http.Request) CreateUsersWithArrayInput(http.ResponseWriter, *http.Request) CreateUsersWithListInput(http.ResponseWriter, *http.Request) - DeleteUser(http.ResponseWriter, *http.Request) - GetUserByName(http.ResponseWriter, *http.Request) LoginUser(http.ResponseWriter, *http.Request) LogoutUser(http.ResponseWriter, *http.Request) + GetUserByName(http.ResponseWriter, *http.Request) UpdateUser(http.ResponseWriter, *http.Request) + DeleteUser(http.ResponseWriter, *http.Request) } @@ -68,21 +68,21 @@ type UserAPIRouter interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetAPIServicer interface { + UpdatePet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error) - DeletePet(context.Context, int64, string) (ImplResponse, error) - FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error) FindPetsByStatus(context.Context, []string, string, string, int32, float32, string) (ImplResponse, error) + SearchPet(context.Context, *int64, *float32, *time.Time, *bool) (ImplResponse, error) // Deprecated FindPetsByTags(context.Context, []string, time.Time, time.Time, Colour) (ImplResponse, error) + FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error) GetPetById(context.Context, int64) (ImplResponse, error) - GetPetImageById(context.Context, int64) (ImplResponse, error) - GetPetsByTime(context.Context, time.Time) (ImplResponse, error) - GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) - SearchPet(context.Context, *int64, *float32, *time.Time, *bool) (ImplResponse, error) - UpdatePet(context.Context, Pet) (ImplResponse, error) UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error) + DeletePet(context.Context, int64, string) (ImplResponse, error) + GetPetImageById(context.Context, int64) (ImplResponse, error) UploadFile(context.Context, int64, string, []string, *os.File) (ImplResponse, error) UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error) + GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) + GetPetsByTime(context.Context, time.Time) (ImplResponse, error) } @@ -91,10 +91,10 @@ type PetAPIServicer interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreAPIServicer interface { - DeleteOrder(context.Context, string) (ImplResponse, error) GetInventory(context.Context) (ImplResponse, error) - GetOrderById(context.Context, int64) (ImplResponse, error) PlaceOrder(context.Context, Order) (ImplResponse, error) + GetOrderById(context.Context, int64) (ImplResponse, error) + DeleteOrder(context.Context, string) (ImplResponse, error) } @@ -106,9 +106,9 @@ type UserAPIServicer interface { CreateUser(context.Context, User) (ImplResponse, error) CreateUsersWithArrayInput(context.Context, []User) (ImplResponse, error) CreateUsersWithListInput(context.Context, []User) (ImplResponse, error) - DeleteUser(context.Context, string, bool) (ImplResponse, error) - GetUserByName(context.Context, string) (ImplResponse, error) LoginUser(context.Context, string, string, bool) (ImplResponse, error) LogoutUser(context.Context) (ImplResponse, error) + GetUserByName(context.Context, string) (ImplResponse, error) UpdateUser(context.Context, string, User) (ImplResponse, error) + DeleteUser(context.Context, string, bool) (ImplResponse, error) } 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 a4b5448a0686..c455813ad35d 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -53,66 +53,56 @@ func NewPetAPIController(s PetAPIServicer, opts ...PetAPIOption) *PetAPIControll // Routes returns all the api routes for the PetAPIController func (c *PetAPIController) Routes() Routes { return Routes{ + "UpdatePet": Route{ + strings.ToUpper("Put"), + "/v2/pet", + c.UpdatePet, + }, "AddPet": Route{ strings.ToUpper("Post"), "/v2/pet", c.AddPet, }, - "DeletePet": Route{ - strings.ToUpper("Delete"), - "/v2/pet/{petId}", - c.DeletePet, - }, - "FilterPetsByCategory": Route{ - strings.ToUpper("Get"), - "/v2/pet/filterPets/{gender}", - c.FilterPetsByCategory, - }, "FindPetsByStatus": Route{ strings.ToUpper("Get"), "/v2/pet/findByStatus", c.FindPetsByStatus, }, + "SearchPet": Route{ + strings.ToUpper("Get"), + "/v2/pet/searchPetWithManyFilters", + c.SearchPet, + }, "FindPetsByTags": Route{ strings.ToUpper("Get"), "/v2/pet/findByTags", c.FindPetsByTags, }, + "FilterPetsByCategory": Route{ + strings.ToUpper("Get"), + "/v2/pet/filterPets/{gender}", + c.FilterPetsByCategory, + }, "GetPetById": Route{ strings.ToUpper("Get"), "/v2/pet/{petId}", c.GetPetById, }, - "GetPetImageById": Route{ - strings.ToUpper("Get"), - "/v2/pet/{petId}/uploadImage", - c.GetPetImageById, - }, - "GetPetsByTime": Route{ - strings.ToUpper("Get"), - "/v2/pets/byTime/{createdTime}", - c.GetPetsByTime, - }, - "GetPetsUsingBooleanQueryParameters": Route{ - strings.ToUpper("Get"), - "/v2/pets/boolean/parsing", - c.GetPetsUsingBooleanQueryParameters, - }, - "SearchPet": Route{ - strings.ToUpper("Get"), - "/v2/pet/searchPetWithManyFilters", - c.SearchPet, - }, - "UpdatePet": Route{ - strings.ToUpper("Put"), - "/v2/pet", - c.UpdatePet, - }, "UpdatePetWithForm": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}", c.UpdatePetWithForm, }, + "DeletePet": Route{ + strings.ToUpper("Delete"), + "/v2/pet/{petId}", + c.DeletePet, + }, + "GetPetImageById": Route{ + strings.ToUpper("Get"), + "/v2/pet/{petId}/uploadImage", + c.GetPetImageById, + }, "UploadFile": Route{ strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", @@ -123,11 +113,21 @@ func (c *PetAPIController) Routes() Routes { "/v2/fake/uploadImage/array of_file", c.UploadFileArrayOfFiles, }, + "GetPetsUsingBooleanQueryParameters": Route{ + strings.ToUpper("Get"), + "/v2/pets/boolean/parsing", + c.GetPetsUsingBooleanQueryParameters, + }, + "GetPetsByTime": Route{ + strings.ToUpper("Get"), + "/v2/pets/byTime/{createdTime}", + c.GetPetsByTime, + }, } } -// AddPet - Add a new pet to the store -func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { +// UpdatePet - Update an existing pet +func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { petParam := Pet{} d := json.NewDecoder(r.Body) d.DisallowUnknownFields() @@ -143,28 +143,7 @@ func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, err, nil) return } - result, err := c.service.AddPet(r.Context(), petParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// DeletePet - Deletes a pet -func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { - petIdParam, err := parseNumericParameter[int64]( - chi.URLParam(r, "petId"), - WithRequire[int64](parseInt64), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) - return - } - apiKeyParam := r.Header.Get("api_key") - result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) + result, err := c.service.UpdatePet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -174,41 +153,24 @@ func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// FilterPetsByCategory - Finds Pets -func (c *PetAPIController) FilterPetsByCategory(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) - if err != nil { +// AddPet - Add a new pet to the store +func (c *PetAPIController) AddPet(w http.ResponseWriter, r *http.Request) { + petParam := Pet{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&petParam); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - genderParam, err := NewGenderFromValue(chi.URLParam(r, "gender")) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "gender", Err: err}, nil) + if err := AssertPetRequired(petParam); err != nil { + c.errorHandler(w, r, err, nil) return } - var speciesParam Species - if query.Has("species") { - param := Species(query.Get("species")) - - speciesParam = param - } else { - c.errorHandler(w, r, &RequiredError{Field: "species"}, nil) + if err := AssertPetConstraints(petParam); err != nil { + c.errorHandler(w, r, err, nil) return } - var notSpeciesParam []Species - if query.Has("notSpecies") { - paramSplits := strings.Split(query.Get("notSpecies"), ",") - notSpeciesParam = make([]Species, 0, len(paramSplits)) - for _, param := range paramSplits { - paramEnum, err := NewSpeciesFromValue(param) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "notSpecies", Err: err}, nil) - return - } - notSpeciesParam = append(notSpeciesParam, paramEnum) - } - } - result, err := c.service.FilterPetsByCategory(r.Context(), genderParam, speciesParam, notSpeciesParam) + result, err := c.service.AddPet(r.Context(), petParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -292,6 +254,76 @@ func (c *PetAPIController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// SearchPet - Search Pets by filters +func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + var ageParam *int64 + if query.Has("age") { + param, err := parseNumericParameter[int64]( + query.Get("age"), + WithParse[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "age", Err: err}, nil) + return + } + + ageParam = ¶m + } else { + } + var priceParam *float32 + if query.Has("price") { + param, err := parseNumericParameter[float32]( + query.Get("price"), + WithParse[float32](parseFloat32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "price", Err: err}, nil) + return + } + + priceParam = ¶m + } else { + } + var bornAfterParam *time.Time + if query.Has("bornAfter"){ + param, err := parseTime(query.Get("bornAfter")) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "bornAfter", Err: err}, nil) + return + } + + bornAfterParam = ¶m + } else { + } + var oldParam *bool + if query.Has("old") { + param, err := parseBoolParameter( + query.Get("old"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "old", Err: err}, nil) + return + } + + oldParam = ¶m + } else { + } + result, err := c.service.SearchPet(r.Context(), ageParam, priceParam, bornAfterParam, oldParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + // FindPetsByTags - Finds Pets by tags // Deprecated func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request) { @@ -345,17 +377,41 @@ func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetById - Find pet by ID -func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { - petIdParam, err := parseNumericParameter[int64]( - chi.URLParam(r, "petId"), - WithRequire[int64](parseInt64), - ) +// FilterPetsByCategory - Finds Pets +func (c *PetAPIController) FilterPetsByCategory(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) + c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - result, err := c.service.GetPetById(r.Context(), petIdParam) + genderParam, err := NewGenderFromValue(chi.URLParam(r, "gender")) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "gender", Err: err}, nil) + return + } + var speciesParam Species + if query.Has("species") { + param := Species(query.Get("species")) + + speciesParam = param + } else { + c.errorHandler(w, r, &RequiredError{Field: "species"}, nil) + return + } + var notSpeciesParam []Species + if query.Has("notSpecies") { + paramSplits := strings.Split(query.Get("notSpecies"), ",") + notSpeciesParam = make([]Species, 0, len(paramSplits)) + for _, param := range paramSplits { + paramEnum, err := NewSpeciesFromValue(param) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "notSpecies", Err: err}, nil) + return + } + notSpeciesParam = append(notSpeciesParam, paramEnum) + } + } + result, err := c.service.FilterPetsByCategory(r.Context(), genderParam, speciesParam, notSpeciesParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -365,8 +421,8 @@ func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetImageById - Returns the image for the Pet that has been previously uploaded -func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { +// GetPetById - Find pet by ID +func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { petIdParam, err := parseNumericParameter[int64]( chi.URLParam(r, "petId"), WithRequire[int64](parseInt64), @@ -375,7 +431,7 @@ func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Reques c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - result, err := c.service.GetPetImageById(r.Context(), petIdParam) + result, err := c.service.GetPetById(r.Context(), petIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -385,147 +441,27 @@ func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Reques _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetPetsByTime - Get the pets by time -func (c *PetAPIController) GetPetsByTime(w http.ResponseWriter, r *http.Request) { - createdTimeParam, err := parseTime(chi.URLParam(r, "createdTime")) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "createdTime", Err: err}, nil) - return - } - result, err := c.service.GetPetsByTime(r.Context(), createdTimeParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters -func (c *PetAPIController) GetPetsUsingBooleanQueryParameters(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) - if err != nil { +// UpdatePetWithForm - Updates a pet in the store with form data +func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - var exprParam bool - if query.Has("expr") { - param, err := parseBoolParameter( - query.Get("expr"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "expr", Err: err}, nil) - return - } - - exprParam = param - } else { - c.errorHandler(w, r, &RequiredError{Field: "expr"}, nil) - return - } - var groupingParam bool - if query.Has("grouping") { - param, err := parseBoolParameter( - query.Get("grouping"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "grouping", Err: err}, nil) - return - } - - groupingParam = param - } else { - } - var inactiveParam bool - if query.Has("inactive") { - param, err := parseBoolParameter( - query.Get("inactive"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "inactive", Err: err}, nil) - return - } - - inactiveParam = param - } else { - var param bool = false - inactiveParam = param - } - result, err := c.service.GetPetsUsingBooleanQueryParameters(r.Context(), exprParam, groupingParam, inactiveParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// SearchPet - Search Pets by filters -func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) + petIdParam, err := parseNumericParameter[int64]( + chi.URLParam(r, "petId"), + WithRequire[int64](parseInt64), + ) if err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) + c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - var ageParam *int64 - if query.Has("age") { - param, err := parseNumericParameter[int64]( - query.Get("age"), - WithParse[int64](parseInt64), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "age", Err: err}, nil) - return - } - - ageParam = ¶m - } else { - } - var priceParam *float32 - if query.Has("price") { - param, err := parseNumericParameter[float32]( - query.Get("price"), - WithParse[float32](parseFloat32), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "price", Err: err}, nil) - return - } - - priceParam = ¶m - } else { - } - var bornAfterParam *time.Time - if query.Has("bornAfter"){ - param, err := parseTime(query.Get("bornAfter")) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "bornAfter", Err: err}, nil) - return - } - - bornAfterParam = ¶m - } else { - } - var oldParam *bool - if query.Has("old") { - param, err := parseBoolParameter( - query.Get("old"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "old", Err: err}, nil) - return - } - - oldParam = ¶m - } else { - } - result, err := c.service.SearchPet(r.Context(), ageParam, priceParam, bornAfterParam, oldParam) + + + nameParam := r.FormValue("name") + + + statusParam := r.FormValue("status") + result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -535,24 +471,18 @@ func (c *PetAPIController) SearchPet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePet - Update an existing pet -func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { - petParam := Pet{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&petParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertPetRequired(petParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertPetConstraints(petParam); err != nil { - c.errorHandler(w, r, err, nil) +// DeletePet - Deletes a pet +func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) { + petIdParam, err := parseNumericParameter[int64]( + chi.URLParam(r, "petId"), + WithRequire[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - result, err := c.service.UpdatePet(r.Context(), petParam) + apiKeyParam := r.Header.Get("api_key") + result, err := c.service.DeletePet(r.Context(), petIdParam, apiKeyParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -562,12 +492,8 @@ func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// UpdatePetWithForm - Updates a pet in the store with form data -func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { - if err := r.ParseForm(); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { petIdParam, err := parseNumericParameter[int64]( chi.URLParam(r, "petId"), WithRequire[int64](parseInt64), @@ -576,13 +502,7 @@ func (c *PetAPIController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ c.errorHandler(w, r, &ParsingError{Param: "petId", Err: err}, nil) return } - - - nameParam := r.FormValue("name") - - - statusParam := r.FormValue("status") - result, err := c.service.UpdatePetWithForm(r.Context(), petIdParam, nameParam, statusParam) + result, err := c.service.GetPetImageById(r.Context(), petIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -672,3 +592,83 @@ func (c *PetAPIController) UploadFileArrayOfFiles(w http.ResponseWriter, r *http // If no error, encode the body and the result code _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } + +// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters +func (c *PetAPIController) GetPetsUsingBooleanQueryParameters(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + var exprParam bool + if query.Has("expr") { + param, err := parseBoolParameter( + query.Get("expr"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "expr", Err: err}, nil) + return + } + + exprParam = param + } else { + c.errorHandler(w, r, &RequiredError{Field: "expr"}, nil) + return + } + var groupingParam bool + if query.Has("grouping") { + param, err := parseBoolParameter( + query.Get("grouping"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "grouping", Err: err}, nil) + return + } + + groupingParam = param + } else { + } + var inactiveParam bool + if query.Has("inactive") { + param, err := parseBoolParameter( + query.Get("inactive"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "inactive", Err: err}, nil) + return + } + + inactiveParam = param + } else { + var param bool = false + inactiveParam = param + } + result, err := c.service.GetPetsUsingBooleanQueryParameters(r.Context(), exprParam, groupingParam, inactiveParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + +// GetPetsByTime - Get the pets by time +func (c *PetAPIController) GetPetsByTime(w http.ResponseWriter, r *http.Request) { + createdTimeParam, err := parseTime(chi.URLParam(r, "createdTime")) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "createdTime", Err: err}, nil) + return + } + result, err := c.service.GetPetsByTime(r.Context(), createdTimeParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // 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 9786bd5f71ab..4c6abe83dec7 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 @@ -29,6 +29,26 @@ func NewPetAPIService() *PetAPIService { return &PetAPIService{} } +// UpdatePet - Update an existing pet +func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { + // 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(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(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") +} + // AddPet - Add a new pet to the store func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, error) { // TODO - update AddPet with the required logic for this service method. @@ -43,34 +63,35 @@ func (s *PetAPIService) AddPet(ctx context.Context, pet Pet) (ImplResponse, erro return Response(http.StatusNotImplemented, nil), errors.New("AddPet method not implemented") } -// DeletePet - Deletes a pet -func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { - // TODO - update DeletePet with the required logic for this service method. +// FindPetsByStatus - Finds Pets by status +func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string, defaultInt int32, defaultNum float32, defaultStr string) (ImplResponse, error) { + // 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(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") + return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByStatus method not implemented") } -// FilterPetsByCategory - Finds Pets -func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, species Species, notSpecies []Species) (ImplResponse, error) { - // TODO - update FilterPetsByCategory with the required logic for this service method. +// SearchPet - Search Pets by filters +func (s *PetAPIService) SearchPet(ctx context.Context, age *int64, price *float32, bornAfter *time.Time, old *bool) (ImplResponse, error) { + // TODO - update SearchPet 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(400, {}) or use other options such as http.Ok ... - // return Response(400, nil),nil - - return Response(http.StatusNotImplemented, nil), errors.New("FilterPetsByCategory method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("SearchPet method not implemented") } -// FindPetsByStatus - Finds Pets by status -func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string, defaultInt int32, defaultNum float32, defaultStr string) (ImplResponse, error) { - // TODO - update FindPetsByStatus with the required logic for this service method. +// FindPetsByTags - Finds Pets by tags +// Deprecated +func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time, colour Colour) (ImplResponse, error) { + // 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 ... @@ -79,13 +100,12 @@ func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, i // 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") + return Response(http.StatusNotImplemented, nil), errors.New("FindPetsByTags method not implemented") } -// FindPetsByTags - Finds Pets by tags -// Deprecated -func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time, colour Colour) (ImplResponse, error) { - // TODO - update FindPetsByTags with the required logic for this service method. +// FilterPetsByCategory - Finds Pets +func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, species Species, notSpecies []Species) (ImplResponse, error) { + // TODO - update FilterPetsByCategory 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 ... @@ -94,7 +114,7 @@ func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornA // 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") + return Response(http.StatusNotImplemented, nil), errors.New("FilterPetsByCategory method not implemented") } // GetPetById - Find pet by ID @@ -114,6 +134,28 @@ func (s *PetAPIService) GetPetById(ctx context.Context, petId int64) (ImplRespon return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") } +// UpdatePetWithForm - Updates a pet in the store with form data +func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { + // 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 + + return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") +} + +// DeletePet - Deletes a pet +func (s *PetAPIService) DeletePet(ctx context.Context, petId int64, apiKey string) (ImplResponse, error) { + // 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 + + return Response(http.StatusNotImplemented, nil), errors.New("DeletePet method not implemented") +} + // GetPetImageById - Returns the image for the Pet that has been previously uploaded func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplResponse, error) { // TODO - update GetPetImageById with the required logic for this service method. @@ -131,88 +173,46 @@ func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplR return Response(http.StatusNotImplemented, nil), errors.New("GetPetImageById method not implemented") } -// GetPetsByTime - Get the pets by time -func (s *PetAPIService) GetPetsByTime(ctx context.Context, createdTime time.Time) (ImplResponse, error) { - // TODO - update GetPetsByTime with the required logic for this service method. +// UploadFile - uploads an image +func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, extraOptionalMetadata []string, file *os.File) (ImplResponse, error) { + // 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 - return Response(http.StatusNotImplemented, nil), errors.New("GetPetsByTime method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") } -// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters -func (s *PetAPIService) GetPetsUsingBooleanQueryParameters(ctx context.Context, expr bool, grouping bool, inactive bool) (ImplResponse, error) { - // TODO - update GetPetsUsingBooleanQueryParameters with the required logic for this service method. +// UploadFileArrayOfFiles - uploads images (array of files) +func (s *PetAPIService) UploadFileArrayOfFiles(ctx context.Context, petId int64, additionalMetadata string, files []*os.File) (ImplResponse, error) { + // TODO - update UploadFileArrayOfFiles 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 - return Response(http.StatusNotImplemented, nil), errors.New("GetPetsUsingBooleanQueryParameters method not implemented") -} - -// SearchPet - Search Pets by filters -func (s *PetAPIService) SearchPet(ctx context.Context, age *int64, price *float32, bornAfter *time.Time, old *bool) (ImplResponse, error) { - // TODO - update SearchPet 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 - - return Response(http.StatusNotImplemented, nil), errors.New("SearchPet method not implemented") -} - -// UpdatePet - Update an existing pet -func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { - // 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(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(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") -} - -// UpdatePetWithForm - Updates a pet in the store with form data -func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name string, status string) (ImplResponse, error) { - // 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 - - return Response(http.StatusNotImplemented, nil), errors.New("UpdatePetWithForm method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UploadFileArrayOfFiles method not implemented") } -// UploadFile - uploads an image -func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, extraOptionalMetadata []string, file *os.File) (ImplResponse, error) { - // TODO - update UploadFile with the required logic for this service method. +// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters +func (s *PetAPIService) GetPetsUsingBooleanQueryParameters(ctx context.Context, expr bool, grouping bool, inactive bool) (ImplResponse, error) { + // TODO - update GetPetsUsingBooleanQueryParameters 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 - return Response(http.StatusNotImplemented, nil), errors.New("UploadFile method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("GetPetsUsingBooleanQueryParameters method not implemented") } -// UploadFileArrayOfFiles - uploads images (array of files) -func (s *PetAPIService) UploadFileArrayOfFiles(ctx context.Context, petId int64, additionalMetadata string, files []*os.File) (ImplResponse, error) { - // TODO - update UploadFileArrayOfFiles with the required logic for this service method. +// GetPetsByTime - Get the pets by time +func (s *PetAPIService) GetPetsByTime(ctx context.Context, createdTime time.Time) (ImplResponse, error) { + // TODO - update GetPetsByTime 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 - return Response(http.StatusNotImplemented, nil), errors.New("UploadFileArrayOfFiles method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("GetPetsByTime 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 e364efe39889..be4a6289e97a 100644 --- a/samples/server/petstore/go-chi-server/go/api_store.go +++ b/samples/server/petstore/go-chi-server/go/api_store.go @@ -51,37 +51,32 @@ func NewStoreAPIController(s StoreAPIServicer, opts ...StoreAPIOption) *StoreAPI // Routes returns all the api routes for the StoreAPIController func (c *StoreAPIController) Routes() Routes { return Routes{ - "DeleteOrder": Route{ - strings.ToUpper("Delete"), - "/v2/store/order/{orderId}", - c.DeleteOrder, - }, "GetInventory": Route{ strings.ToUpper("Get"), "/v2/store/inventory", c.GetInventory, }, + "PlaceOrder": Route{ + strings.ToUpper("Post"), + "/v2/store/order", + c.PlaceOrder, + }, "GetOrderById": Route{ strings.ToUpper("Get"), "/v2/store/order/{orderId}", c.GetOrderById, }, - "PlaceOrder": Route{ - strings.ToUpper("Post"), - "/v2/store/order", - c.PlaceOrder, + "DeleteOrder": Route{ + strings.ToUpper("Delete"), + "/v2/store/order/{orderId}", + c.DeleteOrder, }, } } -// DeleteOrder - Delete purchase order by ID -func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { - orderIdParam := chi.URLParam(r, "orderId") - if orderIdParam == "" { - c.errorHandler(w, r, &RequiredError{"orderId"}, nil) - return - } - result, err := c.service.DeleteOrder(r.Context(), orderIdParam) +// GetInventory - Returns pet inventories by status +func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { + result, err := c.service.GetInventory(r.Context()) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -91,9 +86,24 @@ func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// GetInventory - Returns pet inventories by status -func (c *StoreAPIController) GetInventory(w http.ResponseWriter, r *http.Request) { - result, err := c.service.GetInventory(r.Context()) +// PlaceOrder - Place an order for a pet +func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { + orderParam := Order{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&orderParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + if err := AssertOrderRequired(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + if err := AssertOrderConstraints(orderParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.PlaceOrder(r.Context(), orderParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -125,24 +135,14 @@ func (c *StoreAPIController) GetOrderById(w http.ResponseWriter, r *http.Request _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// PlaceOrder - Place an order for a pet -func (c *StoreAPIController) PlaceOrder(w http.ResponseWriter, r *http.Request) { - orderParam := Order{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&orderParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertOrderRequired(orderParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertOrderConstraints(orderParam); err != nil { - c.errorHandler(w, r, err, nil) +// DeleteOrder - Delete purchase order by ID +func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) { + orderIdParam := chi.URLParam(r, "orderId") + if orderIdParam == "" { + c.errorHandler(w, r, &RequiredError{"orderId"}, nil) return } - result, err := c.service.PlaceOrder(r.Context(), orderParam) + result, err := c.service.DeleteOrder(r.Context(), orderIdParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) 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 46671f7a9fd9..b42eb74efb91 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 @@ -27,20 +27,6 @@ func NewStoreAPIService() *StoreAPIService { return &StoreAPIService{} } -// DeleteOrder - Delete purchase order by ID -func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { - // 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(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") -} - // GetInventory - Returns pet inventories by status func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error) { // TODO - update GetInventory with the required logic for this service method. @@ -52,6 +38,20 @@ func (s *StoreAPIService) GetInventory(ctx context.Context) (ImplResponse, error return Response(http.StatusNotImplemented, nil), errors.New("GetInventory method not implemented") } +// PlaceOrder - Place an order for a pet +func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { + // 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(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") +} + // GetOrderById - Find purchase order by ID func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (ImplResponse, error) { // TODO - update GetOrderById with the required logic for this service method. @@ -69,16 +69,16 @@ func (s *StoreAPIService) GetOrderById(ctx context.Context, orderId int64) (Impl return Response(http.StatusNotImplemented, nil), errors.New("GetOrderById method not implemented") } -// PlaceOrder - Place an order for a pet -func (s *StoreAPIService) PlaceOrder(ctx context.Context, order Order) (ImplResponse, error) { - // TODO - update PlaceOrder with the required logic for this service method. +// DeleteOrder - Delete purchase order by ID +func (s *StoreAPIService) DeleteOrder(ctx context.Context, orderId string) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("PlaceOrder method not implemented") + // 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") } 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 9fd0c1c5fc75..c1ff526edc79 100644 --- a/samples/server/petstore/go-chi-server/go/api_user.go +++ b/samples/server/petstore/go-chi-server/go/api_user.go @@ -66,16 +66,6 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/createWithList", c.CreateUsersWithListInput, }, - "DeleteUser": Route{ - strings.ToUpper("Delete"), - "/v2/user/{username}", - c.DeleteUser, - }, - "GetUserByName": Route{ - strings.ToUpper("Get"), - "/v2/user/{username}", - c.GetUserByName, - }, "LoginUser": Route{ strings.ToUpper("Get"), "/v2/user/login", @@ -86,11 +76,21 @@ func (c *UserAPIController) Routes() Routes { "/v2/user/logout", c.LogoutUser, }, + "GetUserByName": Route{ + strings.ToUpper("Get"), + "/v2/user/{username}", + c.GetUserByName, + }, "UpdateUser": Route{ strings.ToUpper("Put"), "/v2/user/{username}", c.UpdateUser, }, + "DeleteUser": Route{ + strings.ToUpper("Delete"), + "/v2/user/{username}", + c.DeleteUser, + }, } } @@ -171,59 +171,6 @@ func (c *UserAPIController) CreateUsersWithListInput(w http.ResponseWriter, r *h _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } -// DeleteUser - Delete user -func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { - query, err := parseQuery(r.URL.RawQuery) - if err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - usernameParam := chi.URLParam(r, "username") - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - var confirmationParam bool - if query.Has("confirmation") { - param, err := parseBoolParameter( - query.Get("confirmation"), - WithParse[bool](parseBool), - ) - if err != nil { - c.errorHandler(w, r, &ParsingError{Param: "confirmation", Err: err}, nil) - return - } - - confirmationParam = param - } else { - } - result, err := c.service.DeleteUser(r.Context(), usernameParam, confirmationParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - -// GetUserByName - Get user by user name -func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { - usernameParam := chi.URLParam(r, "username") - if usernameParam == "" { - c.errorHandler(w, r, &RequiredError{"username"}, nil) - return - } - result, err := c.service.GetUserByName(r.Context(), usernameParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) -} - // LoginUser - Logs user into the system func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { query, err := parseQuery(r.URL.RawQuery) @@ -285,6 +232,23 @@ func (c *UserAPIController) LogoutUser(w http.ResponseWriter, r *http.Request) { _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// GetUserByName - Get user by user name +func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) { + usernameParam := chi.URLParam(r, "username") + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + result, err := c.service.GetUserByName(r.Context(), usernameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + _ = EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) +} + // UpdateUser - Updated user func (c *UserAPIController) UpdateUser(w http.ResponseWriter, r *http.Request) { usernameParam := chi.URLParam(r, "username") @@ -316,3 +280,39 @@ 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) } + +// DeleteUser - Delete user +func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { + query, err := parseQuery(r.URL.RawQuery) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + usernameParam := chi.URLParam(r, "username") + if usernameParam == "" { + c.errorHandler(w, r, &RequiredError{"username"}, nil) + return + } + var confirmationParam bool + if query.Has("confirmation") { + param, err := parseBoolParameter( + query.Get("confirmation"), + WithParse[bool](parseBool), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Param: "confirmation", Err: err}, nil) + return + } + + confirmationParam = param + } else { + } + result, err := c.service.DeleteUser(r.Context(), usernameParam, confirmationParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // 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 62332a09da48..f117afb35ef9 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 @@ -60,18 +60,29 @@ func (s *UserAPIService) CreateUsersWithListInput(ctx context.Context, user []Us return Response(http.StatusNotImplemented, nil), errors.New("CreateUsersWithListInput method not implemented") } -// DeleteUser - Delete user -func (s *UserAPIService) DeleteUser(ctx context.Context, username string, confirmation bool) (ImplResponse, error) { - // TODO - update DeleteUser with the required logic for this service method. +// LoginUser - Logs user into the system +func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, rememberMe bool) (ImplResponse, error) { + // 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(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 + return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") +} - return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") +// LogoutUser - Logs out current logged in user session +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 + + return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") } // GetUserByName - Get user by user name @@ -91,34 +102,23 @@ func (s *UserAPIService) GetUserByName(ctx context.Context, username string) (Im return Response(http.StatusNotImplemented, nil), errors.New("GetUserByName method not implemented") } -// LoginUser - Logs user into the system -func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, rememberMe bool) (ImplResponse, error) { - // TODO - update LoginUser with the required logic for this service method. +// UpdateUser - Updated user +func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { + // 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(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 - return Response(http.StatusNotImplemented, nil), errors.New("LoginUser method not implemented") -} - -// LogoutUser - Logs out current logged in user session -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(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil - return Response(http.StatusNotImplemented, nil), errors.New("LogoutUser method not implemented") + return Response(http.StatusNotImplemented, nil), errors.New("UpdateUser method not implemented") } -// UpdateUser - Updated user -func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user User) (ImplResponse, error) { - // TODO - update UpdateUser with the required logic for this service method. +// DeleteUser - Delete user +func (s *UserAPIService) DeleteUser(ctx context.Context, username string, confirmation bool) (ImplResponse, error) { + // 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 ... @@ -127,5 +127,5 @@ func (s *UserAPIService) UpdateUser(ctx context.Context, username string, user U // 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") + return Response(http.StatusNotImplemented, nil), errors.New("DeleteUser method not implemented") }