From 3832587c1a09f0471e007541734401b7252346db Mon Sep 17 00:00:00 2001 From: atomgomba Date: Wed, 3 Dec 2025 14:51:06 +0100 Subject: [PATCH] fix(KotlinClientCodegen): store parsed bool values in additionalProperties --- .../languages/KotlinClientCodegen.java | 17 ++++--- .../kotlin/KotlinClientCodegenModelTest.java | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) mode change 100644 => 100755 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java old mode 100644 new mode 100755 index 2bd880808a3b..a4fa43f2b031 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -417,11 +417,14 @@ public void processOpts() { if (hasConflict) { LOGGER.warn("You specified RxJava versions 1 and 2 and 3 or Coroutines together, please choose one of them."); } else if (hasRx3) { - this.setUseRxJava3(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA3).toString())); + setUseRxJava3(convertPropertyToBoolean(USE_RX_JAVA3)); } else if (hasCoroutines) { - this.setUseCoroutines(Boolean.parseBoolean(additionalProperties.get(USE_COROUTINES).toString())); + setUseCoroutines(convertPropertyToBoolean(USE_COROUTINES)); } + additionalProperties.put(USE_RX_JAVA3, useRxJava3); + additionalProperties.put(USE_COROUTINES, useCoroutines); + if (!hasRx3 && !hasCoroutines) { setDoNotUseRxAndCoroutines(true); additionalProperties.put(DO_NOT_USE_RX_AND_COROUTINES, true); @@ -447,7 +450,11 @@ public void processOpts() { } if (additionalProperties.containsKey(OMIT_GRADLE_WRAPPER)) { - setOmitGradleWrapper(Boolean.parseBoolean(additionalProperties.get(OMIT_GRADLE_WRAPPER).toString())); + setOmitGradleWrapper(convertPropertyToBooleanAndWriteBack(OMIT_GRADLE_WRAPPER)); + } + + if (additionalProperties.containsKey(USE_SPRING_BOOT3)) { + convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3); } if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) { @@ -467,11 +474,11 @@ public void processOpts() { } if (additionalProperties.containsKey(GENERATE_ONEOF_ANYOF_WRAPPERS)) { - setGenerateOneOfAnyOfWrappers(Boolean.parseBoolean(additionalProperties.get(GENERATE_ONEOF_ANYOF_WRAPPERS).toString())); + setGenerateOneOfAnyOfWrappers(convertPropertyToBooleanAndWriteBack(GENERATE_ONEOF_ANYOF_WRAPPERS)); } if (additionalProperties.containsKey(FAIL_ON_UNKNOWN_PROPERTIES)) { - setFailOnUnknownProperties(Boolean.parseBoolean(additionalProperties.get(FAIL_ON_UNKNOWN_PROPERTIES).toString())); + setFailOnUnknownProperties(convertPropertyToBooleanAndWriteBack(FAIL_ON_UNKNOWN_PROPERTIES)); } else { additionalProperties.put(FAIL_ON_UNKNOWN_PROPERTIES, false); setFailOnUnknownProperties(false); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java index c4bedf76c279..fe164556ce0f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java @@ -431,6 +431,50 @@ public void testFailOnUnknownPropertiesAdditionalProperty() { configAssert.assertValue(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, codegen::isFailOnUnknownProperties, Boolean.FALSE); } + @Test + public void testBooleanAdditionalProperties() { + final KotlinClientCodegen codegen = new KotlinClientCodegen(); + + // Default to false + codegen.additionalProperties().put(KotlinClientCodegen.USE_COROUTINES, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.USE_RX_JAVA3, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.OMIT_GRADLE_WRAPPER, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.USE_SPRING_BOOT3, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS, "false"); + codegen.additionalProperties().put(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, "false"); + + codegen.processOpts(); + + // Should be false + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_COROUTINES)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_RX_JAVA3)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.OMIT_GRADLE_WRAPPER)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_SPRING_BOOT3)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS)); + Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES)); + + // Default to true + codegen.additionalProperties().put(KotlinClientCodegen.USE_COROUTINES, "true"); // these are exclusive + codegen.additionalProperties().remove(KotlinClientCodegen.USE_RX_JAVA3); // these are exclusive + codegen.additionalProperties().put(KotlinClientCodegen.OMIT_GRADLE_WRAPPER, "true"); + codegen.additionalProperties().put(KotlinClientCodegen.USE_SPRING_BOOT3, "true"); + codegen.additionalProperties().put(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY, "true"); + codegen.additionalProperties().put(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS, "true"); + codegen.additionalProperties().put(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, "true"); + + codegen.processOpts(); + + // Should be true + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_COROUTINES)); + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.OMIT_GRADLE_WRAPPER)); + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_SPRING_BOOT3)); + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY)); + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS)); + Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES)); + } + @DataProvider(name = "gsonClientLibraries") public Object[][] pathResponses() { return new Object[][]{