Skip to content

Commit

Permalink
Allow single-field schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed Jan 17, 2020
1 parent c4ddb0a commit 8ac445d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions labthings/server/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def convert_schema(schema, spec: APISpec):
return schema
elif isinstance(schema, Mapping):
return map2properties(schema, spec)
elif isinstance(schema, Field):
return field2property(schema, spec)
else:
raise TypeError(
"Unsupported schema type. Ensure schema is a Schema class, or dictionary of Field objects"
Expand All @@ -156,3 +158,12 @@ def map2properties(schema, spec: APISpec):
d[k] = v

return {"properties": d}


def field2property(field, spec: APISpec):
marshmallow_plugin = next(
plugin for plugin in spec.plugins if isinstance(plugin, MarshmallowPlugin)
)
converter = marshmallow_plugin.converter

return converter.field2property(field)

0 comments on commit 8ac445d

Please sign in to comment.