Open seveneves opened 6 days ago
Hm it seems that this should work, being encoded to json here:
and converted to a validator here:
But clearly something doesn't work. Would need debugging :)
@adamw the problem is that with the default encode
function, the produced Enumeration
has wraped instances of sealed trait as SString
schema. While after encoding and decoding, it represents such values as actual Scala String
. Then of course equality breaks when it compares Scala String
with an instance of the sealed trait. So the equality boils down to "Female" == Female
which of course is false
.
When using encode
as _.toString
then it forces the derived schema to have actual String
values instead of instances of the sealed trait. And this fixes the equality check.
Ah right ... so we would need special comparison logic for example values, which mirrors what encoderExampleSingleValue
is doing, that is for all non-primitive values, it just performs .toString
Tapir version: 1.10.10
Scala version: 2.13/3.3.3
I am deriving
apispec.Schema
fromtapir.Schema
for an enumeration and found that the defaultencode
function produces inconsistentapispec.Schema
s. Such inconsistency is exposed whenapispec.Schema
is encoded and decoded to/form json.This problem is highlighted with the following code
Given following sealed trait
with helper methods
Then the following works correctly and assertion passes
But when using
derivedEnumeration
with the defaultencode
function, the following code fails