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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4b2712020284cee880b4c55faa513fbc2f8f07f365deda6098f8ab943c9f0df |
|
MD5 | 585af925029c531c63f1d7ba92028179 |
|
BLAKE2b-256 | 8c440065b0e102810356c54e01d8bd56542d5d02acd27060d81b2e372fd0888c |
Close
Hashes for openapi_schema_validator-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b65d6c2242620bfe76d4c749b61cd9657e4528895a8f4fb6f916085b508ebd24 |
|
MD5 | 25f5da49274679a90bd06ac92ff3b522 |
|
BLAKE2b-256 | 61de67a615be34d76a1b18ee13861ffd584ffc982e465499c67d5b029bd1084a |
Close
Hashes for openapi_schema_validator-0.1.5-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 215b516d0942f4e8e2446cf3f7d4ff2ed71d102ebddcc30526d8a3f706ab1df6 |
|
MD5 | 47567108b14084e17330adea1bbba500 |
|
BLAKE2b-256 | 9bd7e1db5c09d71bd9a1eb778af152e3e924ba354a65fb3d24244a1ef2eaa4fc |