Code#
MetaModel#
See Datamodel docs for full documentation
- class linkml_runtime.linkml_model.meta.SchemaDefinition(*args, _if_missing: Optional[Callable[[JsonObj, str], Tuple[bool, Any]]] = None, **kwargs)[source]#
A collection of definitions that make up a schema or a data model.
Generators#
Code for various generators for schema definitions
- class linkml.generators.jsonschemagen.JsonSchemaGenerator(schema: ~typing.Union[str, ~typing.TextIO, ~linkml_runtime.linkml_model.meta.SchemaDefinition, ~linkml.utils.generator.Generator], schemaview: ~typing.Optional[~linkml_runtime.utils.schemaview.SchemaView] = None, format: ~typing.Optional[str] = None, metadata: bool = <factory>, useuris: ~typing.Optional[bool] = None, log_level: int = 30, mergeimports: ~typing.Optional[bool] = <factory>, source_file_date: ~typing.Optional[str] = None, source_file_size: ~typing.Optional[int] = None, logger: ~typing.Optional[~logging.Logger] = None, verbose: ~typing.Optional[bool] = None, output: ~typing.Optional[str] = None, namespaces: ~typing.Optional[~linkml_runtime.utils.namespaces.Namespaces] = None, directory_output: bool = False, base_dir: ~typing.Optional[str] = None, metamodel_name_map: ~typing.Optional[~typing.Dict[str, str]] = None, importmap: ~typing.Optional[~typing.Union[str, ~typing.Mapping[str, str]]] = None, emit_prefixes: ~typing.Set[str] = <factory>, metamodel: ~typing.Optional[~linkml.utils.schemaloader.SchemaLoader] = None, stacktrace: bool = False, topClass: ~typing.Optional[str] = None, not_closed: ~typing.Optional[bool] = <factory>, indent: int = 4, inline: bool = False, top_class: ~typing.Optional[~linkml_runtime.linkml_model.meta.ClassDefinitionName] = None, include_range_class_descendants: bool = <factory>, top_level_schema: ~typing.Optional[~linkml.generators.jsonschemagen.JsonSchema] = None, **_kwargs)[source]#
Generates JSONSchema documents from a LinkML SchemaDefinition
Each linkml class generates a schema
inheritance hierarchies are rolled-down from ancestors
Composition not yet implemented
Enumerations treated as strings
Foreign key references are treated as semantics-free strings
- class linkml.generators.yamlgen.YAMLGenerator(schema: ~typing.Union[str, ~typing.TextIO, ~linkml_runtime.linkml_model.meta.SchemaDefinition, ~linkml.utils.generator.Generator], schemaview: ~typing.Optional[~linkml_runtime.utils.schemaview.SchemaView] = None, format: ~typing.Optional[str] = None, metadata: bool = <factory>, useuris: ~typing.Optional[bool] = None, log_level: int = 30, mergeimports: ~typing.Optional[bool] = <factory>, source_file_date: ~typing.Optional[str] = None, source_file_size: ~typing.Optional[int] = None, logger: ~typing.Optional[~logging.Logger] = None, verbose: ~typing.Optional[bool] = None, output: ~typing.Optional[str] = None, namespaces: ~typing.Optional[~linkml_runtime.utils.namespaces.Namespaces] = None, directory_output: bool = False, base_dir: ~typing.Optional[str] = None, metamodel_name_map: ~typing.Optional[~typing.Dict[str, str]] = None, importmap: ~typing.Optional[~typing.Union[str, ~typing.Mapping[str, str]]] = None, emit_prefixes: ~typing.Set[str] = <factory>, metamodel: ~typing.Optional[~linkml.utils.schemaloader.SchemaLoader] = None, stacktrace: bool = False, validateonly: bool = <factory>, **_kwargs)[source]#
A generator that produces a schema as a YAML Document
Loaders and Dumpers#
- class linkml_runtime.dumpers.json_dumper.JSONDumper[source]#
- dump(element: Union[BaseModel, YAMLRoot], to_file: str, contexts: Optional[Union[str, dict, JsonObj, List[Union[str, dict, JsonObj]]]] = None, **kwargs) None [source]#
Write element as json to to_file :param element: LinkML object to be serialized as YAML :param to_file: file to write to :param contexts: JSON-LD context(s) in the form of:
file name
URL
JSON String
dict
JSON Object
A list containing elements of any type named above
- dumps(element: Union[BaseModel, YAMLRoot], contexts: Optional[Union[str, dict, JsonObj, List[Union[str, dict, JsonObj]]]] = None, inject_type=True) str [source]#
Return element as a JSON or a JSON-LD string :param element: LinkML object to be emitted :param contexts: JSON-LD context(s) in the form of:
file name
URL
JSON String
dict
JSON Object
A list containing elements of any type named above
- Parameters:
inject_type – if True (default), add a @type at the top level
- Returns:
JSON Object representing the element
- class linkml_runtime.loaders.JSONLoader[source]#
- loads(source: str, target_class: Type[Union[BaseModel, YAMLRoot]], *, metadata: Optional[FileInfo] = None, **_) Union[BaseModel, YAMLRoot] #
Load source as a string :param source: source :param target_class: destination class :param metadata: metadata about the source :param _: extensions :return: instance of taarget_class
Schema Utils#
- class linkml_runtime.utils.schemaview.SchemaView(schema: Union[str, Path, SchemaDefinition], importmap: Optional[Mapping[str, str]] = None, merge_imports: bool = False)[source]#
A SchemaView provides a virtual schema layered on top of a schema plus its import closure
Most operations are parameterized by imports. If this is set to True (default), then the full import closure is considered when answering
This class utilizes caching for efficient lookup operations.
TODO: decide how to use this in conjunction with the existing schemaloader, which injects into the schema rather than providing dynamic methods.
Utils#
Utilities