Skip to content

Commit 8ac445d

Browse files
committed
Allow single-field schemas
1 parent c4ddb0a commit 8ac445d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

labthings/server/spec/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def convert_schema(schema, spec: APISpec):
134134
return schema
135135
elif isinstance(schema, Mapping):
136136
return map2properties(schema, spec)
137+
elif isinstance(schema, Field):
138+
return field2property(schema, spec)
137139
else:
138140
raise TypeError(
139141
"Unsupported schema type. Ensure schema is a Schema class, or dictionary of Field objects"
@@ -156,3 +158,12 @@ def map2properties(schema, spec: APISpec):
156158
d[k] = v
157159

158160
return {"properties": d}
161+
162+
163+
def field2property(field, spec: APISpec):
164+
marshmallow_plugin = next(
165+
plugin for plugin in spec.plugins if isinstance(plugin, MarshmallowPlugin)
166+
)
167+
converter = marshmallow_plugin.converter
168+
169+
return converter.field2property(field)

0 commit comments

Comments
 (0)