-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Schema for play-json JsValue #286
Comments
Hello, @0lejk4
Seems like this empty definition does the job. You can do something though, Please check this
https://scastie.scala-lang.org/andyglow/ehjsHlLaTNCScxihwnjdiQ/7 This shows that you can expose json-type information from the types that you are aware of. May I ask you to describe your case little bit more detailed? |
So the use case is having a field in DTO with some random JSON that we don't care about, but it then will be sent to someone who knows what to do with it. {
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "array",
"items": {
"$ref": "#/definitions/JsValue"
},
"definitions": {
"JsObject": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/JsValue"
},
"title": "JsObject"
},
"JsValue": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/definitions/JsValue"
}
},
{
"type": "boolean"
},
{
"$ref": "#/definitions/JsObject"
},
{
"type": "integer"
},
{
"type": "null"
},
{
"type": "string"
}
],
"title": "JsValue"
}
}
} First is easier and enough for my use case but I still had issues with the covariance of the Schema typeclass. So I had schema for JsNull and JsValue, because of covariance they were colliding in implicit search, so I needed to use this trick but in the end in places where JsValue JsonSchema was expected I was getting JsNull`s schema. |
you can also try something like this
which is getting resulted in
|
Hello @andyglow I saw https://github.com/andyglow/scala-jsonschema#free-objects with info on how to create the schema for JsObject and now I am struggling with creating Schema for JsValue. Can you suggest the code for its schema?
Also, have a question on how to have Schema for JsValue and its subtypes as because of Schema type-class covariance the behavior is strange, for example if I define schema for JsValue and JsNull, JsNull is used when Schema for JsValue is expected.
The text was updated successfully, but these errors were encountered: