An OARepo Model Builder plugin to generate invenio sources for polymorphic models.
pip install oarepo-model-builder-polymorphic
A polymorphic model is a dict that can be defined by multiple schemas. Which schema is used depends on a value of a present field (that is shared across all the schemas).
Polymorphic model can be used, for example, to express inheritance:
extension1{}:
disc: { type: keyword }
a: { type: keyword }
extension2{}:
disc: { type: keyword }
b: { type: keyword }
record:
properties:
a:
type: polymorphic
discriminator: disc
schemas:
"1": { use: "/extension1" }
"2": { use: "/extension2" }
The following are valid instances:
a:
disc: "1"
a: "blah"
---
a:
disc: "2"
b: "blah"
Invalid instance:
a:
disc: "3"
b: "blah"
---
a:
disc: "1"
a: "blah"
b: "blah"
If the "disc" field contains value "1", first extension schema will be used, if it contains value "2", second schema will be used. Any other value is not valid.