diff --git a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache index 00bebd2124fa..e9c8ad023782 100644 --- a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache @@ -520,7 +520,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re {{/required}} {{^required}} {{#defaultValue}} - param := {{^isString}}{{dataType}}({{/isString}}{{defaultValue}}{{^isString}}){{/isString}} + param := {{^isString}}{{dataType}}({{/isString}}"{{defaultValue}}"{{^isString}}){{/isString}} {{paramName}}Param = {{#isNullable}}&{{/isNullable}}param {{/defaultValue}} {{/required}} diff --git a/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml index 78a7a1ec6cc5..0e249cae5d9e 100644 --- a/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml @@ -100,6 +100,21 @@ paths: - "OPTION_1" - "OPTION_2" - "OPTION_3" + - name: defaultInt + in: query + schema: + default: 1 + type: integer + - name: defaultNum + in: query + schema: + default: 1.5 + type: number + - name: defaultStr + in: query + schema: + default: default + type: string - name: status in: query description: Status values that need to be considered for filter @@ -616,9 +631,9 @@ paths: required: true schema: type: string - - name: boolean_test + - name: remember_me in: query - description: The password for login in clear text + description: Remember Me schema: type: boolean responses: @@ -731,9 +746,9 @@ paths: required: true schema: type: string - - name: boolean_test # to ensure boolean query parameter won't cause compilation errors + - name: confirmation # to ensure boolean query parameter won't cause compilation errors in: query - description: boolean query parameter + description: Confirm the deletion schema: type: boolean responses: diff --git a/samples/server/petstore/go-api-server/api/openapi.yaml b/samples/server/petstore/go-api-server/api/openapi.yaml index 65a86866857a..f309214557fe 100644 --- a/samples/server/petstore/go-api-server/api/openapi.yaml +++ b/samples/server/petstore/go-api-server/api/openapi.yaml @@ -105,6 +105,30 @@ paths: - OPTION_3 type: string style: form + - explode: true + in: query + name: defaultInt + required: false + schema: + default: 1 + type: integer + style: form + - explode: true + in: query + name: defaultNum + required: false + schema: + default: 1.5 + type: number + style: form + - explode: true + in: query + name: defaultStr + required: false + schema: + default: default + type: string + style: form - deprecated: true description: Status values that need to be considered for filter explode: false @@ -631,10 +655,10 @@ paths: schema: type: string style: form - - description: The password for login in clear text + - description: Remember Me explode: true in: query - name: boolean_test + name: remember_me required: false schema: type: boolean @@ -702,10 +726,10 @@ paths: schema: type: string style: simple - - description: boolean query parameter + - description: Confirm the deletion explode: true in: query - name: boolean_test + name: confirmation required: false schema: type: boolean diff --git a/samples/server/petstore/go-api-server/go/api.go b/samples/server/petstore/go-api-server/go/api.go index 4d4ab7fc38bd..23d5213c5a63 100644 --- a/samples/server/petstore/go-api-server/go/api.go +++ b/samples/server/petstore/go-api-server/go/api.go @@ -71,7 +71,7 @@ type PetAPIServicer interface { 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) (ImplResponse, error) + FindPetsByStatus(context.Context, []string, string, string, int32, float32, string) (ImplResponse, error) // Deprecated FindPetsByTags(context.Context, []string, time.Time, time.Time, Colour) (ImplResponse, error) GetPetById(context.Context, int64) (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 693d0043ca90..65f29e2d672a 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -244,7 +244,48 @@ func (c *PetAPIController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque inlineEnumParam = param } else { } - result, err := c.service.FindPetsByStatus(r.Context(), statusParam, inlineEnumPathParam, inlineEnumParam) + var defaultIntParam int32 + if query.Has("defaultInt") { + param, err := parseNumericParameter[int32]( + query.Get("defaultInt"), + WithParse[int32](parseInt32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + + defaultIntParam = param + } else { + var param int32 = 1 + defaultIntParam = param + } + var defaultNumParam float32 + if query.Has("defaultNum") { + param, err := parseNumericParameter[float32]( + query.Get("defaultNum"), + WithParse[float32](parseFloat32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + + defaultNumParam = param + } else { + var param float32 = 1.5 + defaultNumParam = param + } + var defaultStrParam string + if query.Has("defaultStr") { + param := query.Get("defaultStr") + + defaultStrParam = param + } else { + param := "default" + defaultStrParam = param + } + result, err := c.service.FindPetsByStatus(r.Context(), statusParam, inlineEnumPathParam, inlineEnumParam, defaultIntParam, defaultNumParam, defaultStrParam) // 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_pet_service.go b/samples/server/petstore/go-api-server/go/api_pet_service.go index f5e64cba3cbc..023ccb2ab059 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 @@ -69,7 +69,7 @@ func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, } // FindPetsByStatus - Finds Pets by status -func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string) (ImplResponse, error) { +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. 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 e7a67aab5541..73563a78389c 100644 --- a/samples/server/petstore/go-api-server/go/api_user.go +++ b/samples/server/petstore/go-api-server/go/api_user.go @@ -184,10 +184,10 @@ func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, &RequiredError{"username"}, nil) return } - var booleanTestParam bool - if query.Has("boolean_test") { + var confirmationParam bool + if query.Has("confirmation") { param, err := parseBoolParameter( - query.Get("boolean_test"), + query.Get("confirmation"), WithParse[bool](parseBool), ) if err != nil { @@ -195,10 +195,10 @@ func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { return } - booleanTestParam = param + confirmationParam = param } else { } - result, err := c.service.DeleteUser(r.Context(), usernameParam, booleanTestParam) + 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) @@ -251,10 +251,10 @@ func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, &RequiredError{Field: "password"}, nil) return } - var booleanTestParam bool - if query.Has("boolean_test") { + var rememberMeParam bool + if query.Has("remember_me") { param, err := parseBoolParameter( - query.Get("boolean_test"), + query.Get("remember_me"), WithParse[bool](parseBool), ) if err != nil { @@ -262,10 +262,10 @@ func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { return } - booleanTestParam = param + rememberMeParam = param } else { } - result, err := c.service.LoginUser(r.Context(), usernameParam, passwordParam, booleanTestParam) + result, err := c.service.LoginUser(r.Context(), usernameParam, passwordParam, rememberMeParam) // 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_user_service.go b/samples/server/petstore/go-api-server/go/api_user_service.go index e1353ffab53d..d90b01762d8b 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 @@ -61,7 +61,7 @@ func (s *UserAPIService) CreateUsersWithListInput(ctx context.Context, user []Us } // DeleteUser - Delete user -func (s *UserAPIService) DeleteUser(ctx context.Context, username string, booleanTest bool) (ImplResponse, error) { +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. @@ -92,7 +92,7 @@ func (s *UserAPIService) GetUserByName(ctx context.Context, username string) (Im } // LoginUser - Logs user into the system -func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, booleanTest bool) (ImplResponse, error) { +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. diff --git a/samples/server/petstore/go-chi-server/api/openapi.yaml b/samples/server/petstore/go-chi-server/api/openapi.yaml index 65a86866857a..f309214557fe 100644 --- a/samples/server/petstore/go-chi-server/api/openapi.yaml +++ b/samples/server/petstore/go-chi-server/api/openapi.yaml @@ -105,6 +105,30 @@ paths: - OPTION_3 type: string style: form + - explode: true + in: query + name: defaultInt + required: false + schema: + default: 1 + type: integer + style: form + - explode: true + in: query + name: defaultNum + required: false + schema: + default: 1.5 + type: number + style: form + - explode: true + in: query + name: defaultStr + required: false + schema: + default: default + type: string + style: form - deprecated: true description: Status values that need to be considered for filter explode: false @@ -631,10 +655,10 @@ paths: schema: type: string style: form - - description: The password for login in clear text + - description: Remember Me explode: true in: query - name: boolean_test + name: remember_me required: false schema: type: boolean @@ -702,10 +726,10 @@ paths: schema: type: string style: simple - - description: boolean query parameter + - description: Confirm the deletion explode: true in: query - name: boolean_test + name: confirmation required: false schema: type: boolean diff --git a/samples/server/petstore/go-chi-server/go/api.go b/samples/server/petstore/go-chi-server/go/api.go index 4d4ab7fc38bd..23d5213c5a63 100644 --- a/samples/server/petstore/go-chi-server/go/api.go +++ b/samples/server/petstore/go-chi-server/go/api.go @@ -71,7 +71,7 @@ type PetAPIServicer interface { 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) (ImplResponse, error) + FindPetsByStatus(context.Context, []string, string, string, int32, float32, string) (ImplResponse, error) // Deprecated FindPetsByTags(context.Context, []string, time.Time, time.Time, Colour) (ImplResponse, error) GetPetById(context.Context, int64) (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 038c2f2e9bfa..e66bfe1a978b 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -241,7 +241,48 @@ func (c *PetAPIController) FindPetsByStatus(w http.ResponseWriter, r *http.Reque inlineEnumParam = param } else { } - result, err := c.service.FindPetsByStatus(r.Context(), statusParam, inlineEnumPathParam, inlineEnumParam) + var defaultIntParam int32 + if query.Has("defaultInt") { + param, err := parseNumericParameter[int32]( + query.Get("defaultInt"), + WithParse[int32](parseInt32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + + defaultIntParam = param + } else { + var param int32 = 1 + defaultIntParam = param + } + var defaultNumParam float32 + if query.Has("defaultNum") { + param, err := parseNumericParameter[float32]( + query.Get("defaultNum"), + WithParse[float32](parseFloat32), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + + defaultNumParam = param + } else { + var param float32 = 1.5 + defaultNumParam = param + } + var defaultStrParam string + if query.Has("defaultStr") { + param := query.Get("defaultStr") + + defaultStrParam = param + } else { + param := "default" + defaultStrParam = param + } + result, err := c.service.FindPetsByStatus(r.Context(), statusParam, inlineEnumPathParam, inlineEnumParam, defaultIntParam, defaultNumParam, defaultStrParam) // 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_pet_service.go b/samples/server/petstore/go-chi-server/go/api_pet_service.go index f5e64cba3cbc..023ccb2ab059 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 @@ -69,7 +69,7 @@ func (s *PetAPIService) FilterPetsByCategory(ctx context.Context, gender Gender, } // FindPetsByStatus - Finds Pets by status -func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string, inlineEnumPath string, inlineEnum string) (ImplResponse, error) { +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. 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 1a53a4981f4c..1c98eddab40e 100644 --- a/samples/server/petstore/go-chi-server/go/api_user.go +++ b/samples/server/petstore/go-chi-server/go/api_user.go @@ -183,10 +183,10 @@ func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, &RequiredError{"username"}, nil) return } - var booleanTestParam bool - if query.Has("boolean_test") { + var confirmationParam bool + if query.Has("confirmation") { param, err := parseBoolParameter( - query.Get("boolean_test"), + query.Get("confirmation"), WithParse[bool](parseBool), ) if err != nil { @@ -194,10 +194,10 @@ func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) { return } - booleanTestParam = param + confirmationParam = param } else { } - result, err := c.service.DeleteUser(r.Context(), usernameParam, booleanTestParam) + 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) @@ -249,10 +249,10 @@ func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { c.errorHandler(w, r, &RequiredError{Field: "password"}, nil) return } - var booleanTestParam bool - if query.Has("boolean_test") { + var rememberMeParam bool + if query.Has("remember_me") { param, err := parseBoolParameter( - query.Get("boolean_test"), + query.Get("remember_me"), WithParse[bool](parseBool), ) if err != nil { @@ -260,10 +260,10 @@ func (c *UserAPIController) LoginUser(w http.ResponseWriter, r *http.Request) { return } - booleanTestParam = param + rememberMeParam = param } else { } - result, err := c.service.LoginUser(r.Context(), usernameParam, passwordParam, booleanTestParam) + result, err := c.service.LoginUser(r.Context(), usernameParam, passwordParam, rememberMeParam) // 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_user_service.go b/samples/server/petstore/go-chi-server/go/api_user_service.go index e1353ffab53d..d90b01762d8b 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 @@ -61,7 +61,7 @@ func (s *UserAPIService) CreateUsersWithListInput(ctx context.Context, user []Us } // DeleteUser - Delete user -func (s *UserAPIService) DeleteUser(ctx context.Context, username string, booleanTest bool) (ImplResponse, error) { +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. @@ -92,7 +92,7 @@ func (s *UserAPIService) GetUserByName(ctx context.Context, username string) (Im } // LoginUser - Logs user into the system -func (s *UserAPIService) LoginUser(ctx context.Context, username string, password string, booleanTest bool) (ImplResponse, error) { +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.