[BUG] Kotlin generator produce a invalid kotlin file when shema have an enum with default value.
Created by: etremblay
Description
Kotlin generator produce a invalid kotlin file when shema have an enum with default value.
Unresolved reference: TypeEnum
openapi-generator version
5.2.1, master
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: 'Enum Bug'
version: latest
paths:
'/':
get:
operationId: demoBug
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/MoveMovement'
components:
schemas:
MoveMovement:
required:
- type
properties:
type:
type: string
default: MOVE
enum:
- MOVE
Generation Details
docker run --rm -v ${PWD}:/local --user "${USER_ID}:${GROUP_ID}" openapitools/openapi-generator-cli:latest generate -i /local/model.yaml -g kotlin -o /local/kotlin
Steps to reproduce
Generate a model with an enum property with default value
The model constructor will have invalid kotlin code
data class MovementMoveMovement (
@Json(name = "type")
val type: MovementMoveMovement.Type = TypeEnum.MOVE
) : MovementMovement {
/**
*
*
* Values: MOVE
*/
enum class Type(val value: kotlin.String) {
@Json(name = "MOVE") MOVE("MOVE");
}
}
should be
val type: MovementMoveMovement.Type = Type.MOVE
Related issues/PRs
Similar to https://github.com/OpenAPITools/openapi-generator/issues/10244
The regression was introduced by https://github.com/OpenAPITools/openapi-generator/pull/9853 in 5.2.1
Suggest a fix
@Override
public String toEnumName(CodegenProperty property) {
return property.nameInCamelCase;
}
I will try to submit a proper pull request with unit tests.