INNER CODE UNIT · Python
_is_pydantic_model
phillipdupuis/pydantic-to-typescript · pydantic2ts/cli/script.py:106
def _is_pydantic_model(obj: Any) -> bool:
"""
Return true if an object is a concrete model for either V1 or V2 of pydantic.
"""
return _is_v1_model(obj) or _is_v2_model(obj)
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