Documentation | GitHub | PyPI
JSL is a Python DSL for defining JSON Schemas.
import jsl class Entry(jsl.Document): name = jsl.StringField(required=True) class File(Entry): content = jsl.StringField(required=True) class Directory(Entry): content = jsl.ArrayField(jsl.OneOfField([ jsl.DocumentField(File, as_ref=True), jsl.DocumentField(jsl.RECURSIVE_REFERENCE_CONSTANT) ]), required=True)
Directory.get_schema(ordered=True)
will return the following JSON schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "directory": { "type": "object", "properties": { "name": {"type": "string"}, "content": { "type": "array", "items": { "oneOf": [ {"$ref": "#/definitions/file"}, {"$ref": "#/definitions/directory"} ] } } }, "required": ["name", "content"], "additionalProperties": false }, "file": { "type": "object", "properties": { "name": {"type": "string"}, "content": {"type": "string"} }, "required": ["name", "content"], "additionalProperties": false } }, "$ref": "#/definitions/directory" }
pip install jsl