Open mrdziuban opened 1 year ago
this is a very interesting case
may require some more debugging
for now i'd recommend to not use implicit def
for schemas.
i'm not sure if this would cover your case but what would help in the given scenario is
implicit val jsonSchemaFooBar = Json.schema[Foo[Bar]]
implicit val jsonSchemaFooBaz = Json.schema[Foo[Baz]]
instead of
implicit def jsonSchemaFoo[A: Schema] = Json.schema[Foo[A]]
in general statement like
implicit def jsonSchemaFoo[A: Schema] = Json.schema[Foo[A]]
simply won't work
this statement can be decoded like this
implicit def jsonSchemaFoo[A](implicit aSchema: Schema[A]] = Json.schema[Foo[A]]
as you can see - Json.schema
doesn't not accept aSchema
.. so the underlying macro have no idea about the A
type, not it knows or want to know about aSchema
so basic answer would be - no this won't work but on the other hand it specifies a nice problem. I will try to find some time to think about it
Describe the bug
Using a generic type, i.e. one with a type parameter, multiple times in a single class causes an invalid schema to be generated. There is only one definition generated for the type parameter, but it's referenced from both of the other definitions that refer to the type parameter.
To Reproduce
https://scastie.scala-lang.org/UfJUqfSmTvKu3nr0ImJfxA
This produces
Expected behavior
There should be four definitions in the resulting schema:
Playground.Bar
Playground.Baz
Playground.Foo[Bar]
that referencesPlayground.Bar
Playground.Foo[Baz]
that referencesPlayground.Baz
Actual results
The definitions for
Playground.Foo[Bar]
andPlayGround.Foo[Baz]
both referencePlayground.A
(the name ofFoo
's type parameter), but the definition forPlayground.A
only contains the fields ofBaz
-- the correct definition ofBar
is missing -- so the schema doesn't match the structure of the data.Versions: