Skip to main content

"a framework to extract jsonschemas from a variety of models."

Project description

jsonschema-extractor is a library and extensible framework for extracting json schema from various object and primitives.

https://github.com/toumorokoshi/jsonschema-extractor/actions/workflows/python-package.yaml/badge.svg

Out of the box support exists for:

Usage

from typing import List
import jsonschema_extractor
assert jsonschema_extractor.extract(List[int]) == {
    "type": "array",
    "items": {"type": "integer"}
}

Attrs-example

import attr
from attr.validators import instance_of
import jsonschema_extractor

@attr.define
class Example(object):
    integer: int = attr.field()
    foo = attr.field(metadata={"jsonschema": {"type": "string", "format": "uuid"}})
    validator_list: List[float] = attr.field()
    string: str = attr.field(
        default="foo",
        metadata={"description": "This is an description."}
    )

assert extractor.extract(Example) == {
    "type": "object",
    "title": "Example",
    "properties": {
        "string": {"description": "This is an description.", "type": "string"},
        "integer": {"type": "integer"},
        "validator_list": {"items": {"type": "number"}, "type": "array"},
        "foo": {"type": "string", "format": "uuid"},
    },
    "required": ["integer", "foo", "validator_list"],
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonschema-extractor-2.0.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

jsonschema_extractor-2.0.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema-extractor-2.0.2.tar.gz.

File metadata

  • Download URL: jsonschema-extractor-2.0.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for jsonschema-extractor-2.0.2.tar.gz
Algorithm Hash digest
SHA256 5eac4ef619eb8b7679571f31ff15d1fab52e1b9ff92d19b3241b0e3ebc357226
MD5 faaa929c82c920f7f717da7ef2e66c02
BLAKE2b-256 d8978c7ec239d1ab786af80b2fb121b9806dbad0d0d58ee1e343b6d75924d11a

See more details on using hashes here.

File details

Details for the file jsonschema_extractor-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema_extractor-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d87d7d78fd9a28cc4e8862dcc0ea371f511dd130e583861bff8e8cbb71ce82ec
MD5 61c460dc51f0c86151a34535c793caad
BLAKE2b-256 5520351a119c9133fad9034185cab15aecdb6222c806c9b44dbf96536b3b3652

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page