Skip to content

Commit d533ba9

Browse files
committed
Remove warning from logs, when set invokerPackage by additional properties for kotlin generator
Fixed #2367
1 parent 72408ae commit d533ba9

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,17 +558,35 @@ public void processOpts() {
558558
additionalProperties.remove(ADDITIONAL_ENUM_TYPE_ANNOTATIONS);
559559
}
560560

561+
// Need to remove invokerPackage prop, to disable warning in logs
562+
String addInvokerPackage = null;
563+
if (additionalProperties.containsKey(INVOKER_PACKAGE)) {
564+
addInvokerPackage = (String) additionalProperties.get(INVOKER_PACKAGE);
565+
additionalProperties.remove(INVOKER_PACKAGE);
566+
}
567+
561568
super.processOpts();
562569

563570
// Get properties
564571
if (additionalProperties.containsKey(OPT_TITLE)) {
565572
title = (String) additionalProperties.get(OPT_TITLE);
566573
}
567574

568-
if (additionalProperties.containsKey(INVOKER_PACKAGE)) {
569-
packageName = (String) additionalProperties.get(INVOKER_PACKAGE);
575+
if (addInvokerPackage != null) {
576+
packageName = addInvokerPackage;
577+
additionalProperties.put(INVOKER_PACKAGE, packageName);
578+
additionalProperties.put(PACKAGE_NAME, packageName);
579+
} else {
580+
additionalProperties.put(INVOKER_PACKAGE, packageName);
581+
additionalProperties.put(PACKAGE_NAME, packageName);
582+
}
583+
584+
if (additionalProperties.containsKey(PACKAGE_NAME)) {
585+
packageName = (String) additionalProperties.get(PACKAGE_NAME);
586+
additionalProperties.put(INVOKER_PACKAGE, packageName);
570587
} else {
571588
additionalProperties.put(INVOKER_PACKAGE, packageName);
589+
additionalProperties.put(PACKAGE_NAME, packageName);
572590
}
573591

574592
if (additionalProperties.containsKey(API_PACKAGE)) {

openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.io.BufferedReader;
3030
import java.io.BufferedWriter;
3131
import java.io.IOException;
32-
import java.io.InputStream;
3332
import java.io.InputStreamReader;
3433
import java.nio.charset.StandardCharsets;
3534
import java.nio.file.Files;
@@ -40,7 +39,6 @@
4039
import java.util.HashMap;
4140
import java.util.List;
4241
import java.util.Map;
43-
import java.util.Optional;
4442
import java.util.Properties;
4543

4644
import static io.micronaut.core.util.StringUtils.EMPTY_STRING;
@@ -350,12 +348,9 @@ private String readTemplateFromCustomPath(String customPathStr, @Nullable Visito
350348
} else if (customPathStr.startsWith(FILE_SCHEME)) {
351349
customPathStr = customPathStr.substring(FILE_SCHEME.length());
352350
} else if (customPathStr.startsWith(CLASSPATH_SCHEME)) {
351+
final var customPathStrFinal = customPathStr;
353352
var resourceLoader = new DefaultClassPathResourceLoader(getClass().getClassLoader());
354-
Optional<InputStream> inOpt = resourceLoader.getResourceAsStream(customPathStr);
355-
if (inOpt.isEmpty()) {
356-
throw new IOException("Fail to load " + customPathStr);
357-
}
358-
try (InputStream in = inOpt.get();
353+
try (var in = resourceLoader.getResourceAsStream(customPathStr).orElseThrow(() -> new IOException("Fail to load " + customPathStrFinal));
359354
var reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
360355
) {
361356
return readFile(reader);

0 commit comments

Comments
 (0)