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

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: openapi_schema_validator-0.6.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1012-azure

File hashes

Hashes for openapi_schema_validator-0.6.2.tar.gz
Algorithm Hash digest
SHA256 11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804
MD5 1c1faed2edfd01bb1471bdbe525406f7
BLAKE2b-256 5cb27d5bdf2b26b6a95ebf4fbec294acaf4306c713f3a47c2453962511110248

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_schema_validator-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c4887c1347c669eb7cded9090f4438b710845cd0f90d1fb9e1b3303fb37339f8
MD5 ebf53dddf3ff1032afe8c770f15bc9de
BLAKE2b-256 b3dc9aefae8891454130968ff079ece851d1ae9ccf6fb7965761f47c50c04853

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