Skip to content

Fix #171: close the request body's sourcecode block with a blank line - #175

Open
dstrodtman wants to merge 2 commits into
sphinx-contrib:masterfrom
dstrodtman:doc-1516-request-example-blank-line
Open

Fix #171: close the request body's sourcecode block with a blank line#175
dstrodtman wants to merge 2 commits into
sphinx-contrib:masterfrom
dstrodtman:doc-1516-request-example-blank-line

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #171.

The old renderer emits the .. sourcecode:: json directive for a request body and then goes straight on to the next :status ...: field at the outer indent, so docutils reports Explicit markup ends without a blank line; unexpected unindent and the build fails under -W.

This lands in both openapi30.py and openapi31.py. The two files carry separate copies of the request-body path and both were missing the blank line, so fixing only the 3.0 one would have merged as a no-op for every OAS 3.1 user. Verified by building a 3.1 spec with :request: against the 3.0-only fix: still exit 1 under -W with the same warning. There's a regression test per renderer.

One note on the # yield '' I pointed at in the issue: it's inside the loop over the body's lines, so uncommenting it in place would put a blank line between every line of the JSON rather than closing the block. The blank line belongs after the loop, which is what the response example path at lines 244-248 does.

I left it unconditional rather than guarding it the way the response path guards on example['value'].splitlines(). req_properties comes from json.dumps, which always returns at least {}, so the loop always emits at least one line and the guard would never be false here.

Verified against the reproducer in the issue: sphinx-build -W exits 1 on master with that warning, and exits 0 with the change applied, on both 3.0 and 3.1 specs.

There was no existing test covering the :request: output, so these are the first — TestOpenApi3HttpDomain.test_request_body and TestOpenApi31HttpDomain.test_request_body, each pinning the full markup including the blank line before :status. Both fail before the change.

openapi30.py and tests/test_openapi.py are excluded from the black hook, so I matched the surrounding '{indent}...'.format(**locals()) style there and kept the diff to the one line per file; openapi31.py is not excluded, and is black-clean.

Adjacent and deliberately left out of scope: on the 3.0 side, json.dumps(schema['properties'], ...) is still unguarded, so a non-object request body raises KeyError: 'properties'. The 3.1 side got a guard for that in cca8fc3, which was not ported across. Different bug, and this PR is one line per file — happy to file it separately if that's useful.

Close the request body's sourcecode block with a blank line

The old renderer emitted the `.. sourcecode:: json` directive for a
request body and then the next `:status ...:` field with no blank line
between them, so docutils reported explicit markup ending without a
blank line and the build failed under -W.

The blank line goes after the loop over the body's lines, mirroring the
response example path. A commented-out `yield ''` was already sitting
inside the loop, where it would have separated every line of JSON
instead of closing the block.

Signed-off-by: Douglas Strodtman <douglas@anyscale.com>
The 3.0 and 3.1 renderers carry separate copies of the request body
path, and both were missing the blank line, so fixing only the 3.0 one
left every 3.1 spec using :request: failing under -W for the same
reason.

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: emits a sourcecode block without a trailing blank line, warning under -W

1 participant