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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66fa34b40a40b1ff927e1db8bf5a20dc84fd0933fc284ec0dc87d7ae889a0874 |
|
MD5 | fa3248eba109ba4b0c4a101e445234f6 |
|
BLAKE2b-256 | b59aa9396add8ac3c1e74efbc940d11080962d7a5ab02c041c54183ac2b9b9fb |
Close
Hashes for openapi_schema_validator-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 782c7be7fd75ab172fb47b4504a63833001f7d5de0a06a08998c146e5f923f0a |
|
MD5 | 84785110055cd3758a8d52ae60d57a13 |
|
BLAKE2b-256 | eb3ae2ad512999ca9714fa62d9277e16a723a368c7345404b0e37d6233ac0271 |
Close
Hashes for openapi_schema_validator-0.1.4-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d3401cc1579eed0c1f2bec1a669a964a9974bc6a940261bf7c8aa9edb7d409 |
|
MD5 | a97c7bf6a20f6347b5d7a5cacfce019a |
|
BLAKE2b-256 | 61a9a8c8e8772d23fcd23e95198f601360632861c89b76290cb1bc7fea229bb5 |