I have a set of APIs that were developed using Google Cloud Endpoints. The API methods look something like this:
@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.
I have seen answers to other questions that show how to use functools.wraps (eg 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?
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
:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.