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

Unused sttp.tapir.Validator import required for Codec.derivedEnumeration to compile #2254

Closed
thavril opened this issue Jun 20, 2022 · 2 comments · Fixed by #2255
Closed

Unused sttp.tapir.Validator import required for Codec.derivedEnumeration to compile #2254

thavril opened this issue Jun 20, 2022 · 2 comments · Fixed by #2255

Comments

@thavril
Copy link

thavril commented Jun 20, 2022

Tapir version: 1.0.0

Scala version: 2.13.8

Hi !
I am implementing an http server using tapir and runnning it as a zio http server.

Using the following Codec:

implicit def plainCodecForMyProduct: PlainCodec[MyProduct] = Codec.derivedEnumeration[String, MyProduct](MyProduct.fromString, _.toString)

(Where MyProduct is a trait, implemented by some case objects)

In the documentation it says to import sttp.tapir._ but I am already importing sttp.tapir.ztapir._

When importing only what's needed from plain tapir:

import sttp.tapir.Codec.PlainCodec
import sttp.tapir.Codec

I get the following error:

[error] not found: value Validator
[error] error after rewriting to sttp.tapir.Codec.derivedEnumeration[String, domain.enums.MyProduct].apply
[error] possible cause: maybe a wrong Dynamic method signature?
[error] Codec.derivedEnumeration[String, MyProduct](MyProduct.fromString, _.toString)
[error] ^
[error] missing argument list for method fromString in object MyProduct
[error] Unapplied methods are only converted to functions when a function type is expected.
[error] You can make this conversion explicit by writing fromString _ or fromString(_) instead of fromString.
[error] Codec.derivedEnumeration[String, MyProduct](MyProduct.fromString, _.toString)
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

Everything works fine when I add this import:

import sttp.tapir.Validator

but it stands out as an unused import.

Any workaround?

Thank you!

@adamw
Copy link
Member

adamw commented Jun 20, 2022

Indeed, the macro was missing the fully qualified class name.

The sttp.tapir.ztapir._ import does replace the wildcard sttp.tapir._ (which brings into scope endpoint and input/output builders), but you still need to import the data types such as Codec

@thavril
Copy link
Author

thavril commented Jun 20, 2022

Awesome. Thank you :)

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

Successfully merging a pull request may close this issue.

2 participants