1818from openapi_spec_validator .schemas import openapi_v2_schema_validator
1919from openapi_spec_validator .schemas import openapi_v30_schema_validator
2020from openapi_spec_validator .schemas import openapi_v31_schema_validator
21+ from openapi_spec_validator .schemas .types import AnySchema
2122from openapi_spec_validator .validation import keywords
2223from openapi_spec_validator .validation .decorators import unwraps_iter
2324from openapi_spec_validator .validation .decorators import wraps_cached_iter
@@ -39,11 +40,10 @@ class SpecValidator:
3940
4041 def __init__ (
4142 self ,
42- schema : Schema ,
43+ schema : AnySchema ,
4344 base_uri : str = "" ,
4445 spec_url : Optional [str ] = None ,
4546 ) -> None :
46- self .schema = schema
4747 if spec_url is not None :
4848 warnings .warn (
4949 "spec_url parameter is deprecated. " "Use base_uri instead." ,
@@ -52,11 +52,16 @@ def __init__(
5252 base_uri = spec_url
5353 self .base_uri = base_uri
5454
55- self .spec = SchemaPath .from_dict (
56- self .schema ,
57- base_uri = self .base_uri ,
58- handlers = self .resolver_handlers ,
59- )
55+ if isinstance (schema , SchemaPath ):
56+ self .schema_path = schema
57+ self .schema = schema .contents ()
58+ else :
59+ self .schema = schema
60+ self .schema_path = SchemaPath .from_dict (
61+ self .schema ,
62+ base_uri = self .base_uri ,
63+ handlers = self .resolver_handlers ,
64+ )
6065
6166 self .keyword_validators_registry = KeywordValidatorRegistry (
6267 self .keyword_validators
@@ -84,12 +89,7 @@ def root_validator(self) -> keywords.RootValidator:
8489 def iter_errors (self ) -> Iterator [ValidationError ]:
8590 yield from self .schema_validator .iter_errors (self .schema )
8691
87- spec = SchemaPath .from_dict (
88- self .schema ,
89- base_uri = self .base_uri ,
90- handlers = self .resolver_handlers ,
91- )
92- yield from self .root_validator (spec )
92+ yield from self .root_validator (self .schema_path )
9393
9494
9595class OpenAPIV2SpecValidator (SpecValidator ):
0 commit comments