api_docs: Fix enum strings in parameters to have quotes.

Fixes the rendering of enums to show strings with quotation marks,
while integers will continue to be rendered without quotation marks.

This allows for an empty string to be passed as an enum value and be
rendered as such in the documentation. Null will be rendered without
quotation marks, like integer values.
This commit is contained in:
Lauryn Menard 2022-01-27 20:18:59 +01:00 committed by Tim Abbott
parent 5e506a833f
commit a832a8a3af
1 changed files with 6 additions and 3 deletions

View File

@ -140,9 +140,12 @@ class APIArgumentsTablePreprocessor(Preprocessor):
for argument in arguments:
name = argument.get("argument") or argument.get("name")
description = argument["description"]
oneof = ["`" + str(item) + "`" for item in argument.get("schema", {}).get("enum", [])]
if oneof:
description += "\nMust be one of: {}.".format(", ".join(oneof))
enums = argument.get("schema", {}).get("enum")
if enums is not None:
formatted_enums = [
OBJECT_CODE_TEMPLATE.format(value=json.dumps(enum)) for enum in enums
]
description += "\nMust be one of: {}. ".format(", ".join(formatted_enums))
default = argument.get("schema", {}).get("default")
if default is not None: