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/python-openapi/openapi-schema-validator.svg?branch=master https://img.shields.io/codecov/c/github/python-openapi/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:

Documentation

Check documentation to see more details about the features. All documentation is in the “docs” directory and online at openapi-schema-validator.readthedocs.io

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/python-openapi/openapi-schema-validator.git#egg=openapi_schema_validator

Usage

To validate an OpenAPI v3.1 schema:

from openapi_schema_validator import validate

# A sample schema
schema = {
    "type": "object",
    "required": [
       "name"
    ],
    "properties": {
        "name": {
            "type": "string"
        },
        "age": {
            "type": ["integer", "null"],
            "format": "int32",
            "minimum": 0,
        },
        "birth-date": {
            "type": "string",
            "format": "date",
        },
        "address": {
             "type": 'array',
             "prefixItems": [
                 { "type": "number" },
                 { "type": "string" },
                 { "enum": ["Street", "Avenue", "Boulevard"] },
                 { "enum": ["NW", "NE", "SW", "SE"] }
             ],
             "items": False,
         }
    },
    "additionalProperties": False,
}

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

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

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

By default, the latest OpenAPI schema syntax is expected.

For more details read about Validation.

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.6.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

openapi_schema_validator-0.6.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file openapi_schema_validator-0.6.3.tar.gz.

File metadata

File hashes

Hashes for openapi_schema_validator-0.6.3.tar.gz
Algorithm Hash digest
SHA256 f37bace4fc2a5d96692f4f8b31dc0f8d7400fd04f3a937798eaf880d425de6ee
MD5 7076003c896e5270079d7e9dc33f1498
BLAKE2b-256 8bf35507ad3325169347cd8ced61c232ff3df70e2b250c49f0fe140edb4973c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_schema_validator-0.6.3.tar.gz:

Publisher: python-publish.yml on python-openapi/openapi-schema-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for openapi_schema_validator-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f3b9870f4e556b5a62a1c39da72a6b4b16f3ad9c73dc80084b1b11e74ba148a3
MD5 baf7393e57c351de2b83a6ab0b0c237d
BLAKE2b-256 21c6ad0fba32775ae749016829dace42ed80f4407b171da41313d1a3a5f102e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_schema_validator-0.6.3-py3-none-any.whl:

Publisher: python-publish.yml on python-openapi/openapi-schema-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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