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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: openapi_schema_validator-0.6.1.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-1011-azure

File hashes

Hashes for openapi_schema_validator-0.6.1.tar.gz
Algorithm Hash digest
SHA256 b8b25e2cb600a0ed18452e675b5dd8cbb99009909c2641c973a4b02c93e33ca2
MD5 813ac4c6f62319e86a1fdfd0956e2549
BLAKE2b-256 9a8f4c5653f78960e8ab83387c46909b71f2db6fd41f32c5e3d4437e3b16c737

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openapi_schema_validator-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e39f2cc92a458a1b9971d8a0519fcc94a4c454d9accffab5189575716fe53bed
MD5 9a776221fa2756e0957cf84617648181
BLAKE2b-256 c2b207594c8395ddb145856549127f4ce183c635670241d105846c1afaf2fc7f

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