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
Let Tapir users customise (or somehow derive from the Schema) the encode function of the enumeration Validator, so it is in line with the one provided to Schema using derivedEnumeration[T](encode = Some(...))
Description
Currently (in both Tapir 1.9.9 and on master branch), the macro for Scala 3 enumeration Validator sets encode function to None (code reference). If enumeration validation fails, the list of possible enumeration values in the failure message is encoded differently compared to how it's done in Schema if custom encode is provided.
Use case
Suppose I have an enumeration, with derived Schema
Now, if I have PieType as, for example, query parameter called type, and I call my API with an unsupported value (e.g. berry), then the response I get would be
Invalid value for: path parameter tpe (expected value to be one of (Apple, Orange, BananaCustard), but got: \"berry\")
which doesn't align with the OpenAPI spec that is generated from the endpoint (because Schema.encode is used there).
Current workaround
Override toString method of the enumeration type, but that is not always acceptable
enumPieType(valindex:Int, valname:String) {
...
overridedeftoString:String= name
}
The text was updated successfully, but these errors were encountered:
The validator is later updated (see here, but the updated validator wasn't later used to format error messages. This should be fixed in #4175. I assume error messages where the only problem, otherwise please let us know :)
Feature request
Let Tapir users customise (or somehow derive from the Schema) the
encode
function of the enumeration Validator, so it is in line with the one provided toSchema
usingderivedEnumeration[T](encode = Some(...))
Description
Currently (in both Tapir 1.9.9 and on master branch), the macro for Scala 3 enumeration Validator sets
encode
function toNone
(code reference). If enumeration validation fails, the list of possible enumeration values in the failure message is encoded differently compared to how it's done inSchema
if customencode
is provided.Use case
Suppose I have an enumeration, with derived
Schema
Now, if I have
PieType
as, for example, query parameter calledtype
, and I call my API with an unsupported value (e.g.berry
), then the response I get would bewhich doesn't align with the OpenAPI spec that is generated from the endpoint (because
Schema.encode
is used there).Current workaround
Override
toString
method of the enumeration type, but that is not always acceptableThe text was updated successfully, but these errors were encountered: