Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.
/ jsonSchema4s Public archive

A library for generating a simple json schema from a case class

License

Notifications You must be signed in to change notification settings

despegar/jsonSchema4s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonSchema4s

jsonSchema4s is a simple library for generating a simple json schema from a case class with http://json-schema.org/ format.

Usage

The base method is JsonSchemaGenerator.generateSchema and it returns a JsonSchemaElement ready to be serialized to json to generate the respecting json schema.

The json serialization it's not provided due to not adding extra dependencies, use the JsonSchemaElement on a more complex class to be serializated and also if you already have a json serializer you can use it. (Note: the serialization was tested with https://github.com/json4s/json4s)

Example

import com.despegar.library.serialization.json._

val schema: JsonSchemaElement = JsonSchemaGenerator.generateSchema[ACaseClass]

// You need to use your own scala json serializer
val schemaAsJson = someSerializer.serialize(schema)
...

Supported Types

The library supports case class, Option[A], Seq[A], String, Boolean, Int, Long, BigDecimal.

These were the only ones implemented just by the need

WARNING

It's experimental due to scala reflection universal api. The recommended use is for documentation purposes.

About

A library for generating a simple json schema from a case class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages