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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 133ca9a5c9b57f60f9b662a754e2da5b7650e79e10564dbc108c9d65d1e1b430 |
|
MD5 | 582c659f135c92deccba199473210977 |
|
BLAKE2b-256 | 62c62b56944d319c967488403e8fb2da0193c254374c12ee2a4668abe4277d3b |
Close
Hashes for openapi_schema_validator-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5fa91aceddfa7abc29c8e2e8fd052c5e997204f439a590fea81da5b9b38a255 |
|
MD5 | df5bed9a8db71c8847ce0ad13284e43a |
|
BLAKE2b-256 | 88bf8f2b1f331b645d27e2e0ec5b75eb34d72bf842645d9d16d5c30411237ec3 |
Close
Hashes for openapi_schema_validator-0.1.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dca81e7e710c518b67474fcd35bee9318f0db2fb573fa6143558fce26c7177f6 |
|
MD5 | 2f568a8d85fa45a0290305551c934609 |
|
BLAKE2b-256 | 059caac93ed234fa67334a5df1b4316b84546b455692b8232d6880195c2173da |