Skip to content

Fix #178: handle non-object request bodies in the 3.0 renderer - #179

Open
dstrodtman wants to merge 1 commit into
sphinx-contrib:masterfrom
dstrodtman:doc-1516-non-object-request-body-3-0
Open

Fix #178: handle non-object request bodies in the 3.0 renderer#179
dstrodtman wants to merge 1 commit into
sphinx-contrib:masterfrom
dstrodtman:doc-1516-non-object-request-body-3-0

Conversation

@dstrodtman

Copy link
Copy Markdown

Fixes #178.

Ports the guard cca8fc3 added to openapi31.py into openapi30.py, so a request body whose schema isn't an object is dumped whole instead of having its absent properties key indexed. The two renderers carry separate copies of this path, so the same spec crashed with KeyError: 'properties' on 3.0 and rendered on 3.1.

Ported verbatim rather than rewritten, since the point is 3.0/3.1 parity and cca8fc3 already settled the behaviour. As noted in the issue, that means 3.0 now inherits one pre-existing rough edge from the 3.1 version: the guard indexes schema["type"] directly, so a schema with no type at all raises KeyError: 'type' on both renderers. Happy to follow up with schema.get('type') across both files if you want that closed too — it seemed wrong to fold a behaviour change to the 3.1 renderer into a parity fix for the 3.0 one.

Verified with the reproducer from the issue: aborts with exit 2 on master, exits 0 with this applied. The same spec declared as openapi: 3.1.0 renders on master either way, which is what isolated the divergence.

The regression test asserts on the rendered request body rather than pinning the whole markup block. That block currently has no trailing blank line, which is #171 and the subject of a separate PR, so pinning the full markup here would couple this test to that change.

openapi30.py and tests/test_openapi.py are both excluded from the black hook, so I matched the file's existing json.dumps(..., indent=2, separators=(',', ':')) wrapping and single-quote style rather than reformatting. flake8 is clean on both.

Handle non-object request bodies in the 3.0 renderer

cca8fc3 branched on the schema type before dumping a request body, so a
schema that is not an object gets dumped whole rather than having its
absent 'properties' key indexed. That landed in the 3.1 renderer only,
and the two renderers carry separate copies of this path, so the same
spec crashed with KeyError: 'properties' on 3.0 and rendered on 3.1.

Ported verbatim for parity. The regression test asserts on the rendered
body rather than the whole markup block, since the block's trailing
blank line is the subject of a separate change.

Signed-off-by: Douglas Strodtman <douglas@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old renderer with :request: crashes with KeyError: 'properties' for a non-object request body on OAS 3.0

1 participant