# schema_salad.dlang_codegen

D code generator for a given schema salad definition.

## Classes

`DlangCodeGen` | Generation of D code for a given Schema Salad definition.

## Functions

`is_constant_field`(field) | Return True if a given field only takes the specified string.
`constant_fields_of`(type_) | Return a list of constant fields name from a given record schema.
`are_dispatchable`(types, parent_has_idmap) | Return True if a given list of types are dispatchable.

## Module Contents

class schema_salad.dlang_codegen.DlangCodeGen(base, target, examples, package, copyright_, parser_info, salad_version)

  Bases: `schema_salad.codegen_base.CodeGenBase`

  Generation of D code for a given Schema Salad definition.

  Parameters:

    - base (str)

    - target (IO[str])

    - examples (Optional[str])

    - package (str)

    - copyright_ (Optional[str])

    - parser_info (Optional[str])

    - salad_version (str)

  base_uri
  examples
  target
  package
  copyright
  parser_info
  salad_version
  doc_root_types: list[str] = []
  prologue()

    Trigger to generate the prolouge code.

    Return type:

      None

  epilogue(root_loader)

    Trigger to generate the epilouge code.

    Parameters:

      root_loader (schema_salad.codegen_base.TypeDef)

    Return type:

      None

  static safe_name(name)

    Generate a safe version of the given name.

    Parameters:

      name (str)

    Return type:

      str

  to_doc_comment(doc)

    Return an embedded documentation comments for a given string.

    Parameters:

      doc (Union[None, str, list[str]])

    Return type:

      str

  parse_record_field_type(type_, jsonld_pred, parent_has_idmap=False, has_default=False)

    Return an annotation string and a type string.

    Parameters:

      - type_ (Any)

      - jsonld_pred (Union[None, str, dict[str, Any]])

      - parent_has_idmap (bool)

      - has_default (bool)

    Return type:

      tuple[str, str]

  parse_record_field(field, parent_name=None)

    Return a declaration string for a given record field.

    Parameters:

      - field (dict[str, Any])

      - parent_name (Optional[str])

    Return type:

      str

  parse_record_schema(stype)

    Return a declaration string for a given record schema.

    Parameters:

      stype (dict[str, Any])

    Return type:

      str

  parse_enum(stype)

    Return a declaration string for a given enum schema.

    Parameters:

      stype (dict[str, Any])

    Return type:

      str

  parse_union(stype)

    Return a declaration string for a given union schema.

    Parameters:

      stype (dict[str, Any])

    Return type:

      str

  parse_map(stype)

    Return a declaration string for a given map schema.

    Parameters:

      stype (dict[str, Any])

    Return type:

      str

  parse(items)

    Generate D code from items and write it to target.

    Parameters:

      items (list[dict[str, Any]])

    Return type:

      None

schema_salad.dlang_codegen.is_constant_field(field)

  Return True if a given field only takes the specified string.

  Parameters:

    field (dict[str, Any])

  Return type:

    bool

schema_salad.dlang_codegen.constant_fields_of(type_)

  Return a list of constant fields name from a given record schema.

  Parameters:

    type_ (Any)

  Return type:

    set[str]

schema_salad.dlang_codegen.are_dispatchable(types, parent_has_idmap)

  Return True if a given list of types are dispatchable.

  Parameters:

    - types (list[Any])

    - parent_has_idmap (bool)

  Return type:

    bool