INNER CODE UNIT · Python

_get_model_json_schema

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

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


def _extract_pydantic_models(module: ModuleType) -> List[type]:
    """
    Given a module, return a list of the pydantic models contained within it.
    """
    models: List[type] = []
    module_name = module.__name__

    for _, model in inspect.getmembers(module, _is_pydantic_model):
        models.append(model)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…