Fix #178: handle non-object request bodies in the 3.0 renderer - #179
Open
dstrodtman wants to merge 1 commit into
Open
Fix #178: handle non-object request bodies in the 3.0 renderer#179dstrodtman wants to merge 1 commit into
dstrodtman wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #178.
Ports the guard cca8fc3 added to
openapi31.pyintoopenapi30.py, so a request body whose schema isn't an object is dumped whole instead of having its absentpropertieskey indexed. The two renderers carry separate copies of this path, so the same spec crashed withKeyError: '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 notypeat all raisesKeyError: 'type'on both renderers. Happy to follow up withschema.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.0renders 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.pyandtests/test_openapi.pyare both excluded from the black hook, so I matched the file's existingjson.dumps(..., indent=2, separators=(',', ':'))wrapping and single-quote style rather than reformatting. flake8 is clean on both.