# schema_salad.codegen_base

Base class for the generation of loaders from schema-salad definitions.

## Classes

`TypeDef` | Schema Salad type description.
`LazyInitDef` | Lazy initialization logic.
`CodeGenBase` | Abstract base class for schema salad code generators.

## Module Contents

class schema_salad.codegen_base.TypeDef

  Bases: `NamedTuple`

  Schema Salad type description.

  name: str
  init: str
  is_uri: bool = False
  scoped_id: bool = False
  ref_scope: int | None = 0
  loader_type: str | None = None
  instance_type: str | None = None
  abstract: bool = False

class schema_salad.codegen_base.LazyInitDef

  Bases: `NamedTuple`

  Lazy initialization logic.

  name: str
  init: str

class schema_salad.codegen_base.CodeGenBase

  Abstract base class for schema salad code generators.

  collected_types: collections.OrderedDict[str, TypeDef]
  lazy_inits: collections.OrderedDict[str, LazyInitDef]
  vocab: dict[str, str]
  declare_type(declared_type)

    Add this type to our collection, if needed.

    Parameters:

      declared_type (TypeDef)

    Return type:

      TypeDef

  add_lazy_init(lazy_init)

    Add lazy initialization logic for a given type.

    Parameters:

      lazy_init (LazyInitDef)

    Return type:

      None

  add_vocab(name, uri)

    Add the given name as an abbreviation for the given URI.

    Parameters:

      - name (str)

      - uri (str)

    Return type:

      None

  abstractmethod prologue()

    Trigger to generate the prolouge code.

    Return type:

      None

  static safe_name(name)
    Abstractmethod:

    Parameters:

      name (str)

    Return type:

      str

    Generate a safe version of the given name.

  abstractmethod begin_class(classname, extends, doc, abstract, field_names, idfield, optional_fields)

    Produce the header for the given class.

    Parameters:

      - classname (str)

      - extends (collections.abc.MutableSequence[str])

      - doc (str)

      - abstract (bool)

      - field_names (collections.abc.MutableSequence[str])

      - idfield (str)

      - optional_fields (set[str])

    Return type:

      None

  abstractmethod end_class(classname, field_names)

    Signal that we are done with this class.

    Parameters:

      - classname (str)

      - field_names (list[str])

    Return type:

      None

  abstractmethod type_loader(type_declaration, container=None, no_link_check=None)

    Parse the given type declaration and declare its components.

    Parameters:

      - type_declaration (list[Any] | dict[str, Any])

      - container (str | None)

      - no_link_check (bool | None)

    Return type:

      TypeDef

  abstractmethod declare_field(name, fieldtype, doc, optional, subscope)

    Output the code to load the given field.

    Parameters:

      - name (str)

      - fieldtype (TypeDef)

      - doc (str | None)

      - optional (bool)

      - subscope (str | None)

    Return type:

      None

  abstractmethod declare_id_field(name, fieldtype, doc, optional)

    Output the code to handle the given ID field.

    Parameters:

      - name (str)

      - fieldtype (TypeDef)

      - doc (str | None)

      - optional (bool)

    Return type:

      None

  abstractmethod uri_loader(inner, scoped_id, vocab_term, ref_scope, no_link_check=None)

    Construct the TypeDef for the given URI loader.

    Parameters:

      - inner (TypeDef)

      - scoped_id (bool)

      - vocab_term (bool)

      - ref_scope (int | None)

      - no_link_check (bool | None)

    Return type:

      TypeDef

  abstractmethod idmap_loader(field, inner, map_subject, map_predicate)

    Construct the TypeDef for the given mapped ID loader.

    Parameters:

      - field (str)

      - inner (TypeDef)

      - map_subject (str)

      - map_predicate (str | None)

    Return type:

      TypeDef

  abstractmethod typedsl_loader(inner, ref_scope)

    Construct the TypeDef for the given DSL loader.

    Parameters:

      - inner (TypeDef)

      - ref_scope (int | None)

    Return type:

      TypeDef

  abstractmethod epilogue(root_loader)

    Trigger to generate the epilouge code.

    Parameters:

      root_loader (TypeDef)

    Return type:

      None

  abstractmethod secondaryfilesdsl_loader(inner)

    Construct the TypeDef for secondary files.

    Parameters:

      inner (TypeDef)

    Return type:

      TypeDef