|
8 | 8 | from openapi_schema_validator import _validators as oas_validators
|
9 | 9 | from openapi_schema_validator._types import oas31_type_checker
|
10 | 10 |
|
11 |
| -BaseOAS30Validator = create( |
| 11 | +OAS30Validator = create( |
12 | 12 | meta_schema=_utils.load_schema("draft4"),
|
13 | 13 | validators={
|
14 | 14 | u"multipleOf": _validators.multipleOf,
|
|
76 | 76 | )
|
77 | 77 |
|
78 | 78 |
|
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__ |
81 | 85 |
|
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) |
84 | 90 |
|
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