You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
There should be four definitions in the resulting schema:
Playground.Bar
Playground.Baz
Playground.Foo[Bar] that references Playground.Bar
Playground.Foo[Baz] that references Playground.Baz
Actual results
The definitions for Playground.Foo[Bar] and PlayGround.Foo[Baz] both reference Playground.A (the name of Foo's type parameter), but the definition for Playground.A only contains the fields of Baz -- the correct definition of Bar is missing -- so the schema doesn't match the structure of the data.
Versions:
jsonschema 0.7.9
scala version 2.13.10
The text was updated successfully, but these errors were encountered:
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]]
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:
The text was updated successfully, but these errors were encountered: