Mixin ClassesΒΆ

SQLAlchemy supports adding common functionality from a class to many other classes through mixin classes. OpenAlchemy supports this through the x-mixins extension property.

See also

SQLAlchemy mixin documentation

Documentation for SQLAlchemy mixin.

The following rules apply to the x-mixins extension property:

  • it can either be a string or a list of strings each of which defines one of the mixin classes and

  • each value must be the fully qualified dotted name of the class to use as the mixin. Everything before the last dot will be used to import the module and everything after will be used to retrieve the class from the module.

The following example adds the sqlalchemy_mixins.TimestampsMixin to the Employee model:

1
2
3
4
Employee:
  type: object
  x-mixins: sqlalchemy_mixins.TimestampsMixin
  ...

Alternatively, multiple mixins can be defined using a list:

1
2
3
4
5
6
Employee:
  type: object
  x-mixins:
    - sqlalchemy_mixins.TimestampsMixin
    - sqlalchemy_mixins.EagerLoadMixin
  ...

See also

sqlalchemy_mixins package

Package that defines some helpful SQLAlchemy mixins.