Skip to content

Commit 421fa79

Browse files
Add support for noLinkCheck in codegen
This commit introduces support for the `noLinkCheck` `jsonldPredicate` in the Schema SALAD codegen toolchain, and in particular in the `URILoader` stack. When `noLinkCheck` is set to `true`, no link checking is performed for all the underlying objects hierarchy. The need to propagate its value to the hierarchy makes it necessary to modify also the `LoadingOptions` data structure. All parsers but the Python one never perform link checking up to now, so this update makes no modification to their actual behaviour. However, it enables the `URILoader` classes to receive the `noLinkCheck` parameter for future implementations.
1 parent b2a6052 commit 421fa79

File tree

11 files changed

+118
-69
lines changed

11 files changed

+118
-69
lines changed

schema_salad/codegen.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def codegen(
164164
subscope = field.get("subscope")
165165
fieldpred = field["name"]
166166
optional = bool("https://w3id.org/cwl/salad#null" in field["type"])
167-
uri_loader = gen.uri_loader(gen.type_loader(field["type"]), True, False, None)
167+
uri_loader = gen.uri_loader(
168+
gen.type_loader(field["type"]), True, False, None, None
169+
)
168170
gen.declare_id_field(
169171
fieldpred,
170172
uri_loader,
@@ -189,10 +191,16 @@ def codegen(
189191
type_loader = gen.secondaryfilesdsl_loader(type_loader)
190192
elif jld.get("_type") == "@id":
191193
type_loader = gen.uri_loader(
192-
type_loader, jld.get("identity", False), False, ref_scope
194+
type_loader,
195+
jld.get("identity", False),
196+
False,
197+
ref_scope,
198+
jld.get("noLinkCheck"),
193199
)
194200
elif jld.get("_type") == "@vocab":
195-
type_loader = gen.uri_loader(type_loader, False, True, ref_scope)
201+
type_loader = gen.uri_loader(
202+
type_loader, False, True, ref_scope, jld.get("noLinkCheck")
203+
)
196204

197205
map_subject = jld.get("mapSubject")
198206
if map_subject:

schema_salad/codegen_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def uri_loader(
115115
scoped_id: bool,
116116
vocab_term: bool,
117117
ref_scope: Optional[int],
118+
no_link_check: Optional[bool],
118119
) -> TypeDef:
119120
"""Construct the TypeDef for the given URI loader."""
120121
raise NotImplementedError()

schema_salad/dotnet/util/Loaders/UriLoader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ internal class UriLoader : ILoader<object>
88
readonly bool scopedID;
99
readonly bool vocabTerm;
1010
readonly int? scopedRef;
11+
readonly bool? noLinkCheck;
1112

12-
public UriLoader(in ILoader inner, in bool scopedID, in bool vocabTerm, in int? scopedRef)
13+
public UriLoader(in ILoader inner, in bool scopedID, in bool vocabTerm, in int? scopedRef, in bool? noLinkCheck)
1314
{
1415
this.inner = inner;
1516
this.scopedID = scopedID;
1617
this.vocabTerm = vocabTerm;
1718
this.scopedRef = scopedRef;
19+
this.noLinkCheck = noLinkCheck;
1820
}
1921

2022
public object Load(in object doc_, in string baseuri, in LoadingOptions loadingOptions, in string? docRoot = null)

schema_salad/dotnet_codegen.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,19 +792,21 @@ def uri_loader(
792792
scoped_id: bool,
793793
vocab_term: bool,
794794
ref_scope: Optional[int],
795+
no_link_check: Optional[bool],
795796
) -> TypeDef:
796797
"""Construct the TypeDef for the given URI loader."""
797798
instance_type = inner.instance_type or "object"
798799
return self.declare_type(
799800
TypeDef(
800801
instance_type=instance_type,
801-
name=f"uri{inner.name}{scoped_id}{vocab_term}{ref_scope}",
802+
name=f"uri{inner.name}{scoped_id}{vocab_term}{ref_scope}{no_link_check}",
802803
loader_type="ILoader<object>",
803-
init="new UriLoader({}, {}, {}, {})".format(
804+
init="new UriLoader({}, {}, {}, {}, {})".format(
804805
inner.name,
805806
self.to_dotnet(scoped_id),
806807
self.to_dotnet(vocab_term),
807808
self.to_dotnet(ref_scope),
809+
self.to_dotnet(no_link_check),
808810
),
809811
is_uri=True,
810812
scoped_id=scoped_id,

schema_salad/java/main_utils/UriLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public UriLoader(
1313
final Loader<T> innerLoader,
1414
final boolean scopedId,
1515
final boolean vocabTerm,
16-
final Integer scopedRef) {
16+
final Integer scopedRef,
17+
final Boolean noLinkCheck) {
1718
this.innerLoader = innerLoader;
1819
this.scopedId = scopedId;
1920
this.vocabTerm = vocabTerm;
2021
this.scopedRef = scopedRef;
22+
this.noLinkCheck = noLinkCheck
2123
}
2224

2325
private Object expandUrl(

schema_salad/java_codegen.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,17 +715,19 @@ def uri_loader(
715715
scoped_id: bool,
716716
vocab_term: bool,
717717
ref_scope: Optional[int],
718+
no_link_check: Optional[bool],
718719
) -> TypeDef:
719720
instance_type = inner.instance_type or "Object"
720721
return self.declare_type(
721722
TypeDef(
722723
instance_type=instance_type, # ?
723-
name=f"uri_{inner.name}_{scoped_id}_{vocab_term}_{ref_scope}",
724-
init="new UriLoader({}, {}, {}, {})".format(
724+
name=f"uri_{inner.name}_{scoped_id}_{vocab_term}_{ref_scope}_{no_link_check}",
725+
init="new UriLoader({}, {}, {}, {}, {})".format(
725726
inner.name,
726727
self.to_java(scoped_id),
727728
self.to_java(vocab_term),
728729
self.to_java(ref_scope),
730+
self.to_java(no_link_check),
729731
),
730732
is_uri=True,
731733
scoped_id=scoped_id,

0 commit comments

Comments
 (0)