phase 1
This commit is contained in:
@@ -12,7 +12,7 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, List, get_type_hints
|
||||
|
||||
from ..helpers import get_origin_name, get_type_name, unwrap_optional
|
||||
from ..helpers import get_origin_name, get_type_name, is_dataclass_type, unwrap_optional
|
||||
from ..loader.schema import EnumDefinition, FieldDefinition, ModelDefinition
|
||||
from ..types import PYDANTIC_RESOLVERS
|
||||
from .base import BaseGenerator
|
||||
@@ -54,8 +54,9 @@ class PydanticGenerator(BaseGenerator):
|
||||
if hasattr(models, "get_shared_component"):
|
||||
content = self._generate_from_config(models)
|
||||
elif hasattr(models, "models"):
|
||||
all_models = models.models + getattr(models, "api_models", [])
|
||||
content = self._generate_from_definitions(
|
||||
models.models, getattr(models, "enums", [])
|
||||
all_models, getattr(models, "enums", [])
|
||||
)
|
||||
elif isinstance(models, tuple):
|
||||
content = self._generate_from_definitions(models[0], models[1])
|
||||
@@ -307,6 +308,11 @@ class PydanticGenerator(BaseGenerator):
|
||||
if isinstance(base, type) and issubclass(base, Enum)
|
||||
else None
|
||||
)
|
||||
or (
|
||||
PYDANTIC_RESOLVERS["dataclass"]
|
||||
if is_dataclass_type(base)
|
||||
else None
|
||||
)
|
||||
)
|
||||
result = resolver(base) if resolver else "str"
|
||||
return f"Optional[{result}]" if optional else result
|
||||
|
||||
@@ -8,7 +8,7 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, List, get_type_hints
|
||||
|
||||
from ..helpers import get_origin_name, get_type_name, unwrap_optional
|
||||
from ..helpers import get_origin_name, get_type_name, is_dataclass_type, unwrap_optional
|
||||
from ..loader.schema import EnumDefinition, FieldDefinition, ModelDefinition
|
||||
from ..types import TS_RESOLVERS
|
||||
from .base import BaseGenerator
|
||||
@@ -139,6 +139,11 @@ class TypeScriptGenerator(BaseGenerator):
|
||||
if isinstance(base, type) and issubclass(base, Enum)
|
||||
else None
|
||||
)
|
||||
or (
|
||||
TS_RESOLVERS["dataclass"]
|
||||
if is_dataclass_type(base)
|
||||
else None
|
||||
)
|
||||
)
|
||||
|
||||
result = resolver(base) if resolver else "string"
|
||||
|
||||
Reference in New Issue
Block a user