Skip to main content

OpenAPI schema validation for Python

Project description

https://img.shields.io/pypi/v/openapi-schema-validator.svg https://travis-ci.org/p1c2u/openapi-schema-validator.svg?branch=master https://img.shields.io/codecov/c/github/p1c2u/openapi-schema-validator/master.svg?style=flat https://img.shields.io/pypi/pyversions/openapi-schema-validator.svg https://img.shields.io/pypi/format/openapi-schema-validator.svg https://img.shields.io/pypi/status/openapi-schema-validator.svg

About

Openapi-schema-validator is a Python library that validates schema against the OpenAPI Schema Specification v3.0 which is an extended subset of the JSON Schema Specification Wright Draft 00.

Installation

Recommended way (via pip):

$ pip install openapi-schema-validator

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

$ pip install -e git+https://github.com/p1c2u/openapi-schema-validator.git#egg=openapi_schema_validator

Usage

Simple usage

from openapi_schema_validator import validate

# A sample schema
schema = {
    "type" : "object",
    "required": [
       "name"
    ],
    "properties": {
        "name": {
            "type": "string"
        },
        "age": {
            "type": "integer",
            "format": "int32",
            "minimum": 0,
            "nullable": True,
        },
        "birth-date": {
            "type": "string",
            "format": "date",
        }
    },
    "additionalProperties": False,
}

# If no exception is raised by validate(), the instance is valid.
validate({"name": "John", "age": 23}, schema)

validate({"name": "John", "city": "London"}, schema)

Traceback (most recent call last):
    ...
ValidationError: Additional properties are not allowed ('city' was unexpected)

You can also check format for primitive types

from openapi_schema_validator import oas30_format_checker

validate({"name": "John", "birth-date": "-12"}, schema, format_checker=oas30_format_checker)

Traceback (most recent call last):
    ...
ValidationError: '-12' is not a 'date'

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

openapi-schema-validator-0.1.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distributions

openapi_schema_validator-0.1.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

openapi_schema_validator-0.1.2-py2-none-any.whl (7.7 kB view details)

Uploaded Python 2

File details

Details for the file openapi-schema-validator-0.1.2.tar.gz.

File metadata

  • Download URL: openapi-schema-validator-0.1.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/2.7.18

File hashes

Hashes for openapi-schema-validator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c1596cae94f0319a68e331e823ca1adf763b1823841e8b6b03d09ea486e44e76
MD5 126b448fe9d975c5ff91c8aa9c8ef4f2
BLAKE2b-256 e8ff53cc0ec6646f2b4c0e8826032a1939553e4bb6e6b2efab2e3fd75ed2deef

See more details on using hashes here.

File details

Details for the file openapi_schema_validator-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: openapi_schema_validator-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.12

File hashes

Hashes for openapi_schema_validator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b32307ccd048c82a447088ba72a9f00e1a8607650096f0839a6ca76eecb16c5
MD5 471566427a1dfc2396be6854bd11494b
BLAKE2b-256 3181b00274ad4283e8a1f27c4992a2b41775732e9683a3d437e3793d81a5884e

See more details on using hashes here.

File details

Details for the file openapi_schema_validator-0.1.2-py2-none-any.whl.

File metadata

  • Download URL: openapi_schema_validator-0.1.2-py2-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/2.7.18

File hashes

Hashes for openapi_schema_validator-0.1.2-py2-none-any.whl
Algorithm Hash digest
SHA256 ba27b42454d97d0d46151172c2d70b3027464bdd720060c1e8ebb4b29a255e6d
MD5 37f38f552116ed365202fa021468c06b
BLAKE2b-256 7ed5bba2230de692e7ec1080c9819ee34f677b40ce2100e786b2d49372f944b3

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