From fa3b0b3f70a032a644b03ff306ca2cae1517a2ec Mon Sep 17 00:00:00 2001 From: Armand BENETEAU <50206418+ArmandBENETEAU@users.noreply.github.com> Date: Wed, 4 Sep 2019 05:55:52 +0200 Subject: [PATCH] Fix Go documentation generation (#172) * Correction of the "parameters" accessibility problem in the Go mapper The "parameters" attributes of the GoPythonMapper class instance was not accessible from the "output_rst" function used to create the .rst file. Thanks to this correction, the parameters are now accessible. * Enhance the template used to genertae the .rst file from the .go source file This modification allows to create a .rst file compatible with the last version of Sphinx. Without this correction, the creation of documentation was not possible. A "make html" command lead to an "AssertionError" Exception. --- autoapi/mappers/go.py | 3 +- autoapi/templates/go/base_member.rst | 44 ++++++++++++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/autoapi/mappers/go.py b/autoapi/mappers/go.py index dd966cf..5b65f5f 100644 --- a/autoapi/mappers/go.py +++ b/autoapi/mappers/go.py @@ -123,10 +123,11 @@ class GoPythonMapper(PythonMapperBase): # Second level self.imports = obj.get("imports", []) self.children = [] - self.parameters = map( + temp_parameters = map( lambda n: {"name": n["name"], "type": n["type"].lstrip("*")}, obj.get("parameters", []), ) + self.parameters = list(temp_parameters) self.docstring = obj.get("doc", "") # Go Specific diff --git a/autoapi/templates/go/base_member.rst b/autoapi/templates/go/base_member.rst index ad6e5b6..9bd6a92 100644 --- a/autoapi/templates/go/base_member.rst +++ b/autoapi/templates/go/base_member.rst @@ -1,26 +1,32 @@ -.. go:{{ obj.ref_type }}:: {{ obj.name }} {% if obj.type == 'func' %} + {# Creating the parameters line #} + {% set ns = namespace(tmpstring='') %} {% set argjoin = joiner(', ') %} - ({% for param in obj.parameters %} - {{ argjoin() }}{{ param.name }} {{ param.type }} - {% endfor %}) + {% for param in obj.parameters %} + {% set ns.tmpstring = ns.tmpstring ~ argjoin() ~ param.name ~ ' ' ~ param.type %} + {% endfor %} +.. {{ obj.ref_type }}:: {{ obj.name }}({{ ns.tmpstring }}) +{% else %} +.. go:{{ obj.ref_type }}:: {{ obj.name }} {% endif %} - {% macro render() %}{{ obj.docstring }}{% endmacro %} - {{ render()|indent(4) }} +{% macro render() %}{{ obj.docstring }}{% endmacro %} +{{ render()|indent(4) }} - {# Don't define parameter description here, that can be done in the block - above #} - {% for param in obj.parameters %} - :type {{ param.name }}: {{ param.type }} +{# Don't define parameter description here, that can be done in the block +above #} +{% for param in obj.parameters %} +:param {{ param.name }}: +:type {{ param.name }}: {{ param.type }} +{% endfor %} +{% if obj.returns %} +:rtype: {{ obj.returns.type }} +{% endif %} + +{% if obj.children %} + {% for child in obj.children|sort %} +{% macro render_child() %}{{ child.render() }}{% endmacro %} +{{ render_child()|indent(4) }} {% endfor %} - {% if obj.returns %} - :rtype: {{ obj.returns.type }} - {% endif %} +{% endif %} - {% if obj.children %} - {% for child in obj.children|sort %} - {% macro render_child() %}{{ child.render() }}{% endmacro %} - {{ render_child()|indent(4) }} - {% endfor %} - {% endif %}