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 70ba7d9983c9..2ebd85e56fd0 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 @@ -495,7 +495,12 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re {{/isArray}}{{/isInteger}} {{^isFile}} {{^isLong}} + {{#isArray}} + {{paramName}}Param := strings.Split(r.FormValue("{{baseName}}"), ",") + {{/isArray}} + {{^isArray}} {{paramName}}Param := r.FormValue("{{baseName}}") + {{/isArray}} {{/isLong}} {{/isFile}} {{/isFormParam}} 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 9c440c06a0e2..8756d176f8c1 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 @@ -346,6 +346,11 @@ paths: additionalMetadata: description: Additional data to pass to server type: string + extraOptionalMetadata: + description: More data to pass to server + type: array + items: + type: string file: description: file to upload type: string diff --git a/samples/server/petstore/go-api-server/api/openapi.yaml b/samples/server/petstore/go-api-server/api/openapi.yaml index d1f9d6162065..ee7a4f70c132 100644 --- a/samples/server/petstore/go-api-server/api/openapi.yaml +++ b/samples/server/petstore/go-api-server/api/openapi.yaml @@ -1194,6 +1194,11 @@ components: additionalMetadata: description: Additional data to pass to server type: string + extraOptionalMetadata: + description: More data to pass to server + items: + type: string + type: array file: description: file to upload format: binary diff --git a/samples/server/petstore/go-api-server/go/api.go b/samples/server/petstore/go-api-server/go/api.go index 5f7841c33a7d..7af3533d1b80 100644 --- a/samples/server/petstore/go-api-server/go/api.go +++ b/samples/server/petstore/go-api-server/go/api.go @@ -76,7 +76,7 @@ type PetAPIServicer interface { GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) UpdatePet(context.Context, Pet) (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) } 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 7a86c2e82b0e..c40f9c8fa927 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -407,6 +407,9 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) { additionalMetadataParam := r.FormValue("additionalMetadata") + + + extraOptionalMetadataParam := strings.Split(r.FormValue("extraOptionalMetadata"), ",") fileParam, err := ReadFormFileToTempFile(r, "file") if 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 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 35f250870f7f..c8cb1a207160 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 @@ -173,7 +173,7 @@ func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name } // 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. // 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/api/openapi.yaml b/samples/server/petstore/go-chi-server/api/openapi.yaml index d1f9d6162065..ee7a4f70c132 100644 --- a/samples/server/petstore/go-chi-server/api/openapi.yaml +++ b/samples/server/petstore/go-chi-server/api/openapi.yaml @@ -1194,6 +1194,11 @@ components: additionalMetadata: description: Additional data to pass to server type: string + extraOptionalMetadata: + description: More data to pass to server + items: + type: string + type: array file: description: file to upload format: binary diff --git a/samples/server/petstore/go-chi-server/go/api.go b/samples/server/petstore/go-chi-server/go/api.go index 5f7841c33a7d..7af3533d1b80 100644 --- a/samples/server/petstore/go-chi-server/go/api.go +++ b/samples/server/petstore/go-chi-server/go/api.go @@ -76,7 +76,7 @@ type PetAPIServicer interface { GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error) UpdatePet(context.Context, Pet) (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) } 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 ddf324752be9..4b22302e1ed7 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -401,6 +401,9 @@ func (c *PetAPIController) UploadFile(w http.ResponseWriter, r *http.Request) { additionalMetadataParam := r.FormValue("additionalMetadata") + + + extraOptionalMetadataParam := strings.Split(r.FormValue("extraOptionalMetadata"), ",") fileParam, err := ReadFormFileToTempFile(r, "file") if 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 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 35f250870f7f..c8cb1a207160 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 @@ -173,7 +173,7 @@ func (s *PetAPIService) UpdatePetWithForm(ctx context.Context, petId int64, name } // 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. // Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.