From e152799569092a67be4c8ef13e2d03c7ed2e515f Mon Sep 17 00:00:00 2001 From: martin-mfg <2026226+martin-mfg@users.noreply.github.com> Date: Thu, 11 May 2023 10:47:42 +0200 Subject: [PATCH] [JAVA] fix "text/plain" with charset specifications (#15399) --- .../codegen/languages/JavaClientCodegen.java | 2 +- .../resources/Java/libraries/native/api.mustache | 2 +- .../org/openapitools/client/api/BodyApi.java | 8 ++++---- .../org/openapitools/client/api/FormApi.java | 2 +- .../org/openapitools/client/api/HeaderApi.java | 2 +- .../org/openapitools/client/api/PathApi.java | 2 +- .../org/openapitools/client/api/QueryApi.java | 16 ++++++++-------- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 26fbbbe4467..eed6c36afaf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -855,7 +855,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen // add extension to indicate content type is `text/plain` and the response type is `String` if (op.produces != null) { for (Map produce : op.produces) { - if ("text/plain".equalsIgnoreCase(produce.get("mediaType")) + if ("text/plain".equalsIgnoreCase(produce.get("mediaType").split(";")[0].trim()) && "String".equals(op.returnType)) { op.vendorExtensions.put("x-java-text-plain-string", true); continue; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache index f0f6960bfca..756face0ddf 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache @@ -255,7 +255,7 @@ public class {{classname}} { {{#vendorExtensions.x-java-text-plain-string}} // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java index 83a43459717..0701d23c041 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/BodyApi.java @@ -182,7 +182,7 @@ public class BodyApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -263,7 +263,7 @@ public class BodyApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -417,7 +417,7 @@ public class BodyApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -498,7 +498,7 @@ public class BodyApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/FormApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/FormApi.java index 5ea2af146b2..c6e033ec70b 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/FormApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/FormApi.java @@ -124,7 +124,7 @@ public class FormApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/HeaderApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/HeaderApi.java index 8961d5735d2..41489410a41 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/HeaderApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/HeaderApi.java @@ -124,7 +124,7 @@ public class HeaderApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java index c34fe234ac0..8e5db91279d 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/PathApi.java @@ -122,7 +122,7 @@ public class PathApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( diff --git a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java index 4ce18c3ab72..2aed49d3080 100644 --- a/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java +++ b/samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/QueryApi.java @@ -127,7 +127,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -221,7 +221,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -319,7 +319,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -413,7 +413,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -505,7 +505,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -597,7 +597,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -687,7 +687,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse( @@ -782,7 +782,7 @@ public class QueryApi { } // for plain text response if (localVarResponse.headers().map().containsKey("Content-Type") && - "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0))) { + "text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) { java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A"); String responseBodyText = s.hasNext() ? s.next() : ""; return new ApiResponse(