Open
Description
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
Suggest a fix
Should revert the enum generation changes or provide guidance on fixing the breaking change.