javalin / javalin-openapi

Annotation processor for compile-time OpenAPI & JsonSchema, with out-of-the-box support for Javalin 5.x, Swagger & ReDoc
https://github.com/javalin/javalin-openapi/wiki
Apache License 2.0
45 stars 17 forks source link

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

Closed dennisameling closed 1 year ago

dennisameling commented 1 year ago

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

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 commented 1 year ago

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:

https://github.com/javalin/javalin-openapi/blob/8b3f86ac31ce70d01884ffc9080171409a128a30/openapi-specification/src/main/kotlin/io/javalin/openapi/experimental/processor/generators/TypeSchemaGenerator.kt#L70-L81

dzikoysk commented 1 year ago

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.