flask-restplus
flask-restplus copied to clipboard
polymorphic field provides no input validation for inheriting models
This may not be an issue but more of a feature clarification: polymorphic fields work on output , but not completely on input data it seems -
parent = api.model("parent", { "name":fields.String(required=True)", "class":fields.Discriminator()}) child = api.inherit("child",parent { "favfood":fields.String()"}) child2 = api.inherit("child",parent { "favdrink":fields.String()"})
mapping = { Child: child, Child2: child2 }
combined = api.model('combined', {'combined':fields.Polymorph(mapping)})
@api.expect(combined)
In this case, only the parent model field "name" and "class" will be validated, no child fields will be validated. In fact, the json schema for parent will not include the child.
I have tried to detect and separately use the child models to perform validation, but the child models contain a reference to the parent, and the parent itself is not in that child json schema definition.
Is this the expected behavior? Is there a recommendation for polymorphic input validation?