Skip to content

Commit 7095c26

Browse files
committed
Bound class-level overrised
1 parent dd6b514 commit 7095c26

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

openapi_schema_validator/validators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,6 @@ def _build_oas32_validator() -> Any:
179179

180180
OAS31Validator = _build_oas31_validator()
181181
OAS32Validator = _build_oas32_validator()
182+
183+
OAS31Validator.check_schema = classmethod(check_openapi_schema)
184+
OAS32Validator.check_schema = classmethod(check_openapi_schema)

tests/integration/test_validators.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from base64 import b64encode
33
from typing import Any
44
from typing import cast
5+
from unittest.mock import patch
56

67
import pytest
78
from jsonschema import SchemaError
@@ -34,7 +35,6 @@
3435
from openapi_schema_validator._dialects import OAS32_BASE_DIALECT_ID
3536
from openapi_schema_validator._dialects import OAS32_BASE_DIALECT_METASCHEMA
3637
from openapi_schema_validator._dialects import register_openapi_dialect
37-
from openapi_schema_validator.validators import check_openapi_schema
3838

3939

4040
class TestOAS30ValidatorFormatChecker:
@@ -1087,7 +1087,7 @@ def test_check_schema_accepts_oas32_discriminator_default_mapping(self):
10871087
},
10881088
}
10891089

1090-
check_openapi_schema(OAS32Validator, schema)
1090+
OAS32Validator.check_schema(schema)
10911091

10921092
def test_oas31_check_schema_rejects_discriminator_default_mapping(self):
10931093
schema = {
@@ -1099,7 +1099,21 @@ def test_oas31_check_schema_rejects_discriminator_default_mapping(self):
10991099
}
11001100

11011101
with pytest.raises(SchemaError):
1102-
check_openapi_schema(OAS31Validator, schema)
1102+
OAS31Validator.check_schema(schema)
1103+
1104+
def test_oas32_check_schema_does_not_fetch_remote_metaschemas(self):
1105+
schema = {
1106+
"type": "object",
1107+
"discriminator": {
1108+
"propertyName": "kind",
1109+
"defaultMapping": "#/components/schemas/Pet",
1110+
},
1111+
}
1112+
1113+
with patch("urllib.request.urlopen") as urlopen:
1114+
OAS32Validator.check_schema(schema)
1115+
1116+
urlopen.assert_not_called()
11031117

11041118

11051119
class TestOAS30StrictValidator:

0 commit comments

Comments
 (0)