Skip to content

Commit

Permalink
Switch default renderer to new renderer
Browse files Browse the repository at this point in the history
We add the ability to use the old renderer in some tests.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Nov 21, 2024
1 parent 2b2cb63 commit 6cb06ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The extension provides two configuration options.
This must be one of the renderers defined in ``openapi_renderers``.

:Type: A string corresponding to the alias of a registered renderer.
:Default: ``'httpdomain:old'``
:Default: ``'httpdomain'``


Options
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpdomain": renderers.HttpdomainRenderer,
"httpdomain:old": renderers.HttpdomainOldRenderer,
}
_DEFAULT_RENDERER_NAME = "httpdomain:old"
_DEFAULT_RENDERER_NAME = "httpdomain"


def _register_rendering_directives(app, conf):
Expand Down
25 changes: 14 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,26 @@ def run_sphinx(tmpdir):
src = tmpdir.ensure('src', dir=True)
out = tmpdir.ensure('out', dir=True)

def run(spec, options={}):
def run(spec, *, options={}, openapi_default_renderer=None):
options_raw = '\n'.join([
' %s' % _format_option_raw(key, val)
for key, val in options.items()])

src.join('conf.py').write_text(
textwrap.dedent('''
import os
conf_py = textwrap.dedent('''
import os
project = 'sphinxcontrib-openapi-test'
copyright = '2017, Ihor Kalnytskyi'
project = 'sphinxcontrib-openapi-test'
copyright = '2017, Ihor Kalnytskyi'
extensions = ['sphinxcontrib.openapi']
source_suffix = '.rst'
master_doc = 'index'
'''),
encoding='utf-8')
extensions = ['sphinxcontrib.openapi']
source_suffix = '.rst'
master_doc = 'index'
''')

if openapi_default_renderer is not None:
conf_py += f"openapi_default_renderer = '{openapi_default_renderer}'\n"

src.join('conf.py').write_text(conf_py, encoding='utf-8')

src.join('index.rst').write_text(
'.. openapi:: %s\n%s' % (spec, options_raw),
Expand Down
12 changes: 10 additions & 2 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,11 @@ def test_openapi2_examples(tmpdir, run_sphinx):
py.path.local(spec).copy(tmpdir.join('src', 'test-spec.yml'))

with pytest.raises(ValueError) as excinfo:
run_sphinx('test-spec.yml', options={'examples': True})
run_sphinx(
'test-spec.yml',
options={'examples': True},
openapi_default_renderer='httpdomain:old',
)

assert str(excinfo.value) == (
'Rendering examples is not supported for OpenAPI v2.x specs.')
Expand All @@ -1880,7 +1884,11 @@ def test_openapi3_examples(tmpdir, run_sphinx, render_examples):
'v3.0',
'petstore.yaml')
py.path.local(spec).copy(tmpdir.join('src', 'test-spec.yml'))
run_sphinx('test-spec.yml', options={'examples': render_examples})
run_sphinx(
'test-spec.yml',
options={'examples': render_examples},
openapi_default_renderer='httpdomain:old',
)

rendered_html = tmpdir.join('out', 'index.html').read_text('utf-8')

Expand Down

0 comments on commit 6cb06ec

Please sign in to comment.