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

**URL:** <https://softwaremill.community/t/how-to-handle-scala-3-enums-with-the-same-name-different-scope/177>\
**Category:** tapir\
**Created:** [April 3, 2023, 6:54pm UTC](https://softwaremill.community/t/how-to-handle-scala-3-enums-with-the-same-name-different-scope/177 "2023-04-03T18:54:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/joe/32/129_2.png) [@Joe](https://softwaremill.community/u/Joe)\
**Post date:** [April 3, 2023, 6:54pm UTC](https://softwaremill.community/t/how-to-handle-scala-3-enums-with-the-same-name-different-scope/177/1 "2023-04-03T18:54:39Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [April 3, 2023, 7:33pm UTC](https://softwaremill.community/t/how-to-handle-scala-3-enums-with-the-same-name-different-scope/177/2 "2023-04-03T19:33:53Z")

</div>

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

Otherwise, the method used [here](https://tapir.softwaremill.com/en/latest/endpoint/schemas.html#using-implicits) should work, sth like:

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

```

---

<div class="post-metadata">

**Author:** ![frozenwizard](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@frozenwizard](https://softwaremill.community/u/frozenwizard)\
**Post date:** [April 4, 2023, 3:49pm UTC](https://softwaremill.community/t/how-to-handle-scala-3-enums-with-the-same-name-different-scope/177/3 "2023-04-04T15:49:49Z")

</div>

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:

```auto
  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

```auto
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.
