From f9b64e0a214d9ecbe583289c6e8d6752e1d9cbb4 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Thu, 21 Jan 2021 15:49:30 +0900 Subject: [PATCH] Fix remote obj cache (#313) * Fix remote obj cache * fix key on remote_object_cache --- datamodel_code_generator/parser/jsonschema.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/datamodel_code_generator/parser/jsonschema.py b/datamodel_code_generator/parser/jsonschema.py index 96343c97c..4fcb0bab5 100644 --- a/datamodel_code_generator/parser/jsonschema.py +++ b/datamodel_code_generator/parser/jsonschema.py @@ -785,19 +785,25 @@ def _get_ref_body_from_url(self, ref: str) -> Dict[Any, Any]: return ref_body def _get_ref_body_from_remote(self, ref: str) -> Dict[Any, Any]: - cached_ref_body: Optional[Dict[str, Any]] = self.remote_object_cache.get(ref) - if cached_ref_body: - return cached_ref_body # Remote Reference – $ref: 'document.json' Uses the whole document located on the same server and in # the same location. TODO treat edge case if self.current_source_path and len(self.current_source_path.parts) > 1: full_path = self.base_path / self.current_source_path.parent / ref else: full_path = self.base_path / ref + + ref_full_path = str(full_path) + + cached_ref_body: Optional[Dict[str, Any]] = self.remote_object_cache.get( + ref_full_path + ) + if cached_ref_body: + return cached_ref_body + # yaml loader can parse json data. with full_path.open(encoding=self.encoding) as f: ref_body = load_yaml(f) - self.remote_object_cache[ref] = ref_body + self.remote_object_cache[ref_full_path] = ref_body return ref_body def parse_ref(self, obj: JsonSchemaObject, path: List[str]) -> None: