def METHOD_NAME(
    fields: Dict[str, ModelField], *, restore: bool = False
) -> None:
    for _, field in fields.items():
        if not restore:
            if isinstance(field.required, UndefinedType):
                raise Exception(f"{field.name} is a required field.")
            fields_map[field] = (field.type_, field.required)
            # If field has None allowed as a value
            # then it becomes a required field.
            if field.allow_none and field.name in kwargs:
                field.required = True
            else:
                field.required = False
            if inspect.isclass(field.type_) and issubclass(
                field.type_, BaseModel
            ):
                field.populate_validators()
                if field.sub_fields is not None:
                    for sub_field in field.sub_fields:
                        sub_field.type_ = field.type_
                        sub_field.populate_validators()
                METHOD_NAME(field.type_.__fields__)
        else:
            # No need to recursively de-optionalize once original types
            # are restored
            field.type_, field.required = fields_map[field]
            if field.sub_fields is not None:
                for sub_field in field.sub_fields:
                    sub_field.type_ = field.type_