Skip to content

Commit cca8fc3

Browse files
committed
Handle non-object request bodies
Request bodies can be arrays, int, strings or booleans. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 0993077 commit cca8fc3

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

sphinxcontrib/openapi/openapi31.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,21 @@ def _get_type_from_schema(schema):
340340
request_content = properties.get("requestBody", {}).get("content", {})
341341
if request_content and "application/json" in request_content:
342342
schema = request_content["application/json"]["schema"]
343-
req_properties = json.dumps(
344-
schema["properties"], indent=2, separators=(",", ":")
345-
)
343+
346344
yield "{indent}**Request body:**".format(**locals())
347345
yield ""
348346
yield "{indent}.. sourcecode:: json".format(**locals())
349347
yield ""
348+
349+
if schema["type"] == "object":
350+
# if it's an object, focus on the properties of that object
351+
req_properties = json.dumps(
352+
schema["properties"], indent=2, separators=(",", ":")
353+
)
354+
else:
355+
# if it's another type, dump the whole thing
356+
req_properties = json.dumps(schema, indent=2, separators=(",", ":"))
357+
350358
for line in req_properties.splitlines():
351359
# yield indent + line
352360
yield "{indent}{indent}{line}".format(**locals())

0 commit comments

Comments
 (0)