Comments (5)
FYI, by accident I got this working. If you change 'self' to the name of the schema you're self-referencing, APISpec doesn't blow up.
Like so:
class EntitySchema(ModelSchema):
children = fields.Nested('EntitySchema', many=True)
class Meta:
model = Entity
sqla_session = session
include_fk = True
Not sure if this would be expected or desired behavior so leaving this open for now.
from apispec.
Thanks for the update, @whoiswes . I'm glad you found a workaround, but this still looks to be a bug--passing 'self'
should not break the code.
I would be open to a PR for this.
from apispec.
This bug is now fixed on dev
.
from apispec.
Hi, Can you explain to me the part of this fix:
is_unbound_self_referencing = not getattr(field, 'parent', None) and field.nested == 'self'
How might a self-referencing Nested field be 'bounded'?
Is the test for a parent is the same as a test for being an instance of SchemaABC (top-level abs baseclass)?
I am getting a MaxRecursion error on a self-referencing Nested field. This is fixed by adding a ref, but I'm curious why it is not USR without - the test for there being no parent fails, so the code here doesn't seem to handle.
Regards.
from apispec.
oooh, I think I see now - it if you supply a definition via:
spec.definition('foo', schema=FooSchema)
It will then be a "top-level" object since it has its own definition.
Then the name ('foo') is used to fill in the ref.
Is it possible to raise an exception when the object is self-referential but not top-level?
i.e."Self-referencing schema must provide named definition".
Incidentally, what happens when there are Schema that don't involve self-reference, but are recursive, e.g. involving two elements that refer to each other, A -> B -> A -> B -> A -> ...
If neither provides a definition then the same MaxRecursion will occur, without a Nested 'self'?
Regards.
from apispec.
Related Issues (20)
- Inconsistant behavior when using partial schema HOT 1
- Support with marshmallow.fields.Enum HOT 1
- exported marshmallow Enum fields should be arrays, not CSV strings HOT 1
- Marshmallow OpenApiConverter does not support str openapi_version HOT 4
- Incorrect handling of nullable enums in marshmallow converter HOT 2
- Issue with nested self-referencing schemas HOT 2
- Marshmallow plugin doesn't document the format of fields.DateTime() correctly HOT 3
- marshmallow plugin does not support `marshmallow.fields.Tuple` HOT 1
- What is the correct way to use add_attribute_function in the Marshmallow plugin? HOT 2
- additionalProperties=false is not set when using default Marshmallow schema options HOT 2
- callbacks in operation are not resolved to refs HOT 5
- wrong default value for 'name' in schema2parameters HOT 3
- parameters not being resolved for OAS3 'content' type parameters HOT 2
- Incorrect handling of marshmallow nested schema with allow_none=True in OpenAPI 3.1 HOT 4
- Incorrect handling of Union types HOT 2
- Deprecated flag is not configured correctly on query parameter objects
- sdist is missing `tox.ini` HOT 1
- Interest in taking Schema description from Schema.__doc__ docstring
- Incorrectly serialized format when using a range validator on a Decimal Marshmallow field HOT 10
- Document form data and images
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apispec.