@@ -6,7 +6,18 @@ The simplest way to validate an instance under OAS schema is to use the ``valida
66Validate
77--------
88
9- To validate an OpenAPI v3.1 schema:
9+ ``validate `` call signature is:
10+
11+ .. code-block :: python
12+
13+ validate(instance, schema, cls = OAS32Validator, ** kwargs)
14+
15+ The first argument is always the value you want to validate.
16+ The second argument is always the OpenAPI schema object.
17+ The ``cls `` keyword argument is optional and defaults to ``OAS32Validator ``.
18+ Use ``cls `` when you need a specific validator version/behavior.
19+
20+ To validate an OpenAPI schema:
1021
1122.. code-block :: python
1223
@@ -56,6 +67,17 @@ To validate an OpenAPI v3.1 schema:
5667
5768 By default, the latest OpenAPI schema syntax is expected.
5869
70+ Common pitfalls
71+ ---------------
72+
73+ - argument order matters: call ``validate(instance, schema) ``, not
74+ ``validate(schema, instance) ``
75+ - ``validate `` does not load files from a path; load your OpenAPI document
76+ first and pass the parsed schema mapping
77+ - when validating a schema fragment that uses ``$ref `` (for example,
78+ ``paths/.../responses/.../schema ``), provide reference context via
79+ ``registry=... `` as shown in :doc: `references `
80+
5981Validators
6082----------
6183
@@ -67,32 +89,6 @@ if you want to disambiguate the expected schema version, import and use ``OAS31V
6789
6890 validate({" name" : " John" , " age" : 23 }, schema, cls = OAS31Validator)
6991
70- The OpenAPI 3.1 and 3.2 base dialect URIs are registered for
71- ``jsonschema.validators.validator_for `` resolution.
72- If your schema declares
73- ``"$schema": "https://spec.openapis.org/oas/3.1/dialect/base" `` or
74- ``"$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17" ``,
75- ``validator_for `` resolves directly to ``OAS31Validator `` or
76- ``OAS32Validator `` without unresolved-metaschema fallback warnings.
77-
78- .. code-block :: python
79-
80- from jsonschema.validators import validator_for
81-
82- from openapi_schema_validator import OAS31Validator
83- from openapi_schema_validator import OAS32Validator
84-
85- schema = {
86- " $schema" : " https://spec.openapis.org/oas/3.1/dialect/base" ,
87- " type" : " object" ,
88- }
89- schema32 = {
90- " $schema" : " https://spec.openapis.org/oas/3.2/dialect/2025-09-17" ,
91- " type" : " object" ,
92- }
93- assert validator_for(schema) is OAS31Validator
94- assert validator_for(schema32) is OAS32Validator
95-
9692 For OpenAPI 3.2, use ``OAS32Validator ``.
9793
9894In order to validate OpenAPI 3.0 schema, import and use ``OAS30Validator `` instead of ``OAS31Validator ``.
@@ -127,6 +123,35 @@ In order to validate OpenAPI 3.0 schema, import and use ``OAS30Validator`` inste
127123
128124 validate({" name" : " John" , " age" : None }, schema, cls = OAS30Validator)
129125
126+ Default dialect resolution
127+ --------------------------
128+
129+ The OpenAPI 3.1 and 3.2 base dialect URIs are registered for
130+ ``jsonschema.validators.validator_for `` resolution.
131+ If your schema declares
132+ ``"$schema": "https://spec.openapis.org/oas/3.1/dialect/base" `` or
133+ ``"$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17" ``,
134+ ``validator_for `` resolves directly to ``OAS31Validator `` or
135+ ``OAS32Validator `` without unresolved-metaschema fallback warnings.
136+
137+ .. code-block :: python
138+
139+ from jsonschema.validators import validator_for
140+
141+ from openapi_schema_validator import OAS31Validator
142+ from openapi_schema_validator import OAS32Validator
143+
144+ schema = {
145+ " $schema" : " https://spec.openapis.org/oas/3.1/dialect/base" ,
146+ " type" : " object" ,
147+ }
148+ schema32 = {
149+ " $schema" : " https://spec.openapis.org/oas/3.2/dialect/2025-09-17" ,
150+ " type" : " object" ,
151+ }
152+ assert validator_for(schema) is OAS31Validator
153+ assert validator_for(schema32) is OAS32Validator
154+
130155 Schema errors vs instance errors
131156--------------------------------
132157
0 commit comments