OpenAPI schema validation for Python
Project description
About
Openapi-schema-validator is a Python library that validates schema against the OpenAPI Schema Specification v3.0 which is an extended subset of the JSON Schema Specification Wright Draft 00.
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/p1c2u/openapi-schema-validator.git#egg=openapi_schema_validator
Usage
Simple usage
from openapi_schema_validator import validate
# A sample schema
schema = {
"type" : "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32",
"minimum": 0,
"nullable": True,
},
"birth-date": {
"type": "string",
"format": "date",
}
},
"additionalProperties": False,
}
# If no exception is raised by validate(), the instance is valid.
validate({"name": "John", "age": 23}, schema)
validate({"name": "John", "city": "London"}, schema)
Traceback (most recent call last):
...
ValidationError: Additional properties are not allowed ('city' was unexpected)
You can also check format for primitive types
from openapi_schema_validator import oas30_format_checker
validate({"name": "John", "birth-date": "-12"}, schema, format_checker=oas30_format_checker)
Traceback (most recent call last):
...
ValidationError: '-12' is not a 'date'
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 Distributions
Close
Hashes for openapi-schema-validator-0.1.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230db361c71a5b08b25ec926797ac8b59a8f499bbd7316bd15b6cd0fc9aea5df |
|
MD5 | f0b1727a04bdc820c83d2074d0363a5e |
|
BLAKE2b-256 | b09278320f3b3ff1768ee1e325fc7e1a721c16cee1e244d9fb6817971afb78db |
Close
Hashes for openapi_schema_validator-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af023ae0d16372cf8dd0d128c9f3eaa080dc3cd5dfc69e6a247579f25bd10503 |
|
MD5 | 230bafa4c604f95d5255bcb60ee8bbde |
|
BLAKE2b-256 | b94b4cf4b5b044606fd7765242219ba5e02d3c01550d43fab68e588191508fc1 |
Close
Hashes for openapi_schema_validator-0.1.6-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ef097b78c191c89d9a12cdf3d311b2ecf9d3b80bbe8610dbc67a812205a6a8d |
|
MD5 | 64a0f04c37fd30b2936efe188ab52c96 |
|
BLAKE2b-256 | 25fc55427970ea20b58b9e7cdc32225f0af7757802325a278fbb5489b3d8cbaf |