Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added use_instances parameter to Marshmallow plugin #144

Merged
merged 2 commits into from Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -37,3 +37,4 @@ Contributors (chronological)
- Douglas Anderson `@djanderson <https://github.com/djanderson>`_
- Marat Sharafutdinov `@decaz <https://github.com/decaz>`_
- Daniel Radetsky `@dradetsky <https://github.com/dradetsky>`_
- Evgeny Seliverstov `@theirix <https://github.com/theirix>`_
7 changes: 5 additions & 2 deletions apispec/ext/marshmallow/__init__.py
Expand Up @@ -147,13 +147,16 @@ def resolve_parameters(spec, parameters):
return resolved


def resolve_schema_dict(spec, schema, dump=True):
def resolve_schema_dict(spec, schema, dump=True, use_instances=False):
if isinstance(schema, dict):
if (schema.get('type') == 'array' and 'items' in schema):
schema['items'] = resolve_schema_dict(spec, schema['items'])
return schema
plug = spec.plugins[NAME] if spec else {}
schema_cls = resolve_schema_cls(schema)
if isinstance(schema, marshmallow.Schema) and use_instances:
schema_cls = schema
else:
schema_cls = resolve_schema_cls(schema)
if schema_cls in plug.get('refs', {}):
ref_schema = {'$ref': '#/definitions/{0}'.format(plug['refs'][schema_cls])}
if getattr(schema, 'many', False):
Expand Down
5 changes: 3 additions & 2 deletions apispec/ext/marshmallow/swagger.py
Expand Up @@ -360,7 +360,8 @@ def schema2parameters(schema, **kwargs):


def fields2parameters(fields, schema=None, spec=None, use_refs=True,
default_in='body', name='body', required=False):
default_in='body', name='body', required=False,
use_instances=False):
"""Return an array of OpenAPI parameters given a mapping between field names and
:class:`Field <marshmallow.Field>` objects. If `default_in` is "body", then return an array
of a single parameter; else return an array of a parameter for each included field in
Expand All @@ -372,7 +373,7 @@ def fields2parameters(fields, schema=None, spec=None, use_refs=True,
if schema is not None:
# Prevent circular import
from apispec.ext.marshmallow import resolve_schema_dict
prop = resolve_schema_dict(spec, schema, dump=False)
prop = resolve_schema_dict(spec, schema, dump=False, use_instances=use_instances)
else:
prop = fields2jsonschema(fields, spec=spec, use_refs=use_refs, dump=False)

Expand Down