INNER CODE UNIT · Python
_schema_generation_overrides
phillipdupuis/pydantic-to-typescript · pydantic2ts/cli/script.py:241
def _schema_generation_overrides(
model: Type[Any],
) -> Generator[None, None, None]:
"""
Temporarily override the 'extra' setting for a model,
changing it to 'forbid' unless it was EXPLICITLY set to 'allow'.
This prevents '[k: string]: any' from automatically being added to every interface.
"""
revert: Dict[str, Any] = {}
config = _get_model_config(model)
try:
if isinstance(config, dict):
if config.get("extra") != "allow":
revert["extra"] = config.get("extra")
config["extra"] = "forbid"
else:
if config.extra != "allow":
revert["extra"] = config.extra