/dataclasses-jsonschema

JSON schema generation from dataclasses

Primary LanguagePythonMIT LicenseMIT

Dataclasses JSON Schema

image

image

Language grade: Python

A library to generate JSON Schema from python 3.7 dataclasses. Python 3.6 is supported through the dataclasses backport. Aims to be a more lightweight alternative to similar projects such as marshmallow & pydantic.

Feature Overview

  • Support for draft-04, draft-06, Swagger 2.0 & OpenAPI 3 schema types
  • Serialisation and deserialisation
  • Data validation against the generated schema
  • APISpec support. Example below:

Installation

For improved validation performance using fastjsonschema, install with:

Examples

Generate the schema:

Serialise data:

Deserialise data:

Generate a schema for embedding into an API spec:

Custom validation rules can be added using NewType:

For more examples see the tests

APISpec Plugin

New in v2.5.0

OpenAPI & Swagger specs can be generated using the apispec plugin:

TODO