diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache index 6491013f5a84..8c3ae87ef01a 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache @@ -512,6 +512,15 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return mediaType != null && (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType) || mediaType.getSubtype().matches("^.*\\+json[;]?\\s*$")); } + /** + * Check if the given {@code String} is a Problem JSON MIME (RFC-7807). + * @param mediaType the input MediaType + * @return boolean true if the MediaType represents Problem JSON, false otherwise + */ + public boolean isProblemJsonMime(String mediaType) { + return "application/problem+json".equalsIgnoreCase(mediaType); + } + /** * Select the Accept header's value from the given accepts array: * if JSON exists in the given array, use it; @@ -526,7 +535,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { } for (String accept : accepts) { MediaType mediaType = MediaType.parseMediaType(accept); - if (isJsonMime(mediaType)) { + if (isJsonMime(mediaType) && !isProblemJsonMime(accept)) { return Collections.singletonList(mediaType); } } diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java index b8a53e2f9470..a5823b9bbb3d 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java @@ -497,6 +497,15 @@ public boolean isJsonMime(MediaType mediaType) { return mediaType != null && (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType) || mediaType.getSubtype().matches("^.*\\+json[;]?\\s*$")); } + /** + * Check if the given {@code String} is a Problem JSON MIME (RFC-7807). + * @param mediaType the input MediaType + * @return boolean true if the MediaType represents Problem JSON, false otherwise + */ + public boolean isProblemJsonMime(String mediaType) { + return "application/problem+json".equalsIgnoreCase(mediaType); + } + /** * Select the Accept header's value from the given accepts array: * if JSON exists in the given array, use it; @@ -511,7 +520,7 @@ public List selectHeaderAccept(String[] accepts) { } for (String accept : accepts) { MediaType mediaType = MediaType.parseMediaType(accept); - if (isJsonMime(mediaType)) { + if (isJsonMime(mediaType) && !isProblemJsonMime(accept)) { return Collections.singletonList(mediaType); } }