Skip to content

Commit f00ddf3

Browse files
author
Joel Collins
committed
Fixed Mapping-type schemas in marshal_with
1 parent ebb0d79 commit f00ddf3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

labthings/server/decorators.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from flask import make_response, jsonify, abort, request
44
from http import HTTPStatus
55
from marshmallow.exceptions import ValidationError
6-
7-
from ..core.utilities import rupdate
6+
from collections import Mapping
87

98
from .spec import update_spec
109
from .schema import TaskSchema, Schema
@@ -42,10 +41,14 @@ def __init__(self, schema, code=200):
4241
self.schema = schema
4342
self.code = code
4443

45-
if isinstance(self.schema, Schema):
46-
self.converter = self.schema.jsonify
44+
if isinstance(self.schema, Mapping):
45+
self.converter = Schema.from_dict(self.schema)().jsonify
4746
elif isinstance(self.schema, Field):
4847
self.converter = lambda x: jsonify(self.schema._serialize(x, None, None))
48+
elif isinstance(self.schema, Schema):
49+
self.converter = self.schema.jsonify
50+
else:
51+
raise TypeError(f"Unsupported schema type {type(self.schema)} for marshal_with")
4952

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

0 commit comments

Comments
 (0)