From a832a8a3af99bcdc6a0f07111b392758accbad35 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Thu, 27 Jan 2022 20:18:59 +0100 Subject: [PATCH] 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. --- zerver/lib/markdown/api_arguments_table_generator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/lib/markdown/api_arguments_table_generator.py b/zerver/lib/markdown/api_arguments_table_generator.py index 1e6d5627f5..85f7700d54 100644 --- a/zerver/lib/markdown/api_arguments_table_generator.py +++ b/zerver/lib/markdown/api_arguments_table_generator.py @@ -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: