schema_salad.schema
===================

.. py:module:: schema_salad.schema

.. autoapi-nested-parse::

   Functions to process Schema Salad schemas.



Attributes
----------

.. autoapisummary::

   schema_salad.schema.SALAD_FILES
   schema_salad.schema.saladp
   schema_salad.schema.primitives
   schema_salad.schema.cached_metaschema
   schema_salad.schema.schema_type
   schema_salad.schema.Avro


Functions
---------

.. autoapisummary::

   schema_salad.schema.get_metaschema
   schema_salad.schema.add_namespaces
   schema_salad.schema.collect_namespaces
   schema_salad.schema.load_schema
   schema_salad.schema.load_and_validate
   schema_salad.schema.validate_doc
   schema_salad.schema.get_anon_name
   schema_salad.schema.replace_type
   schema_salad.schema.avro_field_name
   schema_salad.schema.make_valid_avro
   schema_salad.schema.deepcopy_strip
   schema_salad.schema.extend_and_specialize
   schema_salad.schema.make_avro
   schema_salad.schema.make_avro_schema
   schema_salad.schema.make_avro_schema_from_avro
   schema_salad.schema.shortname
   schema_salad.schema.print_inheritance
   schema_salad.schema.print_fieldrefs


Module Contents
---------------

.. py:data:: SALAD_FILES
   :type:  Final
   :value: ('metaschema.yml', 'metaschema_base.yml', 'salad.md', 'field_name.yml', 'import_include.md',...


.. py:data:: saladp
   :type:  Final
   :value: 'https://w3id.org/cwl/salad#'


.. py:data:: primitives
   :type:  Final

.. py:data:: cached_metaschema
   :type:  tuple[schema_salad.avro.schema.Names, list[dict[str, str]], schema_salad.ref_resolver.Loader] | None
   :value: None


.. py:function:: get_metaschema()

   Instantiate the metaschema.


.. py:function:: add_namespaces(metadata, namespaces)

   Collect the provided namespaces, checking for conflicts.


.. py:function:: collect_namespaces(metadata)

   Walk through the metadata object, collecting namespace declarations.


.. py:type:: schema_type
   :canonical: tuple[Loader, Names | SchemaParseException, dict[str, Any], Loader]


.. py:function:: 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


.. py:function:: 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


.. py:function:: validate_doc(schema_names, doc, loader, strict, strict_foreign_properties = False)

   Validate a document using the provided schema.


.. py:function:: get_anon_name(rec)

   Calculate a reproducible name for anonymous types.


.. py:function:: replace_type(items, spec, loader, found, find_embeds = True, deepen = True)

   Go through and replace types in the 'spec' mapping.


.. py:function:: 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.


.. py:type:: Avro
   :canonical: MutableMapping[str, Any] | MutableSequence[Any] | str


.. py:function:: make_valid_avro(items, alltypes, found, union = False, fielddef = False, vocab = None)

   Convert our schema to be more avro like.


.. py:function:: 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.


.. py:function:: extend_and_specialize(items, loader)

   Apply 'extend' and 'specialize' to fully materialize derived record types.


.. py:function:: make_avro(i, loader, metaschema_vocab = None)

.. py:function:: 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.


.. py:function:: make_avro_schema_from_avro(avro)

   Create avro.schema.Names from the given definitions.


.. py:function:: shortname(inputid)

   Return the last segment of the provided fragment or path.


.. py:function:: print_inheritance(doc, stream)

   Write a Grapviz inheritance graph for the supplied document.


.. py:function:: print_fieldrefs(doc, loader, stream)

   Write a GraphViz graph of the relationships between the fields.


