forked from loafle/openapi-generator-original
[Go][Server] FormParams - Generic Array Type Handling (#17001)
* If a form param is an array and isn't caught in the previous checks, treat it as a slice of strings. * Add an example of a FormParam that is an array
This commit is contained in:
parent
e9507077fc
commit
291ce353ce
@ -495,7 +495,12 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
|||||||
{{/isArray}}{{/isInteger}}
|
{{/isArray}}{{/isInteger}}
|
||||||
{{^isFile}}
|
{{^isFile}}
|
||||||
{{^isLong}}
|
{{^isLong}}
|
||||||
|
{{#isArray}}
|
||||||
|
{{paramName}}Param := strings.Split(r.FormValue("{{baseName}}"), ",")
|
||||||
|
{{/isArray}}
|
||||||
|
{{^isArray}}
|
||||||
{{paramName}}Param := r.FormValue("{{baseName}}")
|
{{paramName}}Param := r.FormValue("{{baseName}}")
|
||||||
|
{{/isArray}}
|
||||||
{{/isLong}}
|
{{/isLong}}
|
||||||
{{/isFile}}
|
{{/isFile}}
|
||||||
{{/isFormParam}}
|
{{/isFormParam}}
|
||||||
|
@ -346,6 +346,11 @@ paths:
|
|||||||
additionalMetadata:
|
additionalMetadata:
|
||||||
description: Additional data to pass to server
|
description: Additional data to pass to server
|
||||||
type: string
|
type: string
|
||||||
|
extraOptionalMetadata:
|
||||||
|
description: More data to pass to server
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
file:
|
file:
|
||||||
description: file to upload
|
description: file to upload
|
||||||
type: string
|
type: string
|
||||||
|
@ -1194,6 +1194,11 @@ components:
|
|||||||
additionalMetadata:
|
additionalMetadata:
|
||||||
description: Additional data to pass to server
|
description: Additional data to pass to server
|
||||||
type: string
|
type: string
|
||||||
|
extraOptionalMetadata:
|
||||||
|
description: More data to pass to server
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
file:
|
file:
|
||||||
description: file to upload
|
description: file to upload
|
||||||
format: binary
|
format: binary
|
||||||
|
@ -76,7 +76,7 @@ type PetAPIServicer interface {
|
|||||||
GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error)
|
GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error)
|
||||||
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
||||||
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
||||||
UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error)
|
UploadFile(context.Context, int64, string, []string, *os.File) (ImplResponse, error)
|
||||||
UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error)
|
UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,6 +407,9 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
|
|
||||||
additionalMetadataParam := r.FormValue("additionalMetadata")
|
additionalMetadataParam := r.FormValue("additionalMetadata")
|
||||||
|
|
||||||
|
|
||||||
|
extraOptionalMetadataParam := strings.Split(r.FormValue("extraOptionalMetadata"), ",")
|
||||||
fileParam, err := ReadFormFileToTempFile(r, "file")
|
fileParam, err := ReadFormFileToTempFile(r, "file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||||
@ -414,7 +417,7 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result, err := c.service.UploadFile(r.Context(), petIdParam, additionalMetadataParam, fileParam)
|
result, err := c.service.UploadFile(r.Context(), petIdParam, additionalMetadataParam, extraOptionalMetadataParam, fileParam)
|
||||||
// If an error occurred, encode the error with the status code
|
// If an error occurred, encode the error with the status code
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorHandler(w, r, err, &result)
|
c.errorHandler(w, r, err, &result)
|
||||||
|
@ -173,7 +173,7 @@ func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile - uploads an image
|
// UploadFile - uploads an image
|
||||||
func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file *os.File) (ImplResponse, error) {
|
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.
|
// 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.
|
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
@ -1194,6 +1194,11 @@ components:
|
|||||||
additionalMetadata:
|
additionalMetadata:
|
||||||
description: Additional data to pass to server
|
description: Additional data to pass to server
|
||||||
type: string
|
type: string
|
||||||
|
extraOptionalMetadata:
|
||||||
|
description: More data to pass to server
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
file:
|
file:
|
||||||
description: file to upload
|
description: file to upload
|
||||||
format: binary
|
format: binary
|
||||||
|
@ -76,7 +76,7 @@ type PetAPIServicer interface {
|
|||||||
GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error)
|
GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error)
|
||||||
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
||||||
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
||||||
UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error)
|
UploadFile(context.Context, int64, string, []string, *os.File) (ImplResponse, error)
|
||||||
UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error)
|
UploadFileArrayOfFiles(context.Context, int64, string, []*os.File) (ImplResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,6 +401,9 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
|
|
||||||
additionalMetadataParam := r.FormValue("additionalMetadata")
|
additionalMetadataParam := r.FormValue("additionalMetadata")
|
||||||
|
|
||||||
|
|
||||||
|
extraOptionalMetadataParam := strings.Split(r.FormValue("extraOptionalMetadata"), ",")
|
||||||
fileParam, err := ReadFormFileToTempFile(r, "file")
|
fileParam, err := ReadFormFileToTempFile(r, "file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||||
@ -408,7 +411,7 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result, err := c.service.UploadFile(r.Context(), petIdParam, additionalMetadataParam, fileParam)
|
result, err := c.service.UploadFile(r.Context(), petIdParam, additionalMetadataParam, extraOptionalMetadataParam, fileParam)
|
||||||
// If an error occurred, encode the error with the status code
|
// If an error occurred, encode the error with the status code
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorHandler(w, r, err, &result)
|
c.errorHandler(w, r, err, &result)
|
||||||
|
@ -173,7 +173,7 @@ func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile - uploads an image
|
// UploadFile - uploads an image
|
||||||
func (s *PetAPIService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file *os.File) (ImplResponse, error) {
|
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.
|
// 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.
|
// Add api_pet_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