Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Simple usage
...
ValidationError: Additional properties are not allowed ('city' was unexpected)

Format check
************

You can also check format for primitive types

.. code-block:: python
Expand All @@ -93,6 +96,60 @@ You can also check format for primitive types
...
ValidationError: '-12' is not a 'date'

References
**********

You can resolve JOSN references by passing custon reference resolver

.. code-block:: python

from jsonschema.validators import RefResolver

# A schema with reference
schema = {
"type" : "object",
"required": [
"name"
],
"properties": {
"name": {
"$ref": "#/components/schemas/Name"
},
"age": {
"$ref": "#/components/schemas/Age"
},
"birth-date": {
"$ref": "#/components/schemas/BirthDate"
}
},
"additionalProperties": False,
}
# Referenced schemas
schemas = {
"components": {
"schemas": {
"Name": {
"type": "string"
},
"Age": {
"type": "integer",
"format": "int32",
"minimum": 0,
"nullable": True,
},
"BirthDate": {
"type": "string",
"format": "date",
}
},
},
}

ref_resolver = RefResolver.from_schema(schemas)

validate({"name": "John", "age": 23}, schema, resolver=ref_resolver)

For more information about reference resolver see `Resolving JSON References <https://python-jsonschema.readthedocs.io/en/stable/references/>`__

Related projects
################
Expand Down