Skip to content

[BUG] [Kotlin-client] Handling default value of enum parameter #12531

@joethehoff

Description

@joethehoff

OpenAPIGenerator 6.0.0 produces incorrect kotlin code for a enum parameter with default value.

https://gist.github.com/joethehoff/7373e4b91b57531df6dc15162803f095

The generator produces following code:

@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
    fun workOrdersGet(color: Color_workOrdersGet? = blue) : Unit {...}

    /**
     * enum for parameter color
     */
     enum class Color_workOrdersGet(val value: kotlin.String) {
         @Json(name = "blue") blue("blue"),
         @Json(name = "red") red("red"),
         @Json(name = "yellow") yellow("yellow"),
         @Json(name = "black") black("black")
     }

The kotlin compiler produces the error message:
Unresolved reference: blue

The generator configuration:

<configuration>
    <inputSpec>${project.basedir}/api/work-api.json</inputSpec>
    <generatorName>kotlin</generatorName>
    <generateApiTests>false</generateApiTests>
    <generateModelTests>false</generateModelTests>
    <apiPackage>xxx.controller</apiPackage>
    <modelPackage>xxx.gen.model</modelPackage>
    <apisToGenerate>WorkOrderServiceV2</apisToGenerate>
    <skipValidateSpec>true</skipValidateSpec>
    <configOptions>
        <enumPropertyNaming>camelCase</enumPropertyNaming>
    </configOptions>
    <additionalProperties>interfaceOnly</additionalProperties>
</configuration>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions