diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 4392dcff5df3..dcdcdee2f631 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -389,6 +389,11 @@ public Map postProcessOperationsWithModels(Map o } } + // import "reflect" package if the parameter is collectionFormat=multi + if (param.isCollectionFormatMulti) { + imports.add(createMapping("import", "reflect")); + } + // import "optionals" package if the parameter is optional if (!param.required) { if (!addedOptionalImport) { diff --git a/modules/openapi-generator/src/main/resources/go/api.mustache b/modules/openapi-generator/src/main/resources/go/api.mustache index 2b04681ac91a..a581a3be3c6c 100644 --- a/modules/openapi-generator/src/main/resources/go/api.mustache +++ b/modules/openapi-generator/src/main/resources/go/api.mustache @@ -132,11 +132,37 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams} {{#hasQueryParams}} {{#queryParams}} {{#required}} + {{#isCollectionFormatMulti}} + t:={{paramName}} + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + } + } else { + localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + } + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} localVarQueryParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + {{/isCollectionFormatMulti}} {{/required}} {{^required}} if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() { + {{#isCollectionFormatMulti}} + t:=localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value() + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + } + } else { + localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + } + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} localVarQueryParams.Add("{{baseName}}", parameterToString(localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + {{/isCollectionFormatMulti}} } {{/required}} {{/queryParams}}