def generate_param(name, location, _type, required=None, _format=None):
    """
    Generates a parameter definition dynamically.
    """
    param = {
        'in': location,
        'type': _type,
        'name': name,
    }

    if required is not None:
        param['required'] = required

    if _format is not None:
        param['format'] = _format

    return param