22
33import logging
44import warnings
5+ from collections .abc import Iterable
56from collections .abc import Iterator
67from collections .abc import Mapping
7- from functools import lru_cache
88from typing import cast
99
1010from jsonschema .exceptions import ValidationError
1919from openapi_spec_validator .schemas .types import AnySchema
2020from openapi_spec_validator .settings import OpenAPISpecValidatorSettings
2121from openapi_spec_validator .validation import keywords
22+ from openapi_spec_validator .validation .caches import CachedIterable
2223from openapi_spec_validator .validation .decorators import unwraps_iter
2324from openapi_spec_validator .validation .decorators import wraps_cached_iter
2425from openapi_spec_validator .validation .decorators import wraps_errors
@@ -67,6 +68,7 @@ def __init__(
6768 self .keyword_validators_registry = KeywordValidatorRegistry (
6869 self .keyword_validators
6970 )
71+ self ._cached_errors : CachedIterable [ValidationError ] | None = None
7072
7173 def validate (self ) -> None :
7274 for err in self .iter_errors ():
@@ -83,15 +85,19 @@ def root_validator(self) -> keywords.RootValidator:
8385 self .keyword_validators_registry ["__root__" ],
8486 )
8587
86- @unwraps_iter
87- @lru_cache (maxsize = None )
8888 @wraps_cached_iter
8989 @wraps_errors
90- def iter_errors (self ) -> Iterator [ValidationError ]:
90+ def _iter_errors (self ) -> Iterator [ValidationError ]:
9191 yield from self .schema_validator .iter_errors (self .schema )
9292
9393 yield from self .root_validator (self .schema_path )
9494
95+ @unwraps_iter
96+ def iter_errors (self ) -> Iterable [ValidationError ]:
97+ if getattr (self , "_cached_errors" , None ) is None :
98+ self ._cached_errors = self ._iter_errors ()
99+ return self ._cached_errors
100+
95101
96102class OpenAPIV2SpecValidator (SpecValidator ):
97103 schema_validator = openapi_v2_schema_validator
0 commit comments