api docs: Display the default value of parameters when present.

Whenever a parameter for an endpoint in our REST API has a default
value, it is displayed under the "Description" section of the
arguments table in the docs.

This way, we don't need to explicitly indicate the default values in the
description, thus avoiding duplicate information in the OpenAPI source.
This commit is contained in:
Yago González 2018-07-26 20:48:34 +02:00 committed by Tim Abbott
parent 038f50b05e
commit 95ce311686
1 changed files with 7 additions and 1 deletions

View File

@ -115,11 +115,17 @@ class APIArgumentsTablePreprocessor(Preprocessor):
md_engine = markdown.Markdown(extensions=[])
for argument in arguments:
description = argument['description']
oneof = ['`' + item + '`'
for item in argument.get('schema', {}).get('enum', [])]
description = argument['description']
if oneof:
description += '\nMust be one of: {}.'.format(', '.join(oneof))
default = argument.get('schema', {}).get('default')
if default is not None:
description += '\nDefaults to `{}`.'.format(ujson.dumps(default))
# TODO: Swagger allows indicating where the argument goes
# (path, querystring, form data...). A column in the table should
# be added for this.