schema_salad.schema
Functions to process Schema Salad schemas.
Attributes
Functions
Instantiate the metaschema. |
|
|
Collect the provided namespaces, checking for conflicts. |
|
Walk through the metadata object, collecting namespace declarations. |
|
Load a schema that can be used to validate documents using load_and_validate. |
|
Load a document and validate it with the provided schema. |
|
Validate a document using the provided schema. |
|
Calculate a reproducible name for anonymous types. |
|
Go through and replace types in the 'spec' mapping. |
|
Turn a URL into an Avro-safe name. |
|
Convert our schema to be more avro like. |
|
Make a deep copy of list and dict objects. |
|
Apply 'extend' and 'specialize' to fully materialize derived record types. |
|
|
|
All in one convenience function. |
Create avro.schema.Names from the given definitions. |
|
|
Return the last segment of the provided fragment or path. |
|
Write a Grapviz inheritance graph for the supplied document. |
|
Write a GraphViz graph of the relationships between the fields. |
Module Contents
- 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 = 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:
- 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:
document_loader (schema_salad.ref_resolver.Loader)
avsc_names (schema_salad.avro.schema.Names)
document (Union[ruamel.yaml.comments.CommentedMap, str])
strict (bool)
strict_foreign_properties (bool)
- Return type:
- 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.
- schema_salad.schema.replace_type(items, spec, loader, found, find_embeds=True, deepen=True)
Go through and replace types in the ‘spec’ mapping.
- 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.
- 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.
- 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.
- schema_salad.schema.make_avro(i, loader, metaschema_vocab=None)
- 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)
- Return type:
- schema_salad.schema.make_avro_schema_from_avro(avro)
Create avro.schema.Names from the given definitions.
- schema_salad.schema.shortname(inputid)
Return the last segment of the provided fragment or path.
- schema_salad.schema.print_inheritance(doc, stream)
Write a Grapviz inheritance graph for the supplied document.
- schema_salad.schema.print_fieldrefs(doc, loader, stream)
Write a GraphViz graph of the relationships between the fields.
- Parameters:
loader (schema_salad.ref_resolver.Loader)
stream (IO[Any])
- Return type:
None