# schema_salad.schema

Functions to process Schema Salad schemas.

## Attributes

`SALAD_FILES` |
`saladp` |
`primitives` |
`cached_metaschema` |
`schema_type` |
`Avro` |

## Functions

`get_metaschema`() | Instantiate the metaschema.
`add_namespaces`(metadata, namespaces) | Collect the provided namespaces, checking for conflicts.
`collect_namespaces`(metadata) | Walk through the metadata object, collecting namespace declarations.
`load_schema`(schema_ref[, cache]) | Load a schema that can be used to validate documents using load_and_validate.
`load_and_validate`(document_loader, avsc_names, ...[, ...]) | Load a document and validate it with the provided schema.
`validate_doc`(schema_names, doc, loader, strict[, ...]) | Validate a document using the provided schema.
`get_anon_name`(rec) | Calculate a reproducible name for anonymous types.
`replace_type`(items, spec, loader, found[, ...]) | Go through and replace types in the 'spec' mapping.
`avro_field_name`(url) | Turn a URL into an Avro-safe name.
`make_valid_avro`(items, alltypes, found[, union, ...]) | Convert our schema to be more avro like.
`deepcopy_strip`(item) | Make a deep copy of list and dict objects.
`extend_and_specialize`(items, loader) | Apply 'extend' and 'specialize' to fully materialize derived record types.
`make_avro`(i, loader[, metaschema_vocab]) |
`make_avro_schema`(i, loader[, metaschema_vocab]) | All in one convenience function.
`make_avro_schema_from_avro`(avro) | Create avro.schema.Names from the given definitions.
`shortname`(inputid) | Return the last segment of the provided fragment or path.
`print_inheritance`(doc, stream) | Write a Grapviz inheritance graph for the supplied document.
`print_fieldrefs`(doc, loader, stream) | Write a GraphViz graph of the relationships between the fields.

## Module Contents

