-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
JsonSchema doesn't allow nested Option #669
Comments
Here is a discussion related to this point: https://gitter.im/endpoints4s/endpoints4s?at=5f9200e9245ff718a77dcae2 In summary, the safest option IMHO would be to not use |
So while I agree that using /* Note: make sure that this is only used in places where the `null` doesn't mean anything else
*
* Good (unambiguous about `null`):
* - `arrayJsonSchema(nullableJsonSchema(intJsonSchema))`
* - `arrayJsonSchema(nullableJsonSchema(genericJsonSchema[Foo]))`
*
* Bad (ambiguous about `null`):
* - `nullableJsonSchema(nullableJsonSchema(intJsonSchema))`
* - `optField("doubleNullable")(nullableJsonSchema(intJsonSchema))`
*/
def nullableJsonSchema[A](implicit schema: JsonSchema[A]): JsonSchema[Option[A]] For non-OpenApi, this would have semantics like: def nullableJsonSchema[A](implicit schema: JsonSchema[A]): JsonSchema[Option[A]] = new JsonSchema[Option[A]] {
val encoder = _.fold[ujson.Value](ujson.Null)(schema.encoder.encode)
val decoder = {
case ujson.Null => endpoints4s.Valid(None)
case other => schema.decoder.decode(other).map(Some(_))
}
} And for OpenApi it would set Side note: the OpenAPI interpreter is a little resistant to extension. I was going to try to write an extension trait for
Not sure that there is anything to do about this side note though. Extensibility with type-safety is tricky and endpoints4s already does a great job. |
@harpocrates OK, I’m fine with your suggestion. About the extensibility of interpreters… you’re right. Extensible ADTs are hard (I remember this paper but the solution would be a bit complex… http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf). |
Apart from that functional pearl, there's also https://www.microsoft.com/en-us/research/uploads/prod/2016/11/trees-that-grow.pdf. I'm not arguing for that though. |
The code below fails to compile with the following message:
could not find implicit value for parameter e: JsonSchema[Seq[Option[String]]]
(and similar forc
andd
)The text was updated successfully, but these errors were encountered: