forked from loafle/openapi-generator-original
[go-server] Fix: missing quotes for string default value (#18546)
* Update controller mustache * Add tests to openapi doc * Regen
This commit is contained in:
parent
b1fac19a75
commit
cefbf62060
@ -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}}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user