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
1 change: 1 addition & 0 deletions docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|companionObject|Whether to generate companion objects in data classes, enabling companion extensions.| |false|
|dateLibrary|Option. Date library to use|<dl><dt>**threetenbp-localdatetime**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, for legacy app only)</dd><dt>**kotlinx-datetime**</dt><dd>kotlinx-datetime (preferred for multiplatform)</dd><dt>**string**</dt><dd>String</dd><dt>**java8-localdatetime**</dt><dd>Java 8 native JSR310 (jvm only, for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)</dd><dt>**threetenbp**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, preferred for jdk &lt; 1.8)</dd></dl>|java8|
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', 'original', and 'bestEffortBacktick' (like 'original' but tries to wrap values in backticks before falling back to sanitizing, e.g. `name,asc` stays `name,asc` rather than becoming nameCommaAsc; useful for sort/order enums)| |original|
|enumUnknownDefaultCase|Add an `unknown_default_open_api` enum case as a fallback for unrecognized values. Only `moshi`(serializationLibrary) decodes every unknown value to it: `jackson` skips nullable enums, `kotlinx_serialization` skips non-string enums, and neither `gson`(serializationLibrary) nor `multiplatform`(library) decodes to it at all.|<dl><dt>**false**</dt><dd>No changes to the enums are made, this is the default option.</dd><dt>**true**</dt><dd>Each enum gains an `unknown_default_open_api` case.</dd></dl>|false|
|explicitApi|Generates code with explicit access modifiers to comply with Kotlin Explicit API Mode.| |false|
|failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false|
|generateOneOfAnyOfWrappers|Generate oneOf, anyOf schemas as wrappers. Only `jvm-retrofit2`(library) with `gson` or `kotlinx_serialization`(serializationLibrary) support this option.| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ public KotlinClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_RESPONSE_AS_RETURN_TYPE, "When using retrofit2 and coroutines, use `Response`<`T`> as return type instead of `T`.", true));

cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable."));

// AbstractKotlinCodegen calls cliOptions.clear(), dropping DefaultCodegen's registration.
// Re-registered on kotlin alone: no other Kotlin generator's templates implement the fallback.
CliOption enumUnknownDefaultCaseOpt = CliOption.newBoolean(
CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE,
"Add an `unknown_default_open_api` enum case as a fallback for unrecognized values. Only `moshi`(serializationLibrary) decodes every unknown value to it: `jackson` skips nullable enums, `kotlinx_serialization` skips non-string enums, and neither `gson`(serializationLibrary) nor `multiplatform`(library) decodes to it at all.");
Map<String, String> enumUnknownDefaultCaseOpts = new HashMap<>();
enumUnknownDefaultCaseOpts.put("false",
"No changes to the enums are made, this is the default option.");
enumUnknownDefaultCaseOpts.put("true",
"Each enum gains an `unknown_default_open_api` case.");
enumUnknownDefaultCaseOpt.setEnum(enumUnknownDefaultCaseOpts);
cliOptions.add(enumUnknownDefaultCaseOpt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.languages.KotlinClientCodegen.*;
Expand Down Expand Up @@ -1505,4 +1506,21 @@ public void testNoDefaultImplWhenNeitherSourceIsSet() throws IOException {
Assert.assertTrue(sawJsonTypeInfo,
"Expected at least one generated model with @JsonTypeInfo to exercise the code path");
}

/**
* AbstractKotlinCodegen calls cliOptions.clear(), so an option inherited from DefaultCodegen stays
* functional while vanishing from config-help and docs/generators/kotlin.md. That is how
* enumUnknownDefaultCase went undocumented for years; this guards the re-registration.
*/
@Test
public void testEnumUnknownDefaultCaseIsRegisteredAsCliOption() {
CliOption option = new KotlinClientCodegen().cliOptions().stream()
.filter(o -> CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE.equals(o.getOpt()))
.findFirst()
.orElse(null);

Assert.assertNotNull(option, CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE + " is not registered");
Assert.assertEquals(option.getDefault(), "false");
Assert.assertEquals(option.getEnum().keySet(), Set.of("true", "false"));
}
}
Loading