Skip to content

Commit a5dc436

Browse files
committed
Switch default renderer to new renderer
We add the ability to use the old renderer in some tests. Signed-off-by: Stephen Finucane <[email protected]>
1 parent 9afa811 commit a5dc436

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The extension provides two configuration options.
5151
This must be one of the renderers defined in ``openapi_renderers``.
5252

5353
:Type: A string corresponding to the alias of a registered renderer.
54-
:Default: ``'httpdomain:old'``
54+
:Default: ``'httpdomain'``
5555

5656

5757
Options

sphinxcontrib/openapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"httpdomain": renderers.HttpdomainRenderer,
2525
"httpdomain:old": renderers.HttpdomainOldRenderer,
2626
}
27-
_DEFAULT_RENDERER_NAME = "httpdomain:old"
27+
_DEFAULT_RENDERER_NAME = "httpdomain"
2828

2929

3030
def _register_rendering_directives(app, conf):

tests/conftest.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,26 @@ def run_sphinx(tmpdir):
4545
src = tmpdir.ensure('src', dir=True)
4646
out = tmpdir.ensure('out', dir=True)
4747

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

53-
src.join('conf.py').write_text(
54-
textwrap.dedent('''
55-
import os
53+
conf_py = textwrap.dedent('''
54+
import os
5655
57-
project = 'sphinxcontrib-openapi-test'
58-
copyright = '2017, Ihor Kalnytskyi'
56+
project = 'sphinxcontrib-openapi-test'
57+
copyright = '2017, Ihor Kalnytskyi'
5958
60-
extensions = ['sphinxcontrib.openapi']
61-
source_suffix = '.rst'
62-
master_doc = 'index'
63-
'''),
64-
encoding='utf-8')
59+
extensions = ['sphinxcontrib.openapi']
60+
source_suffix = '.rst'
61+
master_doc = 'index'
62+
''')
63+
64+
if openapi_default_renderer is not None:
65+
conf_py += f"openapi_default_renderer = '{openapi_default_renderer}'\n"
66+
67+
src.join('conf.py').write_text(conf_py, encoding='utf-8')
6568

6669
src.join('index.rst').write_text(
6770
'.. openapi:: %s\n%s' % (spec, options_raw),

tests/test_openapi.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,11 @@ def test_openapi2_examples(tmpdir, run_sphinx):
18651865
py.path.local(spec).copy(tmpdir.join('src', 'test-spec.yml'))
18661866

18671867
with pytest.raises(ValueError) as excinfo:
1868-
run_sphinx('test-spec.yml', options={'examples': True})
1868+
run_sphinx(
1869+
'test-spec.yml',
1870+
options={'examples': True},
1871+
openapi_default_renderer='httpdomain:old',
1872+
)
18691873

18701874
assert str(excinfo.value) == (
18711875
'Rendering examples is not supported for OpenAPI v2.x specs.')
@@ -1880,7 +1884,11 @@ def test_openapi3_examples(tmpdir, run_sphinx, render_examples):
18801884
'v3.0',
18811885
'petstore.yaml')
18821886
py.path.local(spec).copy(tmpdir.join('src', 'test-spec.yml'))
1883-
run_sphinx('test-spec.yml', options={'examples': render_examples})
1887+
run_sphinx(
1888+
'test-spec.yml',
1889+
options={'examples': render_examples},
1890+
openapi_default_renderer='httpdomain:old',
1891+
)
18841892

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

0 commit comments

Comments
 (0)