diff --git a/README.rst b/README.rst index 410ec9c..db48576 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 `__ Related projects ################