INNER CODE UNIT · Python

_is_nullable

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

def _is_nullable(schema: Dict[str, Any]) -> bool:
    """
    Return true if a JSON schema has 'null' as one of its types.
    """
    if schema.get("type") == "null":
        return True
    if isinstance(schema.get("type"), list) and "null" in schema["type"]:
        return True
    if isinstance(schema.get("anyOf"), list):
        return any(_is_nullable(s) for s in schema["anyOf"])
    return False


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.
    """

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…