Skip to content

Commit 25f3a57

Browse files
committed
Document condifuration
1 parent 00a1cce commit 25f3a57

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

README.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ Usage
5454

5555
.. code-block:: python
5656
57-
validate(instance, schema, cls=OAS32Validator, allow_remote_references=False, **kwargs)
57+
validate(
58+
instance,
59+
schema,
60+
cls=OAS32Validator,
61+
allow_remote_references=False,
62+
check_schema=True,
63+
**kwargs,
64+
)
5865
5966
The first argument is always the value you want to validate.
6067
The second argument is always the OpenAPI schema object.
@@ -83,6 +90,15 @@ remote ``$ref`` retrieval. To resolve external references, pass an explicit
8390
``registry``. Set ``allow_remote_references=True`` only if you explicitly
8491
accept jsonschema's default remote retrieval behavior.
8592

93+
``check_schema`` defaults to ``True`` and validates the schema before
94+
validating an instance. For trusted pre-validated schemas in hot paths, set
95+
``check_schema=False`` to skip schema checking.
96+
97+
The ``validate`` helper keeps an internal compiled-validator cache. You can
98+
control cache size using the
99+
``OPENAPI_SCHEMA_VALIDATOR_VALIDATE_CACHE_MAX_SIZE`` environment variable
100+
(default: ``128``).
101+
86102
To validate an OpenAPI schema:
87103

88104
.. code-block:: python

docs/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ Usage
8484
8585
Read more about the :doc:`validation`.
8686

87+
Configuration
88+
-------------
89+
90+
Environment variables:
91+
92+
* ``OPENAPI_SCHEMA_VALIDATOR_VALIDATE_CACHE_MAX_SIZE``
93+
Maximum number of compiled validators kept by the ``validate`` shortcut
94+
cache. Default: ``128``.
95+
96+
See :doc:`validation` for runtime behavior details.
97+
8798
Related projects
8899
----------------
89100

docs/validation.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ Validate
1010

1111
.. code-block:: python
1212
13-
validate(instance, schema, cls=OAS32Validator, allow_remote_references=False, **kwargs)
13+
validate(
14+
instance,
15+
schema,
16+
cls=OAS32Validator,
17+
allow_remote_references=False,
18+
check_schema=True,
19+
**kwargs,
20+
)
1421
1522
The first argument is always the value you want to validate.
1623
The second argument is always the OpenAPI schema object.
1724
The ``cls`` keyword argument is optional and defaults to ``OAS32Validator``.
1825
Use ``cls`` when you need a specific validator version/behavior.
1926
The ``allow_remote_references`` keyword argument is optional and defaults to
2027
``False``.
28+
The ``check_schema`` keyword argument is optional and defaults to ``True``.
2129
Common forwarded keyword arguments include:
2230

2331
- ``registry`` for explicit external reference resolution context
@@ -28,6 +36,13 @@ remote ``$ref`` retrieval.
2836
Set ``allow_remote_references=True`` only if you explicitly accept
2937
jsonschema's default remote retrieval behavior.
3038

39+
For trusted pre-validated schemas in hot paths, set ``check_schema=False`` to
40+
skip schema checking.
41+
42+
The shortcut keeps an internal compiled-validator cache.
43+
Use ``OPENAPI_SCHEMA_VALIDATOR_VALIDATE_CACHE_MAX_SIZE`` to control cache
44+
capacity (default: ``128``).
45+
3146
To validate an OpenAPI schema:
3247

3348
.. code-block:: python
@@ -171,10 +186,14 @@ Schema errors vs instance errors
171186
--------------------------------
172187

173188
The high-level ``validate(...)`` helper checks schema validity before instance
174-
validation, following ``jsonschema.validate(...)`` behavior.
189+
validation by default (``check_schema=True``), following
190+
``jsonschema.validate(...)`` behavior.
175191
Malformed schema values (for example an invalid regex in ``pattern``) raise
176192
``SchemaError``.
177193

194+
When ``check_schema=False``, schema checking is skipped and malformed schemas
195+
may instead fail during validation with lower-level errors.
196+
178197
If you instantiate a validator class directly and call ``.validate(...)``,
179198
schema checking is not performed automatically, matching
180199
``jsonschema`` validator-class behavior.

0 commit comments

Comments
 (0)