OpenAPITools/openapi-generator · error · RuntimeException
{enumSerializationLibrary} is an invalid enum property namin
Error message
{enumSerializationLibrary} is an invalid enum property naming option. Please choose from:
{availableValues} What it means
KotlinClientCodegen.setSerializationLibrary maps the 'serializationLibrary' additional property onto the enum {moshi, gson, jackson, kotlinx_serialization} via valueOf(). Unknown or case-mismatched values raise IllegalArgumentException, rethrown as a RuntimeException listing the four valid names. Default is moshi. The message wording ('invalid enum property naming option') is copy-pasted from modelPropertyNaming code and misleading — this is about the serialization library.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java:384
}
this.useCoroutines = useCoroutines;
}
/**
* Sets the serialization engine for Kotlin
*
* @param enumSerializationLibrary The string representation of the serialization library as defined by
* {@link org.openapitools.codegen.languages.KotlinClientCodegen.SERIALIZATION_LIBRARY_TYPE}
*/
public void setSerializationLibrary(final String enumSerializationLibrary) {
try {
this.serializationLibrary = SERIALIZATION_LIBRARY_TYPE.valueOf(enumSerializationLibrary);
} catch (IllegalArgumentException ex) {
StringBuilder sb = new StringBuilder(enumSerializationLibrary + " is an invalid enum property naming option. Please choose from:");
for (SERIALIZATION_LIBRARY_TYPE t : SERIALIZATION_LIBRARY_TYPE.values()) {
sb.append("\n ").append(t.name());
}
throw new RuntimeException(sb.toString());
}
}
@Override
public String modelFilename(String templateName, String modelName) {
String suffix = modelTemplateFiles().get(templateName);
// If this was a proper template method, i wouldn't have to make myself throw up by doing this....
if (getGenerateRoomModels() && suffix.startsWith("RoomModel")) {
return roomModelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
} else {
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
}
}
public String roomModelFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + roomModelPackage.replace('.', File.separatorChar);
}
View on GitHub (pinned to fcec517be3)
Solutions
- Use exactly `moshi`, `gson`, `jackson`, or `kotlinx_serialization`.
- Remember the default is moshi, so omitting the option is always safe.
- Note library couplings enforced elsewhere: jvm-volley requires gson (line 749), the spring libraries require jackson (line 875) — set the value the library demands, not just any enum member.
Example fix
# before openapi-generator-cli generate -g kotlin -i api.yaml -p serializationLibrary=kotlinx-serialization # after openapi-generator-cli generate -g kotlin -i api.yaml -p serializationLibrary=kotlinx_serialization
Defensive patterns
Strategy: validation
Validate before calling
# shell: kotlin serialization allowlist (default moshi)
sl="${SERIALIZATION_LIBRARY:-moshi}"
case "$sl" in
moshi|gson|jackson|kotlinx_serialization) ;;
*) echo "serializationLibrary must be moshi|gson|jackson|kotlinx_serialization, got: $sl" >&2; exit 2 ;;
esac Type guard
// Kotlin
enum class KotlinSerialization(val option: String) { MOSHI("moshi"), GSON("gson"), JACKSON("jackson"), KOTLINX("kotlinx_serialization") }
fun serializationLibraryOf(v: String): KotlinSerialization? =
KotlinSerialization.entries.firstOrNull { it.option == v } Try / catch
try {
DefaultGenerator().opts(clientOptInput).generate()
} catch (e: RuntimeException) {
// message lists valid names despite the misleading 'property naming' wording
throw IllegalStateException("Invalid kotlin serializationLibrary: ${e.message}", e)
} Prevention
- Remember the underscore: kotlinx_serialization, never kotlinx-serialization.
- Pair the value with the library: spring ⇒ jackson, volley ⇒ gson, default ⇒ moshi.
- Validate via the enum in build scripts instead of trusting free-text input.
When it happens
Trigger: `-g kotlin -p serializationLibrary=kotlinx-serialization` (hyphen instead of underscore), `KotlinxSerialization`, `Jackson` (capitalized), `gson-wasm`, `serde`; also `SerializationLibrary` (wrong key) leading to defaults elsewhere.
Common situations: Hyphen/underscore confusion for kotlinx_serialization; capitalized values from hand-written YAML; copying values from the Micronaut (micronaut_serde_jackson) or Java generators whose vocabularies differ.
Related errors
- useJackson3 requires serializationLibrary=jackson
- This library currently only supports gson serialization. Try
- This library currently only supports jackson serialization.
- Unexpected serializationLibrary value: {serializationLibrary
- Unexpected serializationLibrary value: {serializationLibrary
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/2d5320d2b55a4966.
Report an issue: GitHub.