mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 00:23:49 +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:
@@ -208,6 +208,7 @@ def get_openapi_param_example_value_as_string(
|
||||
# union type. But for this logic's purpose, it's good enough
|
||||
# to just check the first parameter.
|
||||
param_type = param["schema"]["oneOf"][0]["type"]
|
||||
|
||||
if param_type in ["object", "array"]:
|
||||
example_value = param.get("example", None)
|
||||
if not example_value:
|
||||
@@ -225,7 +226,9 @@ cURL example."""
|
||||
else:
|
||||
example_value = param.get("example", DEFAULT_EXAMPLE[param_type])
|
||||
if isinstance(example_value, bool):
|
||||
example_value = str(example_value).lower()
|
||||
# Booleans are effectively JSON-encoded, in that we pass
|
||||
# true/false, not the Python str(True) = "True"
|
||||
jsonify = True
|
||||
if jsonify:
|
||||
example_value = json.dumps(example_value)
|
||||
if curl_argument:
|
||||
|
||||
Reference in New Issue
Block a user