schema_salad.schema

Functions to process Schema Salad schemas.

Module Contents

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)

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.

Attributes

SALAD_FILES

saladp

cached_metaschema

schema_type

Avro

schema_salad.schema.SALAD_FILES = ('metaschema.yml', 'metaschema_base.yml', 'salad.md', 'field_name.yml', 'import_include.md',...
schema_salad.schema.saladp = 'https://w3id.org/cwl/salad#'
schema_salad.schema.cached_metaschema: Tuple[schema_salad.avro.schema.Names, List[Dict[str, str]], schema_salad.ref_resolver.Loader] | 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 (Mapping[str, Any]) –

  • namespaces (MutableMapping[str, str]) –

Return type:

None

schema_salad.schema.collect_namespaces(metadata)

Walk through the metadata object, collecting namespace declarations.

Parameters:

metadata (Mapping[str, Any]) –

Return type:

Dict[str, str]

schema_salad.schema.schema_type
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 (Optional[schema_salad.utils.CacheType]) –

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:
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:
Return type:

None

schema_salad.schema.get_anon_name(rec)

Calculate a reproducible name for anonymous types.

Parameters:

rec (MutableMapping[str, Union[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:
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

schema_salad.schema.Avro
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 (Optional[Dict[str, str]]) –

Return type:

Union[Avro, MutableMapping[str, str], str, List[Union[Any, 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:
Return type:

List[Dict[str, Any]]

schema_salad.schema.make_avro(i, loader, metaschema_vocab=None)
Parameters:
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:
Return type:

schema_salad.avro.schema.Names

schema_salad.schema.make_avro_schema_from_avro(avro)
Parameters:

avro (List[Union[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:
Return type:

None