From d533ba9f23d1f43d6acefac8712e44e76cb1b095 Mon Sep 17 00:00:00 2001 From: altro3 Date: Thu, 25 Sep 2025 13:31:43 +0700 Subject: [PATCH] Remove warning from logs, when set invokerPackage by additional properties for kotlin generator Fixed #2367 --- .../AbstractMicronautKotlinCodegen.java | 22 +++++++++++++++++-- .../openapi/view/OpenApiViewConfig.java | 9 ++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java index f303a8e6a3..65b714b236 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java @@ -558,6 +558,13 @@ public void processOpts() { additionalProperties.remove(ADDITIONAL_ENUM_TYPE_ANNOTATIONS); } + // Need to remove invokerPackage prop, to disable warning in logs + String addInvokerPackage = null; + if (additionalProperties.containsKey(INVOKER_PACKAGE)) { + addInvokerPackage = (String) additionalProperties.get(INVOKER_PACKAGE); + additionalProperties.remove(INVOKER_PACKAGE); + } + super.processOpts(); // Get properties @@ -565,10 +572,21 @@ public void processOpts() { title = (String) additionalProperties.get(OPT_TITLE); } - if (additionalProperties.containsKey(INVOKER_PACKAGE)) { - packageName = (String) additionalProperties.get(INVOKER_PACKAGE); + if (addInvokerPackage != null) { + packageName = addInvokerPackage; + additionalProperties.put(INVOKER_PACKAGE, packageName); + additionalProperties.put(PACKAGE_NAME, packageName); + } else { + additionalProperties.put(INVOKER_PACKAGE, packageName); + additionalProperties.put(PACKAGE_NAME, packageName); + } + + if (additionalProperties.containsKey(PACKAGE_NAME)) { + packageName = (String) additionalProperties.get(PACKAGE_NAME); + additionalProperties.put(INVOKER_PACKAGE, packageName); } else { additionalProperties.put(INVOKER_PACKAGE, packageName); + additionalProperties.put(PACKAGE_NAME, packageName); } if (additionalProperties.containsKey(API_PACKAGE)) { diff --git a/openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java b/openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java index bccba9fc89..f00bcd4103 100644 --- a/openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java +++ b/openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java @@ -29,7 +29,6 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -40,7 +39,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Properties; import static io.micronaut.core.util.StringUtils.EMPTY_STRING; @@ -350,12 +348,9 @@ private String readTemplateFromCustomPath(String customPathStr, @Nullable Visito } else if (customPathStr.startsWith(FILE_SCHEME)) { customPathStr = customPathStr.substring(FILE_SCHEME.length()); } else if (customPathStr.startsWith(CLASSPATH_SCHEME)) { + final var customPathStrFinal = customPathStr; var resourceLoader = new DefaultClassPathResourceLoader(getClass().getClassLoader()); - Optional inOpt = resourceLoader.getResourceAsStream(customPathStr); - if (inOpt.isEmpty()) { - throw new IOException("Fail to load " + customPathStr); - } - try (InputStream in = inOpt.get(); + try (var in = resourceLoader.getResourceAsStream(customPathStr).orElseThrow(() -> new IOException("Fail to load " + customPathStrFinal)); var reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)) ) { return readFile(reader);