5

我有一组使用 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)

我想使用 pydoc 为包含此方法的模块生成文档。但是,当我这样做时,由于使用了 endpoints.method 装饰器,文档字符串不会被保留。

我已经看到了其他问题的答案,这些问题展示了在编写自己的装饰器时如何使用 functools.wraps(例如Python 装饰器处理文档字符串),以便它们保留装饰方法的文档字符串。有没有办法使用 Google Cloud Endpoints 装饰器来做到这一点,因为我无法控制这些装饰器的代码?

4

1 回答 1

1

我最终对端点库的副本进行了本地修改。变化在 api_config.py 中,具体是装饰器的apiserving_method_decorator功能。method我将@wraps装饰添加到包含在其中的invoke_remote函数中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):
            # ...

PYTHONPATH然后,当我运行 pydoc 时,我确保端点库的这个本地修改的副本在我的文件中。

于 2014-02-17T18:49:23.573 回答