繁体   English   中英

如何为Google Cloud Endpoints方法生成pydoc文档?

[英]How to generate pydoc documentation for Google Cloud Endpoints method?

我有一组使用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装饰器,因此不保留docstring。

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

我最终对端点库的副本进行了本地修改。 更改位于api_config.py中,特别是method装饰器的apiserving_method_decorator函数。 我加入了@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):
            # ...

然后,当我运行pydoc时,我确保端点库的本地修​​改副本在我的PYTHONPATH

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM