tapir icon indicating copy to clipboard operation
tapir copied to clipboard

Relaxed enumeratum codecs

Open Fristi opened this issue 1 year ago • 4 comments

Tapir version: 1.10.5

Scala version: 2.12.12

Describe the bug

The TapirCodecEnumeratum contains two methods

def plainCodecEnumEntryDecodeCaseInsensitive[E <: EnumEntry](implicit `enum`: Enum[E]): Codec.PlainCodec[E] = plainCodecEnumEntryUsing(
    `enum`.withNameInsensitiveOption
  )

  implicit def plainCodecEnumEntry[E <: EnumEntry](implicit `enum`: Enum[E]): Codec.PlainCodec[E] = plainCodecEnumEntryUsing(
    `enum`.withNameOption
  )

While plainCodecEnumEntry is defined as implicit, I would rather prefer have plainCodecEnumEntryDecodeCaseInsensitive to be the default? Such that for query parameters, path segments and such the case sensitivity is ignored

How to reproduce?

Define a enumeratum enum and use it an query param of path segment while changing the expected casing, it will break fairly easy

Additional information

Fristi avatar Apr 22 '24 07:04 Fristi

Is this still relevant, otherwise we could close this?

Fristi avatar May 14 '24 13:05 Fristi

I don't now :) What's the behavior of other enum codecs? What are the defaults usually? That would need spending some time on to research properly.

adamw avatar May 14 '24 16:05 adamw