Description
Since 7.25.0, an inline enum array default generates invalid Kotlin:
colors: Set<String>? =
Set<Color>.setOfLeft_ParenthesisColorPeriodRedCommaColorPeriodBlueRight_Parenthesis
Expected:
colors: Set<String>? = setOf("red", "blue")
openapi-generator version
7.25.0. Regression from 7.24.0, exposed by #24556.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Reproduction
version: 1.0.0
paths:
/items:
get:
operationId: getItems
parameters:
- name: colors
in: query
schema:
type: array
uniqueItems: true
items:
type: string
enum: [red, blue]
default: [red, blue]
responses:
"204":
description: No content
Generation Details
openapi-generator-cli generate -g kotlin -i repro.yaml -o out \
-p library=jvm-ktor,serializationLibrary=jackson
Steps to reproduce
- Generate the client with 7.25.0.
- Compile the generated code.
- Observe unresolved
Color and mangled setOf... references.
Related issues/PRs
- #24556 added default values to optional
jvm-ktor parameters and exposed this issue.
- #20394 reports a similar invalid default for an array of inline enum values in the Kotlin
jvm-retrofit2 generator.
- #14873 concerns invalid Kotlin defaults for arrays of referenced enums.
Suggest a fix
KotlinClientCodegen.adjustEnumRefDefault() treats the complete container default as a scalar enum value. Skip containers:
if (StringUtils.isEmpty(param.defaultValue)
+ || param.isContainer
|| !(param.isEnum || param.isEnumRef)) {
Additionally, render inline enum-array parameter defaults according to their exposed type:
Description
Since 7.25.0, an inline enum array default generates invalid Kotlin:
Expected:
openapi-generator version
7.25.0. Regression from7.24.0, exposed by #24556.OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Colorand mangledsetOf...references.Related issues/PRs
jvm-ktorparameters and exposed this issue.jvm-retrofit2generator.Suggest a fix
KotlinClientCodegen.adjustEnumRefDefault()treats the complete container default as a scalar enum value. Skip containers:if (StringUtils.isEmpty(param.defaultValue) + || param.isContainer || !(param.isEnum || param.isEnumRef)) {Additionally, render inline enum-array parameter defaults according to their exposed type: