Skip to main content

Model builder plugin for oarepo-polymorphic

Project description

Polymorphic model builder plugin

An OARepo Model Builder plugin to generate invenio sources for polymorphic models.

Installation

pip install oarepo-model-builder-polymorphic

Usage

What is polymorphic model?

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oarepo-model-builder-polymorphic-1.0.2.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page