OpenAPI schema validation for Python
Project description
About
Openapi-schema-validator is a Python library that validates schema against:
OpenAPI Schema Specification v3.0 which is an extended subset of the JSON Schema Specification Wright Draft 00.
OpenAPI Schema Specification v3.1 which is an extended superset of the JSON Schema Specification Draft 2020-12.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 |
|
MD5 | 1c1faed2edfd01bb1471bdbe525406f7 |
|
BLAKE2b-256 | 5cb27d5bdf2b26b6a95ebf4fbec294acaf4306c713f3a47c2453962511110248 |
File details
Details for the file openapi_schema_validator-0.6.2-py3-none-any.whl
.
File metadata
- Download URL: openapi_schema_validator-0.6.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4887c1347c669eb7cded9090f4438b710845cd0f90d1fb9e1b3303fb37339f8 |
|
MD5 | ebf53dddf3ff1032afe8c770f15bc9de |
|
BLAKE2b-256 | b3dc9aefae8891454130968ff079ece851d1ae9ccf6fb7965761f47c50c04853 |