schema_salad.schema.SALAD_FILES: Final = ('metaschema.yml', 'metaschema_base.yml', 'salad.md', 'field_name.yml', 'import_include.md',...

schema_salad.schema.saladp: Final = 'https://w3id.org/cwl/salad#'

schema_salad.schema.primitives: Final

schema_salad.schema.cached_metaschema: tuple[schema_salad.avro.schema.Names, list[dict[str, str]], schema_salad.ref_resolver.Loader] | None = None

schema_salad.schema.get_metaschema()

  Instantiate the metaschema.

  Return type:

    tuple[schema_salad.avro.schema.Names, list[dict[str, str]], schema_salad.ref_resolver.Loader]

schema_salad.schema.add_namespaces(metadata, namespaces)

  Collect the provided namespaces, checking for conflicts.

  Parameters:

    - metadata (collections.abc.Mapping[str, Any])

    - namespaces (collections.abc.MutableMapping[str, str])

  Return type:

    None

schema_salad.schema.collect_namespaces(metadata)

  Walk through the metadata object, collecting namespace declarations.

  Parameters:

    metadata (collections.abc.Mapping[str, Any])

  Return type:

    dict[str, str]

type schema_salad.schema.schema_type = tuple[Loader, Names | SchemaParseException, dict[str, Any], Loader]

schema_salad.schema.load_schema(schema_ref, cache=None)

  Load a schema that can be used to validate documents using load_and_validate.

  Returns:

    document_loader, avsc_names, schema_metadata, metaschema_loader

  Parameters:

    - schema_ref (schema_salad.utils.ResolveType)

    - cache (schema_salad.utils.CacheType | None)

  Return type:

    schema_type

schema_salad.schema.load_and_validate(document_loader, avsc_names, document, strict, strict_foreign_properties=False)

  Load a document and validate it with the provided schema.

  return data, metadata

  Parameters:

    - document_loader (schema_salad.ref_resolver.Loader)

    - avsc_names (schema_salad.avro.schema.Names)

    - document (ruamel.yaml.comments.CommentedMap | str)

    - strict (bool)

    - strict_foreign_properties (bool)

  Return type:

    tuple[Any, dict[str, Any]]

schema_salad.schema.validate_doc(schema_names, doc, loader, strict, strict_foreign_properties=False)

  Validate a document using the provided schema.

  Parameters:

    - schema_names (schema_salad.avro.schema.Names)

    - doc (schema_salad.utils.ResolveType)

    - loader (schema_salad.ref_resolver.Loader)

    - strict (bool)

    - strict_foreign_properties (bool)

  Return type:

    None

schema_salad.schema.get_anon_name(rec)

  Calculate a reproducible name for anonymous types.

  Parameters:

    rec (collections.abc.MutableMapping[str, str | dict[str, str] | list[str]])

  Return type:

    str

schema_salad.schema.replace_type(items, spec, loader, found, find_embeds=True, deepen=True)

  Go through and replace types in the ‘spec’ mapping.

  Parameters:

    - items (Any)

    - spec (dict[str, Any])

    - loader (schema_salad.ref_resolver.Loader)

    - found (set[str])

    - find_embeds (bool)

    - deepen (bool)

  Return type:

    Any

schema_salad.schema.avro_field_name(url)

  Turn a URL into an Avro-safe name.

  If the URL has no fragment, return this plain URL.

  Extract either the last part of the URL fragment past the slash, otherwise the whole fragment.

  Parameters:

    url (str)

  Return type:

    str

type schema_salad.schema.Avro = MutableMapping[str, Any] | MutableSequence[Any] | str

schema_salad.schema.make_valid_avro(items, alltypes, found, union=False, fielddef=False, vocab=None)

  Convert our schema to be more avro like.

  Parameters:

    - items (Avro)

    - alltypes (dict[str, dict[str, Any]])

    - found (set[str])

    - union (bool)

    - fielddef (bool)

    - vocab (dict[str, str] | None)

  Return type:

    Avro | collections.abc.MutableMapping[str, str] | str | list[Any | collections.abc.MutableMapping[str, str] | str]

schema_salad.schema.deepcopy_strip(item)

  Make a deep copy of list and dict objects.

  Intentionally do not copy attributes. This is to discard CommentedMap and CommentedSeq metadata which is very expensive with regular copy.deepcopy.

  Parameters:

    item (Any)

  Return type:

    Any

schema_salad.schema.extend_and_specialize(items, loader)

  Apply ‘extend’ and ‘specialize’ to fully materialize derived record types.

  Parameters:

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

    - loader (schema_salad.ref_resolver.Loader)

  Return type:

    list[dict[str, Any]]

schema_salad.schema.make_avro(i, loader, metaschema_vocab=None)
  Parameters:

    - i (list[dict[str, Any]])

    - loader (schema_salad.ref_resolver.Loader)

    - metaschema_vocab (dict[str, str] | None)

  Return type:

    list[Any]

schema_salad.schema.make_avro_schema(i, loader, metaschema_vocab=None)

  All in one convenience function.

  Call make_avro() and make_avro_schema_from_avro() separately if you need the intermediate result for diagnostic output.

  Parameters:

    - i (list[Any])

    - loader (schema_salad.ref_resolver.Loader)

    - metaschema_vocab (dict[str, str] | None)

  Return type:

    schema_salad.avro.schema.Names

schema_salad.schema.make_avro_schema_from_avro(avro)

  Create avro.schema.Names from the given definitions.

  Parameters:

    avro (list[Avro | dict[str, str] | str])

  Return type:

    schema_salad.avro.schema.Names

schema_salad.schema.shortname(inputid)

  Return the last segment of the provided fragment or path.

  Parameters:

    inputid (str)

  Return type:

    str

schema_salad.schema.print_inheritance(doc, stream)

  Write a Grapviz inheritance graph for the supplied document.

  Parameters:

    - doc (list[dict[str, Any]])

    - stream (IO[Any])

  Return type:

    None

schema_salad.schema.print_fieldrefs(doc, loader, stream)

  Write a GraphViz graph of the relationships between the fields.

  Parameters:

    - doc (list[dict[str, Any]])

    - loader (schema_salad.ref_resolver.Loader)

    - stream (IO[Any])

  Return type:

    None