Skip to content

Commit

Permalink
Merge pull request #242 from jkozlowicz/swagger_json_content_type
Browse files Browse the repository at this point in the history
Corrected the Content-Type header for /basePath/swagger.json to retur…
  • Loading branch information
rafaelcaricio committed Jun 6, 2016
2 parents d39bbd1 + bfc68da commit d4d2f01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions connexion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

import copy
import json
import logging
import pathlib
import sys
Expand Down Expand Up @@ -222,7 +221,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
9 changes: 9 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ 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 d4d2f01

Please sign in to comment.