From 1ec832b84b3866c37397802cf7a6de1067fa89d5 Mon Sep 17 00:00:00 2001 From: Philippe Kernevez Date: Tue, 30 Dec 2025 17:51:56 +0100 Subject: [PATCH 1/2] fix: test if return type is null before using it --- .../src/main/resources/JavaSpring/apiUtil.mustache | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/apiUtil.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/apiUtil.mustache index edbc003ac0ae..eafd83316e34 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/apiUtil.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/apiUtil.mustache @@ -21,9 +21,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } From 64fec767fdc7e569f4b72a9a4feab2846f66e08a Mon Sep 17 00:00:00 2001 From: Philippe Kernevez Date: Tue, 30 Dec 2025 17:52:38 +0100 Subject: [PATCH 2/2] chore: change sample example --- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- .../main/java/org/openapitools/virtualan/api/ApiUtil.java | 8 +++++--- .../src/main/java/org/openapitools/api/ApiUtil.java | 8 +++++--- 34 files changed, 170 insertions(+), 102 deletions(-) diff --git a/samples/openapi3/client/petstore/spring-stubs-skip-default-interface/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/client/petstore/spring-stubs-skip-default-interface/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/client/petstore/spring-stubs-skip-default-interface/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/client/petstore/spring-stubs-skip-default-interface/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/springboot-3/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/springboot-3/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..44bf770ccc47 100644 --- a/samples/openapi3/server/petstore/springboot-3/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/springboot-3/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/springboot-source/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/springboot-source/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/springboot-source/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/springboot-source/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/openapi3/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/openapi3/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/openapi3/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..44bf770ccc47 100644 --- a/samples/server/petstore/springboot-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-builtin-validation/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-delegate-no-response-entity/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-delegate-no-response-entity/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-delegate-no-response-entity/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-delegate-no-response-entity/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-file-delegate-optional/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-file-delegate-optional/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..44bf770ccc47 100644 --- a/samples/server/petstore/springboot-file-delegate-optional/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-file-delegate-optional/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..44bf770ccc47 100644 --- a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-petstore-with-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-petstore-with-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..44bf770ccc47 100644 --- a/samples/server/petstore/springboot-petstore-with-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-petstore-with-api-response-examples/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-spring-provide-args/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-spring-provide-args/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-spring-provide-args/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-spring-provide-args/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/ApiUtil.java b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/ApiUtil.java index 3835718bcfd5..34bab50358d8 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/ApiUtil.java +++ b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..c03486e4081d 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/ApiUtil.java @@ -9,9 +9,11 @@ public class ApiUtil { public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); + if (res != null) { + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } } catch (IOException e) { throw new RuntimeException(e); }