Skip to content

Commit

Permalink
Get rid of simplejson and fix detection of JSON renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Aug 12, 2020
1 parent a3a73d9 commit 69fdacf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cornice_swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import colander
from cornice import Service
from cornice.util import to_list
from pyramid.threadlocal import get_current_registry
import six
Expand Down Expand Up @@ -615,7 +616,12 @@ def _extract_operation_from_view(self, view, args):
# If 'produces' are not defined in the view, try get from renderers
renderer = args.get('renderer', '')

if "json" in renderer: # allows for "json" or "simplejson"
is_json_renderer = (
"json" in renderer # allows for "json" or "simplejson"
or renderer == Service.renderer # default renderer is json.
)

if is_json_renderer:
produces = ['application/json']
elif renderer == 'xml':
produces = ['text/xml']
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ plaster==1.0
plaster-pastedeploy==0.7
pyramid==1.10.4
repoze.lru==0.7
simplejson==3.17.2
six==1.15.0
translationstring==1.4
venusian==3.0.0
Expand Down
13 changes: 13 additions & 0 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ def test_swagger_call_is_deprecated(self, mocked):

class ExtractContentTypesTest(unittest.TestCase):

def test_default_renderer(self):
service = Service("IceCream", "/icecream/{flavour}")

class IceCream(object):
@service.get()
def view_get(self, request):
return self.request.validated

swagger = CorniceSwagger([service])
spec = swagger.generate()
self.assertEquals(spec['paths']['/icecream/{flavour}']['get']['produces'],
['application/json'])

def test_json_renderer(self):

service = Service("IceCream", "/icecream/{flavour}")
Expand Down

0 comments on commit 69fdacf

Please sign in to comment.