File tree Expand file tree Collapse file tree 4 files changed +32
-21
lines changed
Expand file tree Collapse file tree 4 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Installation
2020
2121.. md-tab-set ::
2222
23- .. md-tab-item :: Pip + PyPI (recommented )
23+ .. md-tab-item :: Pip + PyPI (recommended )
2424
2525 .. code-block :: console
2626
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ def validate(
1818 schema_dict = cast (dict [str , Any ], schema )
1919 cls .check_schema (schema_dict )
2020 validator = cls (schema_dict , * args , ** kwargs )
21- error = best_match (
22- validator . evolve ( schema = schema_dict ). iter_errors ( instance )
23- )
24- if error is not None :
21+ errors = list ( validator . evolve ( schema = schema_dict ). iter_errors ( instance ))
22+ if errors :
23+ error = best_match ( errors )
24+ error . message = f"Validation failed: { error . message } "
2525 raise error
Original file line number Diff line number Diff line change 11from typing import Any
22from typing import cast
3-
43from jsonschema import _keywords
54from jsonschema import _legacy_keywords
65from jsonschema .validators import Draft202012Validator
Original file line number Diff line number Diff line change 1- from unittest import TestCase
2-
1+ import pytest
32from openapi_schema_validator import validate
43
54
6- class ValidateTest (TestCase ):
7- def test_validate_does_not_mutate_schema_adding_nullable_key (self ):
8- schema = {
9- "type" : "object" ,
10- "properties" : {
11- "email" : {"type" : "string" },
12- "enabled" : {
13- "type" : "boolean" ,
14- },
5+ @pytest .fixture (scope = "function" )
6+ def schema ():
7+ return {
8+ "type" : "object" ,
9+ "properties" : {
10+ "email" : {"type" : "string" },
11+ "enabled" : {
12+ "type" : "boolean" ,
1513 },
16- "example" : {"enabled" : False , "email" : "foo@bar.com" },
17- }
14+ },
15+ "example" : {"enabled" : False , "email" : "foo@bar.com" },
16+ }
17+
18+
19+ def test_validate_does_not_add_nullable_to_schema (schema ):
20+ """
21+ Verify that calling validate does not add the 'nullable' key to the schema
22+ """
23+ validate ({"email" : "foo@bar.com" }, schema )
24+ assert "nullable" not in schema ["properties" ]["email" ].keys ()
1825
19- validate ({"email" : "foo@bar.com" }, schema )
2026
21- self .assertTrue ("nullable" not in schema ["properties" ]["email" ].keys ())
27+ def test_validate_does_not_mutate_schema (schema ):
28+ """
29+ Verify that calling validate does not mutate the schema
30+ """
31+ original_schema = schema .copy ()
32+ validate ({"email" : "foo@bar.com" }, schema )
33+ assert schema == original_schema
You can’t perform that action at this time.
0 commit comments