Skip to content
Advertisement

How to generate pydoc documentation for Google Cloud Endpoints method?

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 (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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement