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

Enum values with hyphens or starting with numbers don't end up in the generated OpenAPI spec #199

Closed
dennisameling opened this issue Aug 29, 2023 · 2 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@dennisameling
Copy link

dennisameling commented Aug 29, 2023

Actual behavior (the bug)

Consider the following enum (Kotlin):

enum class ExampleEnum {
    `five-minutes`,
    FIVE_MINUTES, // This is the only one that ends up in the spec
    `5m`,
}

This is valid Kotlin code and the OpenAPI spec also doesn't prevent us from setting enum values like five-minutes and 5m. However, the library converts it into the following in the spec:

"ExampleEnum" : {
  "type" : "string",
  "enum" : [ "FIVE_MINUTES" ]
},

Expected behavior

We would expect the generated spec to look like this instead:

"ExampleEnum" : {
  "type" : "string",
  "enum" : [ "five-minutes", "FIVE_MINUTES", "5m" ]
},

To Reproduce

  • Use the ExampleEnum mentioned above with this library
  • Use it in any property by doing something like val exampleProperty: List<ExampleEnum>
  • Notice that the generated spec misses most of the enum values

Additional context

We're on the latest version (5.6.2-1) of this library.

Please let me know if I can provide more details or examples. Happy to provide a fix if you could point me at the place where I should be looking in the library. Thank you!

@dzikoysk dzikoysk added the bug Something isn't working label Aug 31, 2023
@dzikoysk
Copy link
Member

I didn't even know I can use such names for enum values. I think it could be Kotlin-only feature that is simply invisible for the Java annotation processor 🤔 This is the code we use for that:

source.kind == ENUM -> {
val values = JsonArray()
source.enclosedElements
.filterIsInstance<VariableElement>()
.filter { it.modifiers.contains(Modifier.STATIC) }
.filter { context.isAssignable(it.asType(), type.mirror) }
.map { it.toSimpleName() }
.forEach { values.add(it) }
schema.addProperty("type", "string")
schema.add("enum", values)
}

@dzikoysk
Copy link
Member

Yup, it won't work. This value simply does not exist as a constant value in the compiled enum, so it's beyond our scope.

@dzikoysk dzikoysk added the wontfix This will not be worked on label Aug 31, 2023
@dzikoysk dzikoysk closed this as completed Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants