Lifecycle#

Lifestyle methods mixin

class linkml.generators.common.lifecycle.LifecycleMixin[source]#

Mixin class for implementing lifecycle methods to modify the generation process without needing messy overrides and tiptoeing around parent generator classes.

Not all classes that inherit from the mixin will be able to implement all of the lifecycle methods. The generator class should make it clear which methods are supported in its documentation - no programmatic checking for lifecycle method support is available on first implementation.

Generators should not define any of the lifecycle methods themselves - the purpose is to allow downstream modification of the generation process with clear entrypoints and without needing to copy/paste code from the generator/call super() methods - if the Generator is also using the lifecycle method, the point of the mixin is lost.

The order that these methods are called may vary in different generators, but in general, if slots are generated hierarchically within classes as in the pydantic generator…

  • before_generate_schema()

  • before_generate_classes()

  • before_generate_class()

  • before_generate_slots()

  • before_generate_slot()

  • after_generate_slot()

  • after_generate_slots()

  • after_generate_class()

  • after_generate_classes()

  • after_generate_schema()

  • before_render_template()

  • after_render_template()

(Add other examples of ordering from other generators as implemented)

Each method should receive a SchemaView to get perspective on the current schema being built. The before_ methods should receive and return a single or list of Definitions and the after_ methods should receive and return a single or list of the appropriate BuildResult type.