Skip to content

Commit

Permalink
fix: ensure DefaultJSONProvider default is called
Browse files Browse the repository at this point in the history
Update from @noirbee to ensure that flask.json.provider.DefaultJSONProvider.default is called.
  • Loading branch information
mfmarche committed Jan 2, 2025
1 parent c023ecc commit 3754200
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions connexion/apps/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ def run(self,


class FlaskJSONProvider(DefaultJSONProvider):
def __init__(self, app):
super().__init__(app)

def default(self, o):
@classmethod
def default(cls, o):
if isinstance(o, datetime.datetime):
if o.tzinfo:
# eg: '2015-09-25T23:14:42.588601+00:00'
Expand All @@ -177,22 +175,7 @@ def default(self, o):

class FlaskJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime.datetime):
if o.tzinfo:
# eg: '2015-09-25T23:14:42.588601+00:00'
return o.isoformat('T')
else:
# No timezone present - assume UTC.
# eg: '2015-09-25T23:14:42.588601Z'
return o.isoformat('T') + 'Z'

if isinstance(o, datetime.date):
return o.isoformat()

if isinstance(o, Decimal):
return float(o)

return json.JSONEncoder.default(self, o)
return FlaskJSONProvider.default(o)


class NumberConverter(werkzeug.routing.BaseConverter):
Expand Down

0 comments on commit 3754200

Please sign in to comment.