defroute_patch(cls):"""A decorator to add a patched `add_url_rule` method for `APIFlask` and `APIBlueprint` objects. The patched `add_url_rule` method will create a view function if passed a view class, and then generate spec from it. *Version changed: 0.10.0* - Remove the `route` decorator, and move the logic into `add_url_rule`. *Version added: 0.5.0* """defrecord_spec_for_view_class(view_func:ViewFuncType,view_class:ViewClassType)->ViewFuncType:# when the user call add_url_rule multiple times for one view class,# we only need to extract info from view class once since it will# loop all the methods of the class.ifhasattr(view_func,'_method_spec'):returnview_funcview_func._method_spec={}ifnothasattr(view_func,'_spec'):view_func._spec={}ifnotview_class.methods:# no methods definedreturnview_funcformethod_nameinview_class.methods:# type: ignore# method_name: ['GET', 'POST', ...]method=getattr(view_class,method_name.lower())# collect spec info from class attribute "decorators"ifhasattr(view_func,'_spec')andview_func._spec!={}:ifnothasattr(method,'_spec'):method._spec=view_func._specelse:forkey,valueinview_func._spec.items():ifvalueisnotNoneandmethod._spec.get(key)isNone:method._spec[key]=valueelse:ifnothasattr(method,'_spec'):method._spec={'no_spec':True}ifnotmethod._spec.get('summary'):method._spec['summary']=get_path_summary(method,f'{method_name.title()}{view_class.__name__}')method._spec['generated_summary']=Trueifnotmethod._spec.get('description'):method._spec['description']=get_path_description(method)method._spec['generated_description']=Trueview_func._method_spec[method_name]=method._specreturnview_funcdefadd_url_rule(self,rule:str,endpoint:str|None=None,view_func:ViewFuncOrClassType|None=None,provide_automatic_options:bool|None=None,**options:t.Any,):"""Record the spec for view classes before calling the actual `add_url_rule` method. When calling this method directly, the `view_func` argument can be a view function or a view function created by `ViewClass.as_view()`. It only accepts a view class when using the route decorator on a view class. """ifisinstance(view_func,type):# call as_view() for MethodView passed with @routeifendpointisNone:endpoint=view_func.__name__view_func=view_func.as_view(endpoint)# type: ignoreifhasattr(view_func,'view_class'):# view function created with MethodViewClass.as_view()view_class=view_func.view_class# type: ignoreifnotissubclass(view_class,MethodView):# skip View-based classview_func._spec={'hide':True}# type: ignoreelse:# record spec for MethodView classifhasattr(self,'enable_openapi')andself.enable_openapi:view_func=record_spec_for_view_class(view_func,view_class)# type: ignoresuper(cls,self).add_url_rule(rule,endpoint,view_func,provide_automatic_options=provide_automatic_options,**options,)cls.add_url_rule=add_url_rulereturncls