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 Distribution
Close
Hashes for openapi-schema-validator-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71889d1cb69d9fb46eb04243b24e9c0cd7989d9153d29d8770e626874bf68f80 |
|
MD5 | fc7da15b4b3b9a7bf88cad7bee3584a3 |
|
BLAKE2b-256 | 99a07151418ca44271a1a1c7a575b2d27fa9019a4bdae48c7905db93237ce753 |
Close
Hashes for openapi_schema_validator-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1e4eaaad40e5324fa7b8719fac7ce74f87e14d66f00930c160aeb0e9e370215 |
|
MD5 | 3075b49b8b2920dd0246d17c53362c94 |
|
BLAKE2b-256 | 6a47e5e7d28f814d36fa8a461e015e23048970839e626d2f3071d2bbe7bfaa85 |