Skip to content

Commit

Permalink
Fix issue with relative paths to specs
Browse files Browse the repository at this point in the history
It turns out that after cda6a47,
relative paths to spec apparently got broken due to missing `pathto()`
call in Jinja template.

Closes: 17
  • Loading branch information
ikalnytskyi committed Aug 5, 2018
1 parent 10dc1c4 commit 3b881bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,10 @@
1.5.1 (2018-08-05)
``````````````````

- Fix critical issue when relative path to an OpenAPI spec didn't work.

[:issue:`17`]

1.5.0 (2018-07-28)
``````````````````

Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/redoc.j2
Expand Up @@ -32,7 +32,7 @@
{% if embed %}
var spec = JSON.parse(document.getElementById("spec").innerHTML);
{% else %}
var spec = "{{ spec }}";
var spec = "{{ pathto(spec, 1) }}";
{% endif %}
Redoc.init(spec);
</script>
Expand Down
42 changes: 16 additions & 26 deletions tests/test_integration.py
Expand Up @@ -97,10 +97,10 @@ def test_openapi_spec_is_copied(run_sphinx, tmpdir):

@pytest.mark.parametrize('options, attributes', [
(None,
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml')}),
{}),
({},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml')}),
{}),
({'lazy-rendering': False,
'suppress-warnings': False,
Expand All @@ -112,62 +112,52 @@ def test_openapi_spec_is_copied(run_sphinx, tmpdir):
'native-scrollbars': False,
'untrusted-spec': False,
'expand-responses': []},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml')}),
{}),
({'lazy-rendering': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'lazy-rendering': ''}),
{'lazy-rendering': ''}),
({'suppress-warnings': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'suppress-warnings': ''}),
{'suppress-warnings': ''}),
({'hide-hostname': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'hide-hostname': ''}),
{'hide-hostname': ''}),
({'required-props-first': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'required-props-first': ''}),
{'required-props-first': ''}),
({'no-auto-auth': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'no-auto-auth': ''}),
{'no-auto-auth': ''}),
({'path-in-middle-panel': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'path-in-middle-panel': ''}),
{'path-in-middle-panel': ''}),
({'hide-loading': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'hide-loading': ''}),
{'hide-loading': ''}),
({'native-scrollbars': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'native-scrollbars': ''}),
{'native-scrollbars': ''}),
({'untrusted-spec': True},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'untrusted-spec': ''}),
{'untrusted-spec': ''}),
({'expand-responses': ['200', '404']},
{'spec-url': os.path.join('..', '..', '_specs', 'github.yml'),
'expand-responses': '200,404'}),
{'expand-responses': '200,404'}),
])
def test_redocjs_page_is_generated(run_sphinx, tmpdir, options, attributes):
run_sphinx(redoc_overwrite={'opts': options})

html = tmpdir.join('out').join('api', 'github', 'index.html').read()
soup = bs4.BeautifulSoup(html, 'html.parser')

# spec url is passed directly as the first arg to the redoc init
del attributes["spec-url"]

assert soup.title.string == 'Github API (v3)'
assert soup.redoc.attrs == attributes
assert soup.script.attrs['src'] == os.path.join(
'..', '..', '_static', 'redoc.js')

assert os.path.join('..', '..', '_specs', 'github.yml') \
in soup.find_all('script')[-1].text


def test_embedded_spec(run_sphinx, tmpdir):
run_sphinx(redoc_overwrite={'embed': True})
Expand Down

0 comments on commit 3b881bd

Please sign in to comment.