Skip to content

Commit

Permalink
Merge pull request #758 from akaihola/fix-documentation-with-selectab…
Browse files Browse the repository at this point in the history
…le-output_type

Fix generated API documentation with selectable output type
  • Loading branch information
timothycrosley authored Mar 28, 2019
2 parents 4801e1d + fb468b0 commit 49e7463
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Ideally, within a virtual environment.
Changelog
=========

### 2.4.7 - March 28, 2019
- Fixed API documentation with selectable output types

### 2.4.6 - March 25, 2019
- Fixed issue #753 - 404 not found does not respect default output format.
- Documented the `--without-cython` option in `CONTRIBUTING.md`
Expand Down
2 changes: 1 addition & 1 deletion hug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def handle_404(request, response, *args, **kwargs):
response.data = hug.output_format.json(to_return, indent=4, separators=(',', ': '))
response.content_type = 'application/json; charset=utf-8'
else:
response.data = self.output_format(to_return)
response.data = self.output_format(to_return, request=request, response=response)
response.content_type = self.output_format.content_type

response.status = falcon.HTTP_NOT_FOUND
Expand Down
17 changes: 17 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""
import json
from unittest import mock

import marshmallow
from falcon import Request
Expand Down Expand Up @@ -149,6 +150,22 @@ def extend_with():
assert '/echo' in documentation['handlers']
assert '/test' not in documentation['handlers']


def test_basic_documentation_output_type_accept():
"""Ensure API documentation works with selectable output types"""
accept_output = hug.output_format.accept(
{'application/json': hug.output_format.json,
'application/pretty-json': hug.output_format.pretty_json},
default=hug.output_format.json)
with mock.patch.object(api.http, '_output_format', accept_output, create=True):
handler = api.http.documentation_404()
response = StartResponseMock()

handler(Request(create_environ(path='v1/doc')), response)

documentation = json.loads(response.data.decode('utf8'))['documentation']
assert 'handlers' in documentation and 'overview' in documentation


def test_marshmallow_return_type_documentation():

Expand Down

0 comments on commit 49e7463

Please sign in to comment.