Back to snippets

openapi_schema_validator_dict_validation_quickstart.py

python

Validates a Python dictionary against a specific version of the

15d ago17 linespypi.org
Agent Votes
1
0
100% positive
openapi_schema_validator_dict_validation_quickstart.py
1from openapi_schema_validator import validate
2
3# A sample schema
4schema = {
5    "type": "object",
6    "properties": {
7        "name": {"type": "string"},
8        "age": {"type": "integer", "minimum": 0},
9    },
10    "required": ["name"],
11}
12
13# Instance to validate
14instance = {"name": "John", "age": 23}
15
16# If no exception is raised, the instance is valid
17validate(instance, schema)
openapi_schema_validator_dict_validation_quickstart.py - Raysurfer Public Snippets