scala-jsonschema icon indicating copy to clipboard operation
scala-jsonschema copied to clipboard

README examples need more clarification

Open JoeCordingley opened this issue 5 years ago • 3 comments

The documentation on the front page makes it difficult to pick up as a new user:

import json._

val personSchema: json.Schema[Person] = Json.schema[Person]

isn't going to work because Json isn't found. It isn't imported and searching for a Json type within the repo doesn't help. Perhaps a compilable examples module or be more explicit in your readme?

JoeCordingley avatar Oct 09 '20 11:10 JoeCordingley

I see now that you need to depend on a json implementation such as circe or play in order to use this. And this is not stated in the readme. That is api does not come in if you simply depend on core.

JoeCordingley avatar Oct 09 '20 12:10 JoeCordingley

hi @JoeCordingley

import json._

val personSchema: json.Schema[Person] = Json.schema[Person]

works fine as is. But may be broken iа you would import some other json or Json into the scope. Please check if you have some Play stuff imported. Names may clash in that case.

andyglow avatar Oct 12 '20 16:10 andyglow

depending in json-libraries is necessary in 2 cases

  • you are willing to convert Schema[X] into json ast of certain json-lib.. JsObject, JObject, etc
  • or your model have specified default values of types defined as enum, sealed trait, case class. Scala-JsonSchema library doesn't work with values. it's goal is to setup the contract between code and json-schema representation. so for values we use corresponding json-lib.

andyglow avatar Oct 12 '20 16:10 andyglow