从案例 类 生成 Json 模式(播放框架)

Generate Json schema from case classes (play framework)

我正在使用 Play 框架在大小写 class 和 Json 之间进行转换。

如何提取与案例 class 相对应的 Json 的模式?

编辑: 如果 class 是 case class Foo(string:Option[String], int:Option[Int])

架构应该是(大约):

{
 "$schema": "http://json-schema.org/draft-07/schema#",
 "$id": "http://example.com/product.schema.json",
 "title": "Foo",
 "type": "object",
 "properties": {
   "string": {
     "type": "string"
   },
   "int": {
     "type": "int"
   }
 },
 "required": [ ]
}

为此使用 scala-jsonschema 并赞助这个伟大图书馆的作者。

该库还支持 spray-json、circe 和其他一些 JSON Scala 解析器。