How to handle Scala 3 enums with the same name (different scope)

Hi all!
I have a question with the OpenAPI documentation and Scala 3 enums that have the same name in a different scope. Let’s say you have two classes like the following:

case class User(name: String, status: User.Status)

object User:
  enum Status
    case Active, Inactive

  given Schema[User.Status] = 
    Schema.derivedEnumeration.defaultStringBased


case class Account(users: List[User], status: Account.Status)

object Account:
  enum Status
    case Active, Inactive

  given Schema[Account.Status] = 
    Schema.derivedEnumeration.defaultStringBased

The issue that we are seeing is that when we generate the OpenAPI documentation, the names of the two Status enums get their types mangled into Status1 and Status2. Is there a way, perhaps an annotation I can add to the enums, to give them nicer names like UserStatus and AccountStatus without having to resort to renaming the enums themselves?

I’m not sure if @encodedName would work, please check, if it doesn’t, maybe it should - report a feature request/bug then :slight_smile:

Otherwise, the method used here should work, sth like:

given Schema[User.Status] = Schema.derivedEnumeration.defaultStringBased.name(SName("MyName"))

So we tracked down the issue a bit further. The main issue was coming from using a query param as input in the update endpoint. That used:

  implicit val accountStatus: PlainCodec[Account.Status] =
    Codec.derivedEnumeration[String, Account.Status].defaultStringBased

for the path conversion. So that was causing us to generate multiple statuses as well. We were able to work around the schema with

type AccountStatus = Account.Status
given Schema[AccountStatus] = Schema.derivedEnumeration.defaultStringBased.name(SName("AccountStatus"))

However that’s not available for Codec.derivedEnumeration nor is setting the .name on it.

We’re changing our endpoints to take in a JSON body for the update instead so we won’t even have this issue.