jsonschema-spec

JSONSchema Spec with object-oriented paths


Keywords
jsonschema, swagger, spec, object-oriented, path, schema
License
Apache-2.0
Install
pip install jsonschema-spec==0.2.4

Documentation

JSONSchema Path

https://travis-ci.org/p1c2u/jsonschema-path.svg?branch=master https://img.shields.io/codecov/c/github/p1c2u/jsonschema-path/master.svg?style=flat

About

Object-oriented JSONSchema

Key features

  • Traverse schema like paths
  • Access schema on demand with separate dereferencing accessor layer

Installation

pip install jsonschema-path

Alternatively you can download the code and install from the repository:

pip install -e git+https://github.com/p1c2u/jsonschema-path.git#egg=jsonschema_path

Usage

>>> from jsonschema_path import SchemaPath

>>> d = {
...     "properties": {
...        "info": {
...            "$ref": "#/$defs/Info",
...        },
...     },
...     "$defs": {
...         "Info": {
...             "properties": {
...                 "title": {
...                     "$ref": "http://example.com",
...                 },
...                 "version": {
...                     "type": "string",
...                     "default": "1.0",
...                 },
...             },
...         },
...     },
... }

>>> path = SchemaPath.from_dict(d)

>>> # Stat keys
>>> "properties" in path
True

>>> # Concatenate paths with /
>>> info_path = path / "properties" / "info"

>>> # Stat keys with implicit dereferencing
>>> "properties" in info_path
True

>>> # Concatenate paths with implicit dereferencing
>>> version_path = info_path / "properties" / "version"

>>> # Open content with implicit dereferencing
>>> with version_path.open() as contents:
...     print(contents)
{'type': 'string', 'default': '1.0'}
  • openapi-core
    Python library that adds client-side and server-side support for the OpenAPI.
  • openapi-spec-validator
    Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger) and OpenAPI 3.0 specification
  • openapi-schema-validator
    Python library that validates schema against the OpenAPI Schema Specification v3.0.

License

Copyright (c) 2017-2022, Artur Maciag, All rights reserved. Apache-2.0