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

Question about fields.Nested and APISpec.definition() call order #31

alapshin opened this issue Oct 10, 2015 · 1 comment


Copy link

commented Oct 10, 2015

What is correct way to handle nested schemas with apispec? For example I have something like that

class BarSchema(Schema):
    baz = fields.String()

class FooSchema(Schema):
    bars = fields.Nested(BarSchema, many=True)

spec.definition('Foo', spec=FooSchema)
spec.definition('Bar', spec=BarSchema)

Generated definition for Foo includes Bar as nested object instead of referencing existing definition. Changing order of schemas in spec helps

spec.definition('Bar', spec=BarSchema)
spec.definition('Foo', spec=FooSchema)

but what about situations with circular dependencies when FooSchema nests BarSchema and vice versa?


This comment has been minimized.

Copy link

commented Dec 22, 2015

I think PR #44 solves the problem. given the schema you provided, the output will be the following, regardless of the order:

{"Foo": {"properties": {"bars": {"items": {"$ref": "#/definitions/Bar"}, "type": "array"}}}, "Bar": {"properties": {"baz": {"type": "string"}}}}

(on the assumption that you meant schema instead of spec in the spec definition argument)

@sloria sloria closed this Mar 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.