feat(generators): add --exclude-external-imports flag#2
Open
Conversation
Add a dedicated --exclude-external-imports / --no-exclude-external-imports CLI flag to control whether external vocabulary terms are included in generated artifacts when --no-mergeimports is set. Previously external terms leaked into JSON-LD contexts even with --no-mergeimports. The new flag explicitly suppresses terms whose class_uri or slot_uri belong to an imported (external) schema. Signed-off-by: jdsika <carlo.van-driesten@bmw.de>
6b9de70 to
5df92ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
--exclude-external-importsflag to the JSON-LD context generator that suppresses terms from URL-based external vocabulary imports, keeping only locally defined classes and slots.Problem
When a schema imports an external vocabulary via URL (e.g. W3C Verifiable Credentials), all imported terms leak into the generated JSON-LD context — even with
--no-mergeimports. This is problematic when the external vocabulary defines@protectedterms in its own context (JSON-LD 1.1 §4.1.11): redefining them locally violates the protection semantics.Solution
When
--exclude-external-importsis set, the context generator identifies classes and slots from HTTP(S)-based imports viaSchemaView.schema_mapand skips them duringvisit_class/visit_slot. Local file imports and linkml standard imports are preserved.Changes
jsonldcontextgen.py: Addexclude_external_importsfield,_collect_external_elements()static helper, and filtering invisit_class()/visit_slot(). Add CLI option.test_jsonldcontextgen.py: Add parametrized test covering both merge modes, verifying local elements preserved and external elements excluded.Backward Compatibility
The flag defaults to off — existing behavior is fully preserved.