Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Type-name collision in Schema derivation #3407

Closed
jumale opened this issue Dec 18, 2023 · 0 comments
Closed

[BUG] Type-name collision in Schema derivation #3407

jumale opened this issue Dec 18, 2023 · 0 comments

Comments

@jumale
Copy link
Contributor

jumale commented Dec 18, 2023

Tapir version: 1.8.5

Scala version: 2.13.12

Describe the bug
When a subtype has name None, the derivedEnumeration macro confuses it with built-in Option.None type and fails with this compile error:

type mismatch;
 found   : com.example.TestEnum.None.type
 required: Option[sttp.tapir.Validator.EncodeToRaw[com.example.TestEnum]]
    (which expands to)  Option[com.example.TestEnum => Option[Any]]
  implicit lazy val schema: Schema[TestEnum] = Schema.derivedEnumeration[TestEnum].defaultStringBased

How to reproduce?

package com.example

import sttp.tapir.Schema

sealed abstract class TestEnum(val value: String) {
  override def toString: String = value
}

object TestEnum {
  case object Foo  extends TestEnum("foo")
  case object Bar  extends TestEnum("bar")
  case object None extends TestEnum("none")

  implicit lazy val schema: Schema[TestEnum] = Schema.derivedEnumeration[TestEnum].defaultStringBased
}

Additional information
A PlayJson macro for the same type manages to correctly handle this case, so I guess it should be possible to do the same in Tapir.
Also I'm not sure if it's only problem of derivedEnumeration or other macros are also affected

@jumale jumale changed the title [BUG] Type-name collision in enum Schema derivation [BUG] Type-name collision in Schema derivation Dec 18, 2023
@adamw adamw closed this as completed in 3d66e7b Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant