Skip to content

Commit

Permalink
Fixed Mapping-type schemas in marshal_with
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jan 20, 2020
1 parent ebb0d79 commit f00ddf3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions labthings/server/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from flask import make_response, jsonify, abort, request
from http import HTTPStatus
from marshmallow.exceptions import ValidationError

from ..core.utilities import rupdate
from collections import Mapping

from .spec import update_spec
from .schema import TaskSchema, Schema
Expand Down Expand Up @@ -42,10 +41,14 @@ def __init__(self, schema, code=200):
self.schema = schema
self.code = code

if isinstance(self.schema, Schema):
self.converter = self.schema.jsonify
if isinstance(self.schema, Mapping):
self.converter = Schema.from_dict(self.schema)().jsonify
elif isinstance(self.schema, Field):
self.converter = lambda x: jsonify(self.schema._serialize(x, None, None))
elif isinstance(self.schema, Schema):
self.converter = self.schema.jsonify
else:
raise TypeError(f"Unsupported schema type {type(self.schema)} for marshal_with")

def __call__(self, f):
# Pass params to call function attribute for external access
Expand Down

0 comments on commit f00ddf3

Please sign in to comment.