Skip to content

[BUG][kotlin] const: true on boolean property generates uncompilable enum (Boolean vs String mismatch) #23550

@denysgaievskyi

Description

@denysgaievskyi

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists? (Reproduced on 7.14.0 and 7.21.0)
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

For an OpenAPI 3.1 spec with a property type: boolean + const: true, the Kotlin generator (kotlin client, jvm-ktor library) emits an inline enum class typed as kotlin.Boolean but populates the single enum entry with a String literal. The generated file does not compile.

Related but distinct: #10445 (request for const keyword), #22398 (missing validation for const). Neither covers the Kotlin-specific compile failure.

openapi-generator version

Reproduced on 7.14.0 and 7.21.0.

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Repro
  version: 1.0.0
paths: {}
components:
  schemas:
    ExceptionPeriod:
      type: object
      required: [startDate, endDate]
      properties:
        startDate: { type: string, format: date }
        endDate: { type: string, format: date }
        isClosed:
          type: boolean
          const: true
          description: Marker flag; when present always true.
Generation Details

kotlin client generator, jvm-ktor library (default options).

Steps to reproduce
  1. Run codegen against the spec above.
  2. Compile the generated Kotlin.
Actual output
enum class ExceptionPeriodIsClosed(@get:JsonValue val value: kotlin.Boolean) {
    @JsonProperty(value = "true")
    `true`("true");  // String passed where Boolean required
    ...
}
e: ExceptionPeriodIsClosed.kt:41:12 Argument type mismatch: actual type is 'String', but 'Boolean' was expected.
Expected output

Either:

Suggest a fix

In the Kotlin inline-enum promotion path, type-check the enum value and emit the literal matching the declared type, not always "$value" as a String.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions