Skip to content

Commit 8d17f66

Browse files
authored
fix(KotlinClientCodegen): store parsed bool values in additionalProperties (#22491)
1 parent 4f9f14a commit 8d17f66

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java

100644100755
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,14 @@ public void processOpts() {
417417
if (hasConflict) {
418418
LOGGER.warn("You specified RxJava versions 1 and 2 and 3 or Coroutines together, please choose one of them.");
419419
} else if (hasRx3) {
420-
this.setUseRxJava3(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA3).toString()));
420+
setUseRxJava3(convertPropertyToBoolean(USE_RX_JAVA3));
421421
} else if (hasCoroutines) {
422-
this.setUseCoroutines(Boolean.parseBoolean(additionalProperties.get(USE_COROUTINES).toString()));
422+
setUseCoroutines(convertPropertyToBoolean(USE_COROUTINES));
423423
}
424424

425+
additionalProperties.put(USE_RX_JAVA3, useRxJava3);
426+
additionalProperties.put(USE_COROUTINES, useCoroutines);
427+
425428
if (!hasRx3 && !hasCoroutines) {
426429
setDoNotUseRxAndCoroutines(true);
427430
additionalProperties.put(DO_NOT_USE_RX_AND_COROUTINES, true);
@@ -447,7 +450,11 @@ public void processOpts() {
447450
}
448451

449452
if (additionalProperties.containsKey(OMIT_GRADLE_WRAPPER)) {
450-
setOmitGradleWrapper(Boolean.parseBoolean(additionalProperties.get(OMIT_GRADLE_WRAPPER).toString()));
453+
setOmitGradleWrapper(convertPropertyToBooleanAndWriteBack(OMIT_GRADLE_WRAPPER));
454+
}
455+
456+
if (additionalProperties.containsKey(USE_SPRING_BOOT3)) {
457+
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3);
451458
}
452459

453460
if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
@@ -467,11 +474,11 @@ public void processOpts() {
467474
}
468475

469476
if (additionalProperties.containsKey(GENERATE_ONEOF_ANYOF_WRAPPERS)) {
470-
setGenerateOneOfAnyOfWrappers(Boolean.parseBoolean(additionalProperties.get(GENERATE_ONEOF_ANYOF_WRAPPERS).toString()));
477+
setGenerateOneOfAnyOfWrappers(convertPropertyToBooleanAndWriteBack(GENERATE_ONEOF_ANYOF_WRAPPERS));
471478
}
472479

473480
if (additionalProperties.containsKey(FAIL_ON_UNKNOWN_PROPERTIES)) {
474-
setFailOnUnknownProperties(Boolean.parseBoolean(additionalProperties.get(FAIL_ON_UNKNOWN_PROPERTIES).toString()));
481+
setFailOnUnknownProperties(convertPropertyToBooleanAndWriteBack(FAIL_ON_UNKNOWN_PROPERTIES));
475482
} else {
476483
additionalProperties.put(FAIL_ON_UNKNOWN_PROPERTIES, false);
477484
setFailOnUnknownProperties(false);

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,50 @@ public void testFailOnUnknownPropertiesAdditionalProperty() {
431431
configAssert.assertValue(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, codegen::isFailOnUnknownProperties, Boolean.FALSE);
432432
}
433433

434+
@Test
435+
public void testBooleanAdditionalProperties() {
436+
final KotlinClientCodegen codegen = new KotlinClientCodegen();
437+
438+
// Default to false
439+
codegen.additionalProperties().put(KotlinClientCodegen.USE_COROUTINES, "false");
440+
codegen.additionalProperties().put(KotlinClientCodegen.USE_RX_JAVA3, "false");
441+
codegen.additionalProperties().put(KotlinClientCodegen.OMIT_GRADLE_WRAPPER, "false");
442+
codegen.additionalProperties().put(KotlinClientCodegen.USE_SPRING_BOOT3, "false");
443+
codegen.additionalProperties().put(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY, "false");
444+
codegen.additionalProperties().put(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS, "false");
445+
codegen.additionalProperties().put(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, "false");
446+
447+
codegen.processOpts();
448+
449+
// Should be false
450+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_COROUTINES));
451+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_RX_JAVA3));
452+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.OMIT_GRADLE_WRAPPER));
453+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_SPRING_BOOT3));
454+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY));
455+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS));
456+
Assert.assertFalse((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES));
457+
458+
// Default to true
459+
codegen.additionalProperties().put(KotlinClientCodegen.USE_COROUTINES, "true"); // these are exclusive
460+
codegen.additionalProperties().remove(KotlinClientCodegen.USE_RX_JAVA3); // these are exclusive
461+
codegen.additionalProperties().put(KotlinClientCodegen.OMIT_GRADLE_WRAPPER, "true");
462+
codegen.additionalProperties().put(KotlinClientCodegen.USE_SPRING_BOOT3, "true");
463+
codegen.additionalProperties().put(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY, "true");
464+
codegen.additionalProperties().put(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS, "true");
465+
codegen.additionalProperties().put(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES, "true");
466+
467+
codegen.processOpts();
468+
469+
// Should be true
470+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_COROUTINES));
471+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.OMIT_GRADLE_WRAPPER));
472+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.USE_SPRING_BOOT3));
473+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.MAP_FILE_BINARY_TO_BYTE_ARRAY));
474+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.GENERATE_ONEOF_ANYOF_WRAPPERS));
475+
Assert.assertTrue((Boolean) codegen.additionalProperties().get(KotlinClientCodegen.FAIL_ON_UNKNOWN_PROPERTIES));
476+
}
477+
434478
@DataProvider(name = "gsonClientLibraries")
435479
public Object[][] pathResponses() {
436480
return new Object[][]{

0 commit comments

Comments
 (0)