Skip to content

Commit

Permalink
Corrected the Content-Type header for /basePath/swagger.json to retur…
Browse files Browse the repository at this point in the history
…n application/json and added a test for that
  • Loading branch information
jkozlowicz committed Jun 6, 2016
1 parent d39bbd1 commit bd25c5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion connexion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def add_swagger_json(self):
"""
logger.debug('Adding swagger.json: %s/swagger.json', self.base_url)
endpoint_name = "{name}_swagger_json".format(name=self.blueprint.name)
self.blueprint.add_url_rule('/swagger.json', endpoint_name, lambda: json.dumps(self.specification))
self.blueprint.add_url_rule('/swagger.json',
endpoint_name,
lambda: flask.jsonify(self.specification))

def add_swagger_ui(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_no_swagger_json_api(simple_api_spec_dir):
assert swagger_json.status_code == 404


def test_swagger_json_content_type(simple_app):
app_client = simple_app.app.test_client()

response = app_client.get('/v1.0/swagger.json', data={}) # type: flask.Response
assert response.status_code == 200
assert response.content_type == 'application/json'


def test_single_route(simple_app):
def route1():
return 'single 1'
Expand Down

0 comments on commit bd25c5c

Please sign in to comment.