From e279354f1ae8190fc20b22fc92eead60a46ae0bf Mon Sep 17 00:00:00 2001 From: "Sai Ram Varma Gadiraju -X (sagadira - XORIANT SOLUTIONS PRIVATE LIMITED at Cisco)" Date: Wed, 17 Jun 2026 14:41:11 +0530 Subject: [PATCH] ISSDK-692: Handle text/plain JSON responses in Go SDK decode() Add fallback in decode() that checks if content-type starts with 'text/plain' AND body is valid JSON, then attempts JSON deserialization for oneOf/anyOf types. This handles scenarios where Intersight gateway timeouts return JSON bodies with text/plain content-type, which previously caused 'undefined response type' errors. Also regenerates all Go and C# samples to include this fix and CSCwu08056 fix. --- .../src/main/resources/go/client.mustache | 16 ++++++++++++++++ .../client/echo_api/go-external-refs/client.go | 16 ++++++++++++++++ samples/client/echo_api/go/client.go | 16 ++++++++++++++++ .../client.go | 16 ++++++++++++++++ .../others/go/oneof-anyof-required/client.go | 16 ++++++++++++++++ .../go/oneof-discriminator-lookup/client.go | 16 ++++++++++++++++ .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- .../Client/HttpSigningConfiguration.cs | 10 ++++++++-- samples/client/petstore/go/go-petstore/client.go | 16 ++++++++++++++++ .../x-auth-id-alias/go-experimental/client.go | 16 ++++++++++++++++ .../client.go | 16 ++++++++++++++++ .../client/petstore/go/go-petstore/client.go | 16 ++++++++++++++++ 21 files changed, 248 insertions(+), 22 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index f74fc88a84c5..b9f722c8f151 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -566,6 +566,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/echo_api/go-external-refs/client.go b/samples/client/echo_api/go-external-refs/client.go index 29662b18543d..b93aa084fd6d 100644 --- a/samples/client/echo_api/go-external-refs/client.go +++ b/samples/client/echo_api/go-external-refs/client.go @@ -500,6 +500,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/echo_api/go/client.go b/samples/client/echo_api/go/client.go index 29662b18543d..b93aa084fd6d 100644 --- a/samples/client/echo_api/go/client.go +++ b/samples/client/echo_api/go/client.go @@ -500,6 +500,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go b/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go index c1d35e12a5ab..92ff2fe1baea 100644 --- a/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go +++ b/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go @@ -471,6 +471,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/others/go/oneof-anyof-required/client.go b/samples/client/others/go/oneof-anyof-required/client.go index c1d35e12a5ab..92ff2fe1baea 100644 --- a/samples/client/others/go/oneof-anyof-required/client.go +++ b/samples/client/others/go/oneof-anyof-required/client.go @@ -471,6 +471,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/others/go/oneof-discriminator-lookup/client.go b/samples/client/others/go/oneof-discriminator-lookup/client.go index c1d35e12a5ab..92ff2fe1baea 100644 --- a/samples/client/others/go/oneof-discriminator-lookup/client.go +++ b/samples/client/others/go/oneof-discriminator-lookup/client.go @@ -471,6 +471,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index f3d8d64b477b..ac2320ec96cb 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/net4.7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/net4.7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/restsharp/net4.7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/net4.7/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/net4.8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/net4.8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/restsharp/net4.8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/net4.8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/net8/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/net8/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index f3d8d64b477b..ac2320ec96cb 100644 --- a/samples/client/petstore/csharp/restsharp/net8/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/net8/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index f3d8d64b477b..ac2320ec96cb 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/net9/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/net9/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index f3d8d64b477b..ac2320ec96cb 100644 --- a/samples/client/petstore/csharp/restsharp/net9/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/net9/EnumMappings/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/restsharp/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/restsharp/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index f3d8d64b477b..ac2320ec96cb 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs index 6973f2bf6691..3218c0e06877 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs @@ -138,11 +138,17 @@ public Dictionary GetHttpSignedHeader(string basePath,string met } var httpValues = HttpUtility.ParseQueryString(string.Empty); +#if (NETCOREAPP) + // On .NET 9+, ParseQueryString already URL-encodes values. + // Skip UrlEncode to prevent double-encoding that causes signature mismatches. + string framework = RuntimeInformation.FrameworkDescription; + bool skipUrlEncode = framework.StartsWith(".NET ") && + int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9; +#endif foreach (var parameter in requestOptions.QueryParameters) { #if (NETCOREAPP) - string framework = RuntimeInformation.FrameworkDescription; - string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key); + string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key); if (parameter.Value.Count > 1) { // array foreach (var value in parameter.Value) diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index af5ee9f2f29c..6da470ba5fb9 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -506,6 +506,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go index 6a36cf12e03f..e216c43c1e2f 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go +++ b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go @@ -474,6 +474,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go index 8f8601625f13..22463f1591f4 100644 --- a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go +++ b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go @@ -486,6 +486,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index 78fd61f75fc4..75ebd53f234e 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -524,6 +524,22 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } + // Fallback: text/plain responses may carry JSON-encoded error messages + // (e.g. gateway-timeout: Content-Type: text/plain; charset=utf-8 with JSON body). + if strings.HasPrefix(contentType, "text/plain") && json.Valid(b) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") }