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

Apispec doesn't play nicely with the schemas where fields are generated/modified on the fly #37

Closed
frol opened this issue Nov 23, 2015 · 0 comments

Comments

@frol
Copy link
Contributor

commented Nov 23, 2015

The following use-case doesn't work for me:

from marshmallow import Schema, fields
from apispec.ext.marshmallow.swagger import schema2jsonschema

class A(Schema):
    q = fields.Integer()
    def __init__(self, default_q=None):
        super(A, self).__init__()
        self.fields['q'].default = default_q

class B(Schema):
    a = fields.Nested(A(default_q=1))

schema2jsonschema(B)

The output jsonschema is:

{
    'properties': {
        'a': {
             'properties': {
                 'q': {
                     'format': 'int32',
                     'type': 'integer'
                 }
            }
        }
    }
}

I expect to see:

{
    'properties': {
        'a': {
             'properties': {
                 'q': {
                     'format': 'int32',
                     'type': 'integer',
                     'default': 1
                 }
            }
        }
    }
}

Here are the relevant source code lines:

Only a Nested schema class (not instance) will be analyzed for the Nested fields:
https://github.com/marshmallow-code/apispec/blob/dev/apispec/ext/marshmallow/swagger.py#L105

Only fields that are declared on class definition will be analyzed when running schema2parameters and schema2jsonschema

@sloria sloria closed this in bd0c847 Nov 27, 2015

sloria added a commit that referenced this issue Nov 27, 2015

Merge pull request #39 from frol/fix-nested-field2property
Fixed #37: Introspect fields of an instance (if passed) instead of falling back to a class

frol added a commit to frol/apispec that referenced this issue Feb 20, 2016

Improved further marshmallow-code#37: Schema instances introspection;…
… (bonus - resolved 'fields' global import and local arguments collision by importing marshmallow by itself)

sloria added a commit that referenced this issue Mar 6, 2016

Merge pull request #53 from frol/fix-schema-instances-introspection
Improved further #37: Schema instances introspection for `many=True`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.