Skip to content

feat(generators): add --exclude-external-imports flag#2

Open
jdsika wants to merge 1 commit intomainfrom
fix/contextgen-skip-external-imports
Open

feat(generators): add --exclude-external-imports flag#2
jdsika wants to merge 1 commit intomainfrom
fix/contextgen-skip-external-imports

Conversation

@jdsika
Copy link
Copy Markdown

@jdsika jdsika commented Mar 26, 2026

Summary

Add a --exclude-external-imports flag 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 @protected terms in its own context (JSON-LD 1.1 §4.1.11): redefining them locally violates the protection semantics.

Solution

When --exclude-external-imports is set, the context generator identifies classes and slots from HTTP(S)-based imports via SchemaView.schema_map and skips them during visit_class / visit_slot. Local file imports and linkml standard imports are preserved.

Changes

  • jsonldcontextgen.py: Add exclude_external_imports field, _collect_external_elements() static helper, and filtering in visit_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.

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>
@jdsika jdsika force-pushed the fix/contextgen-skip-external-imports branch from 6b9de70 to 5df92ed Compare March 30, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant