INNER CODE UNIT · Python

_get_model_config

phillipdupuis/pydantic-to-typescript · pydantic2ts/cli/script.py:126

def _get_model_config(model: Type[Any]) -> "Union[ConfigDict, Type[BaseConfig]]":
    """
    Return the 'config' for a pydantic model.
    In version 1 of pydantic, this is a class. In version 2, it's a dictionary.
    """
    if hasattr(model, "Config") and inspect.isclass(model.Config):
        return model.Config
    return model.model_config


def _get_model_json_schema(model: Type[Any]) -> Dict[str, Any]:
    """
    Generate the JSON schema for a pydantic model.
    """
    if _is_v1_model(model):
        return json.loads(model.schema_json())
    return model.model_json_schema(mode="serialization")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…