Skip to content

Commit 8ca5d34

Browse files
authored
Minor apidocs cleanups (#827)
* Improve API docs rendering Remove some of the cruft by using a custom template. * Fix JS error * Tweak docstrings * Remove some blank lines * Customize layout to get base CSS * Minor doc tweaks * Minor issue with hightlight * Move doctrees
1 parent 9df2285 commit 8ca5d34

File tree

66 files changed

+2598
-3189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2598
-3189
lines changed

.generator/templates/api.mustache

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class {{classname}}(object):
8787
{{#allParams}}
8888
'{{paramName}}': {
8989
{{#required}}'required': True,{{/required}}
90-
{{#isNullable}}'nullable': True,{{/isNullable}}
90+
{{#isNullable}}'nullable': True,{{/isNullable}}
9191
{{#isEnum}}
9292
'allowed_values': {
9393
{{#isNullable}}
@@ -111,14 +111,14 @@ class {{classname}}(object):
111111
},
112112
{{/hasValidation}}
113113
'openapi_types': ({{{dataType}}},),
114-
{{^isBodyParam}}
114+
{{^isBodyParam}}
115115
'attribute': '{{baseName}}',
116116
{{/isBodyParam}}
117117
'location': '{{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isCookieParam}}cookie{{/isCookieParam}}{{#isBodyParam}}body{{/isBodyParam}}',
118118
{{#collectionFormat}}
119119
'collection_format': '{{collectionFormat}}',
120120
{{/collectionFormat}}
121-
},
121+
},
122122
{{/allParams}}
123123
},
124124
headers_map={
@@ -170,25 +170,13 @@ class {{classname}}(object):
170170

171171
>>> thread = api.{{operationId}}({{#requiredParams}}{{^defaultValue}}{{paramName}}, {{/defaultValue}}{{/requiredParams}}{{#requiredParams}}{{#defaultValue}}{{paramName}}={{{defaultValue}}}, {{/defaultValue}}{{/requiredParams}}async_req=True)
172172
>>> result = thread.get()
173-
{{#requiredParams}}
174173

175-
{{/requiredParams}}
176-
{{#requiredParams}}
177-
{{^defaultValue}}{{#description}}
178-
:param {{paramName}}: {{{.}}}{{/description}}
174+
{{#requiredParams}}{{#description}} :param {{paramName}}: {{{.}}}{{#defaultValue}} Defaults to {{{defaultValue}}}.{{/defaultValue}}{{/description}}
179175
:type {{paramName}}: {{dataType}}
180-
{{/defaultValue}}
181-
{{/requiredParams}}
182-
{{#requiredParams}}
183-
{{#defaultValue}}{{#description}}
184-
:param {{paramName}}: {{{.}}} Defaults to {{{defaultValue}}}. Must be one of [{{{defaultValue}}}]{{/description}}
185-
:type {{paramName}}: {{dataType}}
186-
{{/defaultValue}}
187176
{{/requiredParams}}
188-
{{#optionalParams}}{{#description}}
189-
:param {{paramName}}: {{{.}}}{{#defaultValue}} If omitted the server will use the default value of {{{defaultValue}}}.{{/defaultValue}}{{/description}}
177+
{{#optionalParams}}{{#description}} :param {{paramName}}: {{{.}}}{{#defaultValue}} If omitted the server will use the default value of {{{defaultValue}}}.{{/defaultValue}}{{/description}}
190178
:type {{paramName}}: {{dataType}}, optional
191-
{{/optionalParams}}
179+
{{/optionalParams}}
192180
:param _return_http_data_only: Response data without head status
193181
code and headers. Default is True.
194182
:type _return_http_data_only: bool

.generator/templates/model_templates/methods_setattr_getattr_composed.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def __setitem__(self, name, value):
2-
"""set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
2+
"""Set the value of an attribute using square-bracket notation: `instance[attr] = val`."""
33
if name in self.required_properties:
44
self.__dict__[name] = value
55
return
@@ -15,7 +15,7 @@
1515
__unset_attribute_value__ = object()
1616

1717
def get(self, name, default=None):
18-
"""returns the value of an attribute or some default value if the attribute was not set"""
18+
"""Returns the value of an attribute or some default value if the attribute was not set."""
1919
if name in self.required_properties:
2020
return self.__dict__[name]
2121

@@ -46,7 +46,7 @@
4646
)
4747

4848
def __getitem__(self, name):
49-
"""get the value of an attribute using square-bracket notation: `instance[attr]`"""
49+
"""Get the value of an attribute using square-bracket notation: `instance[attr]`."""
5050
value = self.get(name, self.__unset_attribute_value__)
5151
if value is self.__unset_attribute_value__:
5252
raise ApiAttributeError(
@@ -57,7 +57,7 @@
5757
return value
5858

5959
def __contains__(self, name):
60-
"""used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`"""
60+
"""Used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`."""
6161

6262
if name in self.required_properties:
6363
return name in self.__dict__
@@ -70,4 +70,4 @@
7070
if name in model_instance._data_store:
7171
return True
7272

73-
return False
73+
return False
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
def __setitem__(self, name, value):
2-
"""set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
2+
"""Set the value of an attribute using square-bracket notation: `instance[attr] = val`."""
33
if name in self.required_properties:
44
self.__dict__[name] = value
55
return
66

77
self.set_attribute(name, value)
88

99
def get(self, name, default=None):
10-
"""returns the value of an attribute or some default value if the attribute was not set"""
10+
"""Returns the value of an attribute or some default value if the attribute was not set."""
1111
if name in self.required_properties:
1212
return self.__dict__[name]
1313

1414
return self.__dict__['_data_store'].get(name, default)
1515

1616
def __getitem__(self, name):
17-
"""get the value of an attribute using square-bracket notation: `instance[attr]`"""
17+
"""Get the value of an attribute using square-bracket notation: `instance[attr]`."""
1818
if name in self:
1919
return self.get(name)
2020

@@ -25,8 +25,8 @@
2525
)
2626

2727
def __contains__(self, name):
28-
"""used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`"""
28+
"""Used by `in` operator to check if an attribute value was set in an instance: `'attr' in instance`."""
2929
if name in self.required_properties:
3030
return name in self.__dict__
3131

32-
return name in self.__dict__['_data_store']
32+
return name in self.__dict__['_data_store']

.generator/templates/model_templates/methods_shared.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
return not self == other
88

99
def __setattr__(self, attr, value):
10-
"""set the value of an attribute using dot notation: `instance.attr = val`"""
10+
"""Set the value of an attribute using dot notation: `instance.attr = val`."""
1111
self[attr] = value
1212

1313
def __getattr__(self, attr):
14-
"""get the value of an attribute using dot notation: `instance.attr`"""
15-
return self.{{#attrNoneIfUnset}}get{{/attrNoneIfUnset}}{{^attrNoneIfUnset}}__getitem__{{/attrNoneIfUnset}}(attr)
14+
"""Get the value of an attribute using dot notation: `instance.attr`."""
15+
return self.{{#attrNoneIfUnset}}get{{/attrNoneIfUnset}}{{^attrNoneIfUnset}}__getitem__{{/attrNoneIfUnset}}(attr)

.generator/templates/model_utils.mustache

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ def validate_get_composed_info(constant_args, model_args, self):
17961796
additional_properties_type. This list can include self
17971797
:rtype: list
17981798
"""
1799-
# create composed_instances
1799+
# Create composed_instances
18001800
composed_instances = []
18011801
allof_instances = get_allof_instances(self, model_args, constant_args)
18021802
composed_instances.extend(allof_instances)
@@ -1805,34 +1805,14 @@ def validate_get_composed_info(constant_args, model_args, self):
18051805
composed_instances.append(oneof_instance)
18061806
anyof_instances = get_anyof_instances(self, model_args, constant_args)
18071807
composed_instances.extend(anyof_instances)
1808-
"""
1809-
set additional_properties_model_instances
1810-
additional properties must be evaluated at the schema level
1811-
so self's additional properties are most important
1812-
If self is a composed schema with:
1813-
- no properties defined in self
1814-
- additionalProperties: False
1815-
Then for object payloads every property is an additional property
1816-
and they are not allowed, so only empty dict is allowed
1817-
1818-
Properties must be set on all matching schemas
1819-
so when a property is assigned toa composed instance, it must be set on all
1820-
composed instances regardless of additionalProperties presence
1821-
keeping it to prevent breaking changes in v5.0.1
1822-
TODO remove cls._additional_properties_model_instances in 6.0.0
1823-
"""
1808+
18241809
additional_properties_model_instances = []
18251810
if self.additional_properties_type is not None:
18261811
additional_properties_model_instances = [self]
18271812

1828-
"""
1829-
no need to set properties on self in here, they will be set in __init__
1830-
By here all composed schema oneOf/anyOf/allOf instances have their properties set using
1831-
model_args
1832-
"""
18331813
discarded_args = get_discarded_args(self, composed_instances, model_args)
18341814

1835-
# map variable names to composed_instances
1815+
# Map variable names to composed_instances
18361816
var_name_to_model_instances = {}
18371817
for prop_name in model_args:
18381818
if prop_name not in discarded_args:

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Cache sphinx
3333
uses: actions/cache@v2
3434
with:
35-
path: site
35+
path: docs/.sphinx
3636
key: sphinx
3737

3838
- name: Build documentation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ src/datadog_api_client/version.py
33
.generator/lib
44
examples/generated
55
site
6+
docs/.sphinx
67

78
# VSCode
89
.vscode

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
name: Generate API docs
2525
stages: [manual]
2626
language: python
27-
entry: sphinx-apidoc --output-dir docs --force --no-toc src/datadog_api_client *apis *models *version.py
27+
entry: sphinx-apidoc --output-dir docs --force --no-toc --templatedir docs/_templates src/datadog_api_client *apis *models *version.py
2828
pass_filenames: false
2929
additional_dependencies:
3030
- Sphinx

docs/_templates/layout.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{%- extends "!layout.html" %}
2+
3+
{%- block extrahead %}
4+
<link rel="stylesheet" href="{{ pathto('_static/basic.css', 1) }}"/>
5+
<style>
6+
dt:target {
7+
background-color: white;
8+
}
9+
</style>
10+
11+
{{ super() }}
12+
{% endblock %}

docs/_templates/package.rst_t

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{%- macro automodule(modname, options) -%}
2+
.. automodule:: {{ modname }}
3+
{%- for option in options %}
4+
:{{ option }}:
5+
{%- endfor %}
6+
{%- endmacro %}
7+
8+
{%- macro toctree(docnames) -%}
9+
.. toctree::
10+
:maxdepth: {{ maxdepth }}
11+
{% for docname in docnames %}
12+
{{ docname }}
13+
{%- endfor %}
14+
{%- endmacro %}
15+
16+
{{- pkgname | e | heading }}
17+
18+
{%- if modulefirst %}
19+
{{ automodule(pkgname, automodule_options) }}
20+
{% endif %}
21+
22+
{%- if subpackages %}
23+
24+
{{ toctree(subpackages) }}
25+
{% endif %}
26+
27+
{%- if submodules %}
28+
{% if separatemodules %}
29+
{{ toctree(submodules) }}
30+
{% else %}
31+
{%- for submodule in submodules %}
32+
{% if show_headings %}
33+
{{- submodule.split(".")[-1] | e | heading(2) }}
34+
{% endif %}
35+
{{ automodule(submodule, automodule_options) }}
36+
{% endfor %}
37+
{%- endif %}
38+
{%- endif %}
39+
40+
{%- if not modulefirst %}
41+
42+
{{ automodule(pkgname, automodule_options) }}
43+
{% endif %}

0 commit comments

Comments
 (0)