Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@ public CodegenModel fromModel(String name, Schema schema) {

@Override
public String toEnumValue(String value, String datatype) {
if ("kotlin.Int".equals(datatype) || "kotlin.Long".equals(datatype)) {
if ("kotlin.Int".equals(datatype) || "kotlin.Long".equals(datatype)
|| "kotlin.Boolean".equals(datatype)) {
return value;
} else if ("kotlin.Double".equals(datatype)) {
if (value.contains(".")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void toEnumValue() {
assertEquals(codegen.toEnumValue("1", "kotlin.Double"), "1.0");
assertEquals(codegen.toEnumValue("1.3", "kotlin.Double"), "1.3");
assertEquals(codegen.toEnumValue("1337", "kotlin.Long"), "1337");
assertEquals(codegen.toEnumValue("true", "kotlin.Boolean"), "true");
assertEquals(codegen.toEnumValue("5", "kotlin.Float"), "5f");
assertEquals(codegen.toEnumValue("1.0", "kotlin.Float"), "1.0f");
assertEquals(codegen.toEnumValue("data", "Something"), "\"data\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,36 @@ public void testIntArrayToEnum() throws IOException {
TestUtils.assertFileContains(modelKt, "enum class DaysOfWeek(val value: kotlin.Int)");
}

@Test
public void testBooleanConstEnumUsesBooleanLiteral() throws IOException {
File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("kotlin")
.setLibrary("jvm-ktor")
.setAdditionalProperties(new HashMap<>() {{
put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson");
put(CodegenConstants.MODEL_PACKAGE, "model");
put(ENUM_PROPERTY_NAMING, "original");
}})
.setInputSpec("src/test/resources/3_1/kotlin/issue23550-boolean-const.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();

generator.opts(clientOptInput).generate();

final Path modelKt = Paths.get(output + "/src/main/kotlin/model/ExceptionState.kt");

TestUtils.assertFileContains(modelKt,
"enum class ExceptionPeriodIsClosed(val value: kotlin.Boolean)",
"@JsonProperty(value = \"true\")",
"`true`(true);");
TestUtils.assertFileNotContains(modelKt, "`true`(\"true\")");
}

@Test
public void testJacksonEnumsUseJsonCreator() throws IOException {
File output = Files.createTempDirectory("test").toFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
openapi: 3.1.0
info:
title: Boolean const regression
version: 1.0.0
paths: {}
components:
schemas:
ExceptionState:
type: object
properties:
exceptionPeriodIsClosed:
type: boolean
const: true
Loading