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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1596cae94f0319a68e331e823ca1adf763b1823841e8b6b03d09ea486e44e76 |
|
MD5 | 126b448fe9d975c5ff91c8aa9c8ef4f2 |
|
BLAKE2b-256 | e8ff53cc0ec6646f2b4c0e8826032a1939553e4bb6e6b2efab2e3fd75ed2deef |
Close
Hashes for openapi_schema_validator-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b32307ccd048c82a447088ba72a9f00e1a8607650096f0839a6ca76eecb16c5 |
|
MD5 | 471566427a1dfc2396be6854bd11494b |
|
BLAKE2b-256 | 3181b00274ad4283e8a1f27c4992a2b41775732e9683a3d437e3793d81a5884e |
Close
Hashes for openapi_schema_validator-0.1.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba27b42454d97d0d46151172c2d70b3027464bdd720060c1e8ebb4b29a255e6d |
|
MD5 | 37f38f552116ed365202fa021468c06b |
|
BLAKE2b-256 | 7ed5bba2230de692e7ec1080c9819ee34f677b40ce2100e786b2d49372f944b3 |