Skip to content

Allow type customization when scanning code (for example: custom serializations for enum values) #247

@troyunverdruss

Description

@troyunverdruss

Originally discussed on discord: https://discord.com/channels/804862058528505896/821821822500208691/1391964076971655238

Original bug/request description:

Hi, apologies if I'm posting wrong, this is my first time. I'm attempting to setup the openapi plugin for my project and it mostly works as expected except that my Kotlin server has to interop with a rails server (to be totally clear, my frontend react code base needs to be able to fetch some data from kotlin and some from rails but rails defines my "enums"). So I have enum in my kotlin code, like this:

interface MyEnum {
  val value: String
}

enum class CustomEnum(
  override val value: String,
) : MyEnum {
  ONE("One"), TWO("Two")
}

and I need to get the openapi JSON to reflect that. Right now it serializes to something like:

  "components" : {
    "schemas" : {
      "CustomEnum" : {
        "type" : "string",
        "enum" : [ "ONE", "TWO" ]

but I need it to be: "enum" : [ "One", "Two" ]

I've tried a TON of things but I just cannot figure out how to get this to work. I tried @get:JsonValue as well as trying to use a custom jackson mapper (I did this by pulling the openapi plugin code and modifying it) but nothing seems to work. Generating the API values as all caps is wrong for my use case and I can't figure out how to work around it.

Thank you!

Initial reply from Discord:

jackson is not involved in the process of generating it, because the schema is processed at compile time by annotation processor, not at runtime
I think it's not possible for now to have a different casing for enum values
could you create a feature request ticket for that in the openapi repo? :) I think it'll be relatively simple, so I might be able to take a look at it later today

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions