I have a set of APIs that were developed using Google Cloud Endpoints. The API methods look something like this:
我有一组使用Google Cloud Endpoints开发的API。 API方法看起来像这样:
@endpoints.method(message_types.VoidMessage, SystemAboutResponse, name="about", http_method="GET")
def about(self, request):
"""
Returns some simple information about the APIs.
Example:
...
"""
return SystemAboutResponse(version=API_VERSION)
I would like to use pydoc to generate documentation for the module that contains this method. However, when I do this, the docstring is not preserved due to the use of the endpoints.method decorator.
我想使用pydoc为包含此方法的模块生成文档。但是,当我这样做时,由于使用了endpoints.method装饰器,因此不保留docstring。
I have seen answers to other questions that show how to use functools.wraps (e.g. Python decorator handling docstrings) when writing your own decorators so that they will preserve the docstring of decorated methods. Is there some way to do this with Google Cloud Endpoints decorators, since I won't have control over the code for these decorators?
我已经看到了其他问题的答案,这些问题展示了在编写自己的装饰器时如何使用functools.wraps(例如Python装饰器处理文档字符串),以便它们保留装饰方法的文档字符串。有没有办法通过Google Cloud Endpoints装饰器执行此操作,因为我无法控制这些装饰器的代码?
1 个解决方案
#1
1
I ended up making a local modification to a copy of the endpoints library. The change is in api_config.py, specifically the apiserving_method_decorator
function of the method
decorator. I added the @wraps
decoration to the invoke_remote
function contained within apiserving_method_decorator
:
我最终对端点库的副本进行了本地修改。更改位于api_config.py中,特别是方法装饰器的apiserving_method_decorator函数。我将@wraps修饰添加到apiserving_method_decorator中包含的invoke_remote函数中:
def method(request_message=message_types.VoidMessage,
response_message=message_types.VoidMessage,
name=None,
path=None,
http_method='POST',
cache_control=None,
scopes=None,
audiences=None,
allowed_client_ids=None,
auth_level=None):
# ...
def apiserving_method_decorator(api_method):
# ...
@wraps(api_method)
def invoke_remote(service_instance, request):
# ...
I then make sure that this locally modified copy of the endpoints library is in my PYTHONPATH
when I run pydoc.
然后,当我运行pydoc时,我确保端点库的本地修改副本在我的PYTHONPATH中。
#1
1
I ended up making a local modification to a copy of the endpoints library. The change is in api_config.py, specifically the apiserving_method_decorator
function of the method
decorator. I added the @wraps
decoration to the invoke_remote
function contained within apiserving_method_decorator
:
我最终对端点库的副本进行了本地修改。更改位于api_config.py中,特别是方法装饰器的apiserving_method_decorator函数。我将@wraps修饰添加到apiserving_method_decorator中包含的invoke_remote函数中:
def method(request_message=message_types.VoidMessage,
response_message=message_types.VoidMessage,
name=None,
path=None,
http_method='POST',
cache_control=None,
scopes=None,
audiences=None,
allowed_client_ids=None,
auth_level=None):
# ...
def apiserving_method_decorator(api_method):
# ...
@wraps(api_method)
def invoke_remote(service_instance, request):
# ...
I then make sure that this locally modified copy of the endpoints library is in my PYTHONPATH
when I run pydoc.
然后,当我运行pydoc时,我确保端点库的本地修改副本在我的PYTHONPATH中。