diff --git a/docs/index.rst b/docs/index.rst index b95460b..f8eed51 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 diff --git a/sphinxcontrib/openapi/__init__.py b/sphinxcontrib/openapi/__init__.py index 33908c0..420de0d 100644 --- a/sphinxcontrib/openapi/__init__.py +++ b/sphinxcontrib/openapi/__init__.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index d102a4a..411c641 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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), diff --git a/tests/test_openapi.py b/tests/test_openapi.py index 551f6a6..8f12582 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -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.') @@ -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')