fge / json-schema-avro

Avro to JSON Schema, and back
Other
133 stars 39 forks source link

Read me first

The license of this project is LGPLv3 or later. See file src/main/resources/LICENSE for the full text.

The current version is 0.1.4.

What this is

This package contains two processors (see json-schema-core) to convert Avro schemas to JSON Schemas, and the reverse.

Status

Avro schemas to JSON Schema

This processor can transform all Avro schemas you can think of, as long as said schemas are self contained. The generated JSON Schemas can accurately validate JSON representations of Avro data with two exceptions:

Note that this processor is demoed online here.

JSON Schema to Avro schemas

This processor is not complete yet. It is _much_ more difficult to write than the reverse for two reasons:

The generated Avro schemas are however reasonably good, and cover a very large subset of JSON Schema usages.

This processor is not available online yet; it will soon be.

Why limits are not enforced on Avro's float and double

While JSON Schema has minimum and maximum to enforce the minimum and maximum values of a JSON number, JSON numbers (RFC 4627, section 2.4) do not define any limit to the scale and/or precision of numbers.

That is a first reason, but then one should ask why then, are there limits for int and long. There are two reasons for this:

Defining limits would therefore not ensure that the JSON number being validated can indeed fit into the corresponding Avro type.

Maven artifact

Replace your-version-here with the appropriate version:

<dependency>
    <groupId>com.github.fge</groupId>
    <artifactId>json-schema-avro</artifactId>
    <version>your-version-here</version>
</dependency>