feature: add instance level ref cache #63

Merged
HideyoshiNakazone merged 12 commits from feature/add-instance-level-ref-cache into main 2025-11-25 00:07:55 +00:00
Showing only changes of commit 4de711075e - Show all commits

View File

@@ -26,25 +26,18 @@ class SchemaConverter:
self, self,
schema: JSONSchema, schema: JSONSchema,
ref_cache: Optional[RefCacheDict] = None, ref_cache: Optional[RefCacheDict] = None,
with_clean_cache: bool = True,
) -> type[BaseModel]: ) -> type[BaseModel]:
""" """
Converts a JSON Schema to a Pydantic model. Converts a JSON Schema to a Pydantic model.
:param schema: The JSON Schema to convert. :param schema: The JSON Schema to convert.
:param ref_cache: An optional reference cache to use during conversion, if provided `with_clean_cache` will be ignored. :param ref_cache: An optional reference cache to use during conversion.
:param with_clean_cache: Whether to use a clean reference cache for this conversion. Set to True due to API compatibility. Will be set to False in future versions.
:return: The generated Pydantic model. :return: The generated Pydantic model.
""" """
if ref_cache is None: return self.build(schema, ref_cache or self._ref_cache)
ref_cache = self._ref_cache
return self.build(schema, ref_cache, with_clean_cache)
@staticmethod @staticmethod
def build( def build(
schema: JSONSchema, schema: JSONSchema, ref_cache: Optional[RefCacheDict] = None
ref_cache: Optional[RefCacheDict] = None,
with_clean_cache: bool = True,
) -> type[BaseModel]: ) -> type[BaseModel]:
""" """
Converts a JSON Schema to a Pydantic model. Converts a JSON Schema to a Pydantic model.
@@ -53,7 +46,7 @@ class SchemaConverter:
:param with_clean_cache: Whether to use a clean reference cache for this conversion. Set to rue due to API compatibility. Will be set to False in future versions. :param with_clean_cache: Whether to use a clean reference cache for this conversion. Set to rue due to API compatibility. Will be set to False in future versions.
:return: The generated Pydantic model. :return: The generated Pydantic model.
""" """
if ref_cache is None or with_clean_cache: if ref_cache is None:
ref_cache = dict() ref_cache = dict()
try: try: