diff --git a/languages/golang/templates/api.mustache b/languages/golang/templates/api.mustache index a41750ee..88df1079 100644 --- a/languages/golang/templates/api.mustache +++ b/languages/golang/templates/api.mustache @@ -1,4 +1,4 @@ -{{! This template was customized to use the GenericOpenAPIError from the core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.25.0/modules/openapi-generator/src/main/resources/go/api.mustache for the original template }} +{{! This template was customized to use the GenericOpenAPIError from the core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.27.0/modules/openapi-generator/src/main/resources/go/api.mustache for the original template }} {{>partial_header}} package {{packageName}} @@ -282,11 +282,33 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class } {{#headerParams}} {{#required}} + {{#vendorExtensions.x-go-json-header}} + if jsonHeaderValue, err := parameterToJSONHeaderValue(r.{{paramName}}); err != nil { + {{! TEMPLATE CUSTOMIZATION - BEGIN - don't return http response - would require closing after each SDK API call to prevent resource leaks }} + return {{#returnType}}localVarReturnValue, {{/returnType}} reportError("failed to serialize {{{baseName}}} header: %v", err) + {{! TEMPLATE CUSTOMIZATION - END - don't return http response - would require closing after each SDK API call to prevent resource leaks }} + } else { + localVarHeaderParams["{{{baseName}}}"] = jsonHeaderValue + } + {{/vendorExtensions.x-go-json-header}} + {{^vendorExtensions.x-go-json-header}} parameterAddToHeaderOrQuery(localVarHeaderParams, "{{{baseName}}}", r.{{paramName}}, "{{style}}", "{{collectionFormat}}") + {{/vendorExtensions.x-go-json-header}} {{/required}} {{^required}} if r.{{paramName}} != nil { + {{#vendorExtensions.x-go-json-header}} + if jsonHeaderValue, err := parameterToJSONHeaderValue(r.{{paramName}}); err != nil { + {{! TEMPLATE CUSTOMIZATION - BEGIN - don't return http response - would require closing after each SDK API call to prevent resource leaks }} + return {{#returnType}}localVarReturnValue, {{/returnType}} reportError("failed to serialize {{{baseName}}} header: %v", err) + {{! TEMPLATE CUSTOMIZATION - END - don't return http response - would require closing after each SDK API call to prevent resource leaks }} + } else { + localVarHeaderParams["{{{baseName}}}"] = jsonHeaderValue + } + {{/vendorExtensions.x-go-json-header}} + {{^vendorExtensions.x-go-json-header}} parameterAddToHeaderOrQuery(localVarHeaderParams, "{{{baseName}}}", r.{{paramName}}, "{{style}}", "{{collectionFormat}}") + {{/vendorExtensions.x-go-json-header}} } {{/required}} {{/headerParams}} diff --git a/languages/golang/templates/client.mustache b/languages/golang/templates/client.mustache index e9f0ecf2..97ccbc54 100644 --- a/languages/golang/templates/client.mustache +++ b/languages/golang/templates/client.mustache @@ -1,4 +1,4 @@ -{{! This template was customized to support the custom configuration options from the core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.25.0/modules/openapi-generator/src/main/resources/go/client.mustache for the original template }} +{{! This template was customized to support the custom configuration options from the core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.27.0/modules/openapi-generator/src/main/resources/go/client.mustache for the original template }} {{>partial_header}} package {{packageName}} @@ -192,6 +192,17 @@ func parameterValueToString( obj interface{}, key string ) string { } return fmt.Sprintf("%v", dataMap[key]) } +{{#x-go-has-json-header}} + +// parameterToJSONHeaderValue encodes a content: application/json header. +func parameterToJSONHeaderValue(obj interface{}) (string, error) { + encoded, err := json.Marshal(obj) + if err != nil { + return "", err + } + return string(encoded), nil +} +{{/x-go-has-json-header}} // parameterAddToHeaderOrQuery adds the provided object to the request header or url query // supporting deep object syntax @@ -228,10 +239,14 @@ func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix stri for i:=0;i 0 { headers := http.Header{} for h, v := range headerParams { + {{#useHttpHeaderSet}} + headers.Set(h, v) + {{/useHttpHeaderSet}} + {{^useHttpHeaderSet}} headers[h] = []string{v} + {{/useHttpHeaderSet}} } localVarRequest.Header = headers } diff --git a/languages/golang/templates/configuration.mustache b/languages/golang/templates/configuration.mustache index 1ed712c9..7030fd59 100644 --- a/languages/golang/templates/configuration.mustache +++ b/languages/golang/templates/configuration.mustache @@ -1,4 +1,4 @@ -{{! This template was ENTIRELY overwritten to support the custom configuration type and options from the STACKIT SDK core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.25.0/modules/openapi-generator/src/main/resources/go/configuration.mustache for the original template }} +{{! This template was ENTIRELY overwritten to support the custom configuration type and options from the STACKIT SDK core module. See https://github.com/OpenAPITools/openapi-generator/blob/v7.27.0/modules/openapi-generator/src/main/resources/go/configuration.mustache for the original template }} {{>partial_header}} package {{packageName}} diff --git a/scripts/generate-sdk/generate-sdk.sh b/scripts/generate-sdk/generate-sdk.sh index 63ae7b7c..1a973326 100755 --- a/scripts/generate-sdk/generate-sdk.sh +++ b/scripts/generate-sdk/generate-sdk.sh @@ -68,7 +68,7 @@ case "${LANGUAGE}" in go) # When the GENERATOR_VERSION changes, migrate also the templates in templates/go # Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver - GENERATOR_VERSION="v7.25.0" + GENERATOR_VERSION="v7.27.0" ;; python) # When the GENERATOR_VERSION changes, migrate also the templates in templates/python