From 6226dc28487f8cb0d25c8a3b69d5cb444a7df0a7 Mon Sep 17 00:00:00 2001 From: Pierre-Quentin Warlot <76955678+pqwarlot@users.noreply.github.com> Date: Wed, 27 Jul 2022 13:01:45 +0200 Subject: [PATCH] fix issue content-type default charset (#13009) --- .../libraries/apache-httpclient/ApiClient.mustache | 10 +++------- .../main/java/org/openapitools/client/ApiClient.java | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache index 2162321690a..b90bbb117b8 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache @@ -707,18 +707,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { /** * Parse content type object from header value */ - private ContentType getContentType(String headerValue) throws ApiException { - try { - return ContentType.parse(headerValue); - } catch (ParseException e) { - throw new ApiException("Could not parse content type " + headerValue); - } + private ContentType getContentType(String headerValue) { + return ContentType.getByMimeType(headerValue); } /** * Get content type of a response or null if one was not provided */ - private String getResponseMimeType(HttpResponse response) throws ApiException { + private String getResponseMimeType(HttpResponse response) { Header contentTypeHeader = response.getFirstHeader("Content-Type"); if (contentTypeHeader != null) { return getContentType(contentTypeHeader.getValue()).getMimeType(); diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java index a6e7049085a..cc89a408f81 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java @@ -662,18 +662,14 @@ public class ApiClient extends JavaTimeFormatter { /** * Parse content type object from header value */ - private ContentType getContentType(String headerValue) throws ApiException { - try { - return ContentType.parse(headerValue); - } catch (ParseException e) { - throw new ApiException("Could not parse content type " + headerValue); - } + private ContentType getContentType(String headerValue) { + return ContentType.getByMimeType(headerValue); } /** * Get content type of a response or null if one was not provided */ - private String getResponseMimeType(HttpResponse response) throws ApiException { + private String getResponseMimeType(HttpResponse response) { Header contentTypeHeader = response.getFirstHeader("Content-Type"); if (contentTypeHeader != null) { return getContentType(contentTypeHeader.getValue()).getMimeType();