Skip to content

Commit b740b53

Browse files
authored
Merge pull request #49 from p1c2u/fix/oas30validator-subclassing-fix
oas30validator subclassing workaround
2 parents 00d2a69 + 7532fb3 commit b740b53

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

openapi_schema_validator/validators.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from openapi_schema_validator import _validators as oas_validators
99
from openapi_schema_validator._types import oas31_type_checker
1010

11-
BaseOAS30Validator = create(
11+
OAS30Validator = create(
1212
meta_schema=_utils.load_schema("draft4"),
1313
validators={
1414
u"multipleOf": _validators.multipleOf,
@@ -76,17 +76,19 @@
7676
)
7777

7878

79-
@attrs
80-
class OAS30Validator(BaseOAS30Validator):
79+
def _patch_validator_with_read_write_context(cls):
80+
"""Adds read/write context to jsonschema validator class"""
81+
# subclassing validator classes is not intended to
82+
# be part of their public API and will raise error
83+
# See https://github.com/p1c2u/openapi-schema-validator/issues/48
84+
original_init = cls.__init__
8185

82-
read: bool = attrib(default=None)
83-
write: bool = attrib(default=None)
86+
def __init__(self, *args, **kwargs):
87+
self.read = kwargs.pop("read", None)
88+
self.write = kwargs.pop("write", None)
89+
original_init(self, *args, **kwargs)
8490

85-
@classmethod
86-
def __init_subclass__(cls):
87-
# Subclassing validator classes is not intended to
88-
# be part of their public API
89-
# but it's the only way to pass extra context
90-
# to the validator
91-
# See https://github.com/p1c2u/openapi-schema-validator/issues/48
92-
pass
91+
cls.__init__ = __init__
92+
93+
94+
_patch_validator_with_read_write_context(OAS30Validator)

0 commit comments

Comments
 (0)