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

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: openapi_schema_validator-0.6.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for openapi_schema_validator-0.6.0.tar.gz
Algorithm Hash digest
SHA256 921b7c1144b856ca3813e41ecff98a4050f7611824dfc5c6ead7072636af0520
MD5 de0ac19ceed2aa7e13f081ac21e71c1e
BLAKE2b-256 9992f4be01a9e2ccd0edfce1b573d49b694c8a13ac303123125179c2ccfbac7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_schema_validator-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e95b95b621efec5936245025df0d6a7ffacd1551e91d09196b3053040c931d7
MD5 620a4d0c7e152b81e111dc6fb9e35afb
BLAKE2b-256 3720bc67fcae5cf7c0f783e35f9d1e9ece2708f38e16450b1a05e7a2f766aa1b

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