Open DenisNovac opened 3 years ago
Right, I suspect CirceEnum
brings in the codecs only for a single type, while TapirCodecEnumeratum
brings in codecs for any type. So it should be completely sufficient to extend that trait only by the outer enum, or just import sttp.tapir.codec.enumeratum._
which should be equivalent.
I think the intended usage of CirceEnum
and TapirCodecEnumeratum
is different - creating a single object containing all of the codec derivation rules that are used in an app, see https://tapir.softwaremill.com/en/latest/mytapir.html
trait only by the outer enum
I tried it and it gives the same error. But it seems to work when i place it only here:
object ClassWithInner extends TapirCodecEnumeratum {
implicit val codec: Codec[ClassWithInner] = deriveCodec[ClassWithInner]
implicit val schema: Schema[ClassWithInner] = Schema.derived[ClassWithInner]
}
So it seems that you need to place this trait in every place you make schema for some type which contains enum elements instead of just creating the schema for this enum.
Imports are working but IDEA says they are unused a removes it. It happens with many such imports so we don't really use them in projects.
Hm yeah you're right, no idea why the version with ... extends
doesn't work when it's on the outside enum.
As for intellij, I suppose you could report a bug, as these imports are used and incorrectly marked as unused.
Tapir version: 0.18.0-M17
Scala version: 2.13.6
Describe the bug
When you have inner enum inside other enum and both of them extends
TapirCodecEnumeratum
trait - compile will fail with error:How to reproduce?
Example of code:
By the way, circe does not have this issue. I guess, it is because
CirceEnum
have the type.Additional information
Project code: https://github.com/DenisNovac/tapir-enumeratum