Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [KOTLIN-CLIENT] enums with empty entries to generate invalid kotlin-client code #18660

Open
4 of 6 tasks
burntcookie90 opened this issue May 13, 2024 · 1 comment
Open
4 of 6 tasks

Comments

@burntcookie90
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

A spec with an empty enum entry no longer generates a valid enum in kotlin code.

openapi-generator version

7.4.0, also 7.5.0

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: API
  version: 1.0.0
paths:
  /api/v1/foo/:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Foo'
components:
  schemas:
    Foo:
      type: object
      description: foo
      properties:
        field_name:
          nullable: true
          enum:
            - ''
            - stringvalue1
          type: string
Generation Details

will generate this kotlin code:

/**
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 *
 */

@file:Suppress(
    "ArrayInDataClass",
    "EnumEntryName",
    "RemoveRedundantQualifierName",
    "UnusedImport"
)


import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
 * foo
 *
 * @param fieldName 
 */
@JsonClass(generateAdapter = true)

data class ApiFoo (

    @Json(name = "field_name")
    val fieldName: ApiFoo.FieldName? = null

) {

    /**
     * 
     *
     * Values: ,stringvalue1
     */
    @JsonClass(generateAdapter = false)
    enum class FieldName(val value: kotlin.String) {
        @Json(name = "") (""),
        @Json(name = "stringvalue1") stringvalue1("stringvalue1");
    }
}

which has the invalid first entry. Previously this (in 7.3.0) this would generate the following:

/**
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 *
 */

@file:Suppress(
    "ArrayInDataClass",
    "EnumEntryName",
    "RemoveRedundantQualifierName",
    "UnusedImport"
)


import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
 * foo
 *
 * @param fieldName 
 */
@JsonClass(generateAdapter = true)

data class ApiFoo (

    @Json(name = "field_name")
    val fieldName: ApiFoo.FieldName? = null

) {

    /**
     * 
     *
     * Values: eMPTY,stringvalue1
     */
    @JsonClass(generateAdapter = false)
    enum class FieldName(val value: kotlin.String) {
        @Json(name = "") eMPTY(""),
        @Json(name = "stringvalue1") stringvalue1("stringvalue1");
    }
}

with the eMPTY entry.

here is my openApiGenerate task

openApiGenerate {
  generatorName = "kotlin"
  inputSpec = specFile
  outputDir = generationDir
  templateDir = "$templatesDir"
  apiPackage = "com.giftster.network.api"
  packageName = "com.giftster.network"
  cleanupOutput = true
  modelNamePrefix = "Api"
  library = "jvm-retrofit2"
  generateApiTests = false
  generateModelTests = false
  configOptions.set([
    artifactId              : "client",
    dateLibrary             : "java8",
    groupId                 : "com.foo,
    moshiCodeGen            : "true",
    omitGradlePluginVersions: "true",
    omitGradleWrapper       : "true",
    useCoroutines           : "true"
  ])
}
Steps to reproduce

Run the generation on the yaml.

Related issues/PRs

#18062

Suggest a fix

Should revert the enum generation changes or provide guidance on fixing the breaking change.

@burntcookie90
Copy link
Author

setting enumPropertyNaming to camelCase reverts the behavior introudced in #18062. However, I'm leaving this issue open because original should not generate invalid code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant