zio / zio-schema

Compositional, type-safe schema definitions, which enable auto-derivation of codecs and migrations.
https://zio.dev/zio-schema
Apache License 2.0
142 stars 162 forks source link

Add Schema#toJsonSchema #88

Open jdegoes opened 3 years ago

jdegoes commented 3 years ago

JSON Schema is a protocol to describe the structure of JSON values.

It would be great if we could take an existing schema for a user-defined data type, and convert it into a JSON schema, in such a way that the JSON codec could read and write data in that format.

trait Schema[A] {
  def toJsonSchema: String
}

Probably, we should implement this as a method on MetaSchema, and then delegate to it from Schema, because a MetaSchema is more than sufficient to document the structure of JSON values.

calvinlfer commented 3 years ago

There are multiple specs for JSON Schema out there - Draft 7 seems to be the most common but Draft 2019_09 is newer (there are other older ones as well) - maybe we should have implementations for both of these?

jdegoes commented 3 years ago

Agreed, would be nice to support the popular ones.

alexvanolst commented 3 years ago

I'll be picking this up

bjornbak commented 1 year ago

@alexvanolst any progress on this? Our current json schema generator https://github.com/andyglow/scala-jsonschema and not many scala alternatives so I would be very interested in a new implementation :)

alexvanolst commented 1 year ago

@bjornbak Unfortunately I ended up not having the time (or a concrete use case for it)

987Nabil commented 4 months ago

@jdegoes is this still relevant?

guersam commented 1 month ago

@987Nabil I think it is, because there are some popular use cases of JSON Schema without OpenAPI, such as [OpenAI].