'Decorator for versioning api methods.
Add the decorator to any method which takes a request object
as the first parameter and belongs to a class which inherits from
wsgi.Controller.
@min_ver: string representing minimum version
@max_ver: optional string representing maximum version'

@classmethod
def api_version(cls, min_ver, max_ver=None):

    def decorator(f):
        obj_min_ver = api_version.APIVersionRequest(min_ver)
        if max_ver:
            obj_max_ver = api_version.APIVersionRequest(max_ver)
        else:
            obj_max_ver = api_version.APIVersionRequest()
        func_name = f.__name__
        new_func = versioned_method.VersionedMethod(func_name, obj_min_ver, obj_max_ver, f)
        func_dict = getattr(cls, VER_METHOD_ATTR, {})
        if (not func_dict):
            setattr(cls, VER_METHOD_ATTR, func_dict)
        func_list = func_dict.get(func_name, [])
        if (not func_list):
            func_dict[func_name] = func_list
        func_list.append(new_func)
        is_intersect = Controller.check_for_versions_intersection(func_list)
        if is_intersect:
            raise exception.ApiVersionsIntersect(name=new_func.name, min_ver=new_func.start_version, max_ver=new_func.end_version)
        func_list.sort(key=(lambda f: f.start_version), reverse=True)
        return f
    return decorator
