mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
openapi: Fix display for boolean example values.
The comments explain in some detail, but basically we were displaying the types for booleans incorrectly, and the types for strings in a somewhat confusing fashion. Fix this with comments explaining the logic. Using JSON dumping also results in our showing strings inside quotation marks in our examples, which seems net helpful. Thanks to ArunSankarKs for finding where we needed to change the codebase. Fixes #18021.
This commit is contained in:
@@ -124,7 +124,14 @@ class APIArgumentsTablePreprocessor(Preprocessor):
|
||||
# (path, querystring, form data...). We should document this detail.
|
||||
example = ""
|
||||
if "example" in argument:
|
||||
example = argument["example"]
|
||||
# We use this style without explicit JSON encoding for
|
||||
# integers, strings, and booleans.
|
||||
# * For booleans, JSON encoding correctly corrects for Python's
|
||||
# str(True)="True" not matching the encoding of "true".
|
||||
# * For strings, doing so nicely results in strings being quoted
|
||||
# in the documentation, improving readability.
|
||||
# * For integers, it is a noop, since json.dumps(3) == str(3) == "3".
|
||||
example = json.dumps(argument["example"])
|
||||
else:
|
||||
example = json.dumps(argument["content"]["application/json"]["example"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user