Reputation: 4133
I want to generate json schema of case class in order to provide some information to other service that is going to expose my app with rest api
I've got this class:
case class Vendor(
name: String,
synonyms: List[String],
transalit: String,
urlPart: String)
How can i generate like this:
{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"synonyms":{
"type":"array",
"items":{
"type":"string"
}
},
"translit":{
"type":"string"
},
"urlPart":{
"type":"string"
}
}
}
i found this: https://github.com/coursera/autoschema but sbt can't find dependency.
also i found this Is there a way to get a JSON-Schema from a Scala Case Class hierarchy? and this question is very similar to mine but there is no answer..
May be i'm looking for answer that doesn't exist. May be it's better to use some other techniques
Upvotes: 2
Views: 2723
Reputation: 140
The project has been forked:
https://github.com/sauldhernandez/autoschema
Now, you can get the artifact by adding this dependency to your build.sbt:
libraryDependencies += "com.sauldhernandez" %% "autoschema" % "1.0.4"
Upvotes: 1
Reputation: 2178
It seems that the Maven artifact for autoschema does not exist and this is why sbt can't find the dependency.
Good news is that with sbt you can import a project from github and add it as a dependency. In your build.sbt
add the following:
lazy val autoschemaProject =
ProjectRef(uri("https://github.com/coursera/autoschema.git"), "autoschema")
lazy val root = (project in file(".")).dependsOn(autoschemaProject)
Notice that root
might already be defined in your build.sbt
, in this case only add dependsOn(autoschemaProject)
.
I tested this with sbt 0.13.7 and I managed to use autoschema to generate a json schema from a case class.
Upvotes: 6