Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/shacl2code/lang/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_all_named_individuals(cls):
"concrete_classes": concrete_classes,
"abstract_classes": abstract_classes,
"context": model.context,
"jsf_signature": model.jsf_signature,
**self.get_additional_render_args(model),
}

Expand Down
11 changes: 11 additions & 0 deletions src/shacl2code/lang/templates/cpp/jsonld-source.j2
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,17 @@ void JSONLDDeserializer::read(std::istream& input, SHACLObjectSet& objectSet,
errorHandler.handleDeserializeError("Invalid context URLs", path);
return;
}
{%- if jsf_signature %}
if (d.contains("{{ jsf_signature }}")) {
path.pushMember("{{ jsf_signature }}", [&] {
if (!d["{{ jsf_signature }}"].is_object()) {
errorHandler.handleDeserializeError("Signature {{ jsf_signature }} must be an object", path);
return;
}
});
d.erase("{{ jsf_signature }}");
}
{%- endif %}

if (!d.contains("@graph")) {
JSONData data;
Expand Down
12 changes: 12 additions & 0 deletions src/shacl2code/lang/templates/golang/shaclobjectset.go.j2
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var CONTEXT_URLS = []string{
{{ '/' }}{{ '*' }}*/
}

var JSF_SIGNATURE = "{{ jsf_signature or '' }}"

func makeshaclObjectList(lst []SHACLObject) shaclObjectList {
idx := make(map[SHACLObject]int)
for i, o := range lst {
Expand Down Expand Up @@ -187,6 +189,16 @@ func (self *SHACLObjectSetObject) Decode(decoder *json.Decoder) error {
return DecodeSHACLObject[SHACLObject](data, path, context, nil, state)
}

if JSF_SIGNATURE != "" {
if signature, found := data[JSF_SIGNATURE]; found {
_, ok := signature.(map[string]interface{})
if !ok {
return &DecodeError{path, "Bad type for signature '" + JSF_SIGNATURE + "'"}
}
}
delete(data, JSF_SIGNATURE)
}

_, has_graph := data["@graph"]
if has_graph {
for k, v := range data {
Expand Down
19 changes: 16 additions & 3 deletions src/shacl2code/lang/templates/jsonschema.j2
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@
"$ref": "#/$defs/AnyClass",
"unevaluatedProperties": false
}
}
}{%- if jsf_signature %},
"{{ jsf_signature }}": {
"$ref": "#/$defs/JSF"
}{%- endif %}
},
"required": ["@graph"]
},
"else": {
"$ref": "#/$defs/AnyClass"
"allOf": [
{
"$ref": "#/$defs/AnyClass"
}{%- if jsf_signature %},
{
"properties": {
"{{ jsf_signature }}": { "$ref": "#/$defs/JSF" }
}
}{%- endif %}
]
},
"unevaluatedProperties": false,

Expand Down Expand Up @@ -328,6 +340,7 @@
}
}
]
}
},
"JSF": { "type": "object" }
}
}
12 changes: 6 additions & 6 deletions src/shacl2code/lang/templates/python/cmd.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import argparse
from pathlib import Path
from typing import Any, Iterable, List
from typing import Any

from .model import (
DataPath,
JSONLDDeserializer,
JSONLDSerializer,
ListProxy,
Expand All @@ -17,13 +18,13 @@ from .model import (
)


def print_tree(objects: Iterable[SHACLObject], all_fields: bool = False) -> None:
def print_tree(objectset: SHACLObjectSet, all_fields: bool = False) -> None:
"""
Print object tree
"""
seen = set()

def callback(value: Any, path: List[str]) -> bool:
def callback(value: Any, path: DataPath) -> bool:
s = (" " * (len(path) - 1)) + f"{path[-1]}"
if isinstance(value, SHACLObject):
s += f" {value} ({id(value)})"
Expand All @@ -47,8 +48,7 @@ def print_tree(objects: Iterable[SHACLObject], all_fields: bool = False) -> None

return True

for o in objects:
o.walk(callback)
objectset.walk(callback)


def main() -> int:
Expand All @@ -65,7 +65,7 @@ def main() -> int:
d.read(f, objectset)

if args.print:
print_tree(objectset.objects)
print_tree(objectset)

if args.outfile:
with args.outfile.open("wb") as f:
Expand Down
Loading
Loading