There is a chicken-and-egg situation when developing modular LinkML schemas which could be supported better. The issue happens when the LinkML schema has modular design and affects imports and developer lifecycle...
Linkml status
Problem
LinkML imports are resolved by the loader as follows:
- CURIE expansion via prefixes - for example
linkml:/schema/linkml (hypothetical) uses prefix linkml: https://w3id.org/linkml which expands to https://w3id.org/linkml/schema/linkml.
- Import-map lookup -
SchemaLoader supports importmap (CLI flag --importmap PATH) containing key matching the expanded URI (or prefix).
- Built-in Catalog -
linkml:types, etc
- Filessytem - a string with no schema (i.e. hypothetical
./linkml_sub_schema)
- HTTP fetch - last resort
The pure URI imports work for consumers only after the URI resolves (w3id.org redirect, GitHub serves the yaml). But at development time, step 5 fails because there are competing requirements
| Requirement |
Needs |
gen-project runs locally |
URI must resolve to a file on disk |
External LinkML imports <myproject>:/schema/sub_schema.yaml (other variants possible) |
URI must resolve to published YAML over HTTPS |
Generated artifacts caryy canonical from_schema IRIs |
Imports must be expressed as as URIs, not relative paths |
A relative import ./sub-schema or ./modules/sub-schema only satisfies first - a bare URI only satisifes second - the mechanism designed to bridge both is LinkML importmap.
importmap
- it is build-time-only indirection. The YAML committed to the repo stays canonical (URI form). No rewriting or hacking after publishing.
- It allows literal subsition (
"https://w3id.org/my-awesome-schema/schema/module/sub_schema" -> "src/my_awesome_schema/schema/module/sub_schema.yaml)
- Consumers never see this - they imports resolve via
w3id -> Github (or whatever solution they have)
gen-project, gen-owl, gen-jsonschema, linkml-lint, linkml-convert, etc all accept `--importmap.
solution here
So it would be great to support importmap out of the box - should work for everyone.
Add template/importmap.json.jinja with two entries (schemaloader expects no trailing colon, shcemaview map_import expects trailing colon. Add both keys for safety.
{
"{{project_slug}": "src/{project_slug}",
"{{project_slug}:": "src/{project_slug}"
}
Update config.yaml and config.public.mk to pass importmap: importmap.json to each generator.
Workaround
Various local hacks needed.
There is a chicken-and-egg situation when developing modular LinkML schemas which could be supported better. The issue happens when the LinkML schema has modular design and affects
importsand developer lifecycle...Linkml status
importmapparameter to schemaview) -> new issue tbcProblem
LinkML imports are resolved by the loader as follows:
linkml:/schema/linkml(hypothetical) uses prefixlinkml: https://w3id.org/linkmlwhich expands tohttps://w3id.org/linkml/schema/linkml.SchemaLoadersupportsimportmap(CLI flag--importmap PATH) containing key matching the expanded URI (or prefix).linkml:types, etc./linkml_sub_schema)The pure URI imports work for consumers only after the URI resolves (w3id.org redirect, GitHub serves the yaml). But at development time, step 5 fails because there are competing requirements
gen-projectruns locally<myproject>:/schema/sub_schema.yaml(other variants possible)from_schemaIRIsA relative import
./sub-schemaor./modules/sub-schemaonly satisfies first - a bare URI only satisifes second - the mechanism designed to bridge both is LinkMLimportmap.importmap
"https://w3id.org/my-awesome-schema/schema/module/sub_schema" -> "src/my_awesome_schema/schema/module/sub_schema.yaml)w3id-> Github (or whatever solution they have)gen-project,gen-owl,gen-jsonschema,linkml-lint,linkml-convert, etc all accept `--importmap.solution here
So it would be great to support
importmapout of the box - should work for everyone.Add
template/importmap.json.jinjawith two entries (schemaloader expects no trailing colon, shcemaviewmap_importexpects trailing colon. Add both keys for safety.{ "{{project_slug}": "src/{project_slug}", "{{project_slug}:": "src/{project_slug}" }Update
config.yamlandconfig.public.mkto passimportmap: importmap.jsonto each generator.Workaround
Various local hacks needed.