[go-server] Fix: missing quotes for string default value (#18546)

* Update controller mustache

* Add tests to openapi doc

* Regen
This commit is contained in:
Ween Jiann
2024-05-06 14:17:44 +08:00
committed by GitHub
parent b1fac19a75
commit cefbf62060
14 changed files with 188 additions and 43 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)

View File

@@ -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.