Apologies if I'm missing something obvious here as I'm still figuring out Marshmallow and APISpec.
When we have a Model with a self-referential relationship, apispec is not able to parse the child relationships successfully. Here's an example (SQLAlchemy, Marshmallow-SQLAlchemy, APISpec, and Flask)
Models:
Parent_Child = Table('Parent_Child', Base.metadata,
Column('parent_id', Integer, ForeignKey('Entity.id')),
Column('child_id', Integer, ForeignKey('Entity.id'))
)
class Entity(Base):
__tablename__ = 'Entity'
id = Column(Integer, primary_key=True)
name = Column(String(80))
children = relationship('Entity', secondary='Parent_Child', primaryjoin=(id == Parent_Child.c.parent_id), secondaryjoin=(id == Parent_Child.c.child_id), lazy='joined', backref='parent')
Schema:
class EntitySchema(ModelSchema):
children = fields.Nested('self', many=True)
class Meta:
model = Entity
sqla_session = session
include_fk = True
EntitySerializer = EntitySchema()
APISpec to_dict output (note the Entity.children object reference)
{
'parameters': {},
'paths': {
'/entities': {}
},
'swagger': '2.0',
'info': {
'version': '1.0.0',
'title': 'M2M Nested Example'
},
'description': 'M2M Nested Example',
'definitions': {
'Entity': {
'properties': {
'children': .at 0x00000000048BF7B8 > ,
'id': {
'format': 'int32',
'type': 'integer'
},
'parent': {
'type': 'array',
'items': {
'type': 'string'
}
},
'name': {
'type': 'string'
}
}
}
}
}
Again, apologies if I've missed something obvious or this is a known issue. I can provide a complete sample app via gist if that would be helpful.
Thanks!
Apologies if I'm missing something obvious here as I'm still figuring out Marshmallow and APISpec.
When we have a Model with a self-referential relationship, apispec is not able to parse the child relationships successfully. Here's an example (SQLAlchemy, Marshmallow-SQLAlchemy, APISpec, and Flask)
Models:
Schema:
APISpec to_dict output (note the Entity.children object reference)
Again, apologies if I've missed something obvious or this is a known issue. I can provide a complete sample app via gist if that would be helpful.
Thanks!