shacl2code 0.0.6__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {shacl2code-0.0.6 → shacl2code-0.0.7}/PKG-INFO +1 -1
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/common.py +4 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/templates/jsonschema.j2 +24 -37
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/templates/python.j2 +326 -166
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/main.py +14 -11
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/model.py +31 -19
- shacl2code-0.0.7/src/shacl2code/version.py +1 -0
- shacl2code-0.0.6/tests/data/bad-referenceable.ttl → shacl2code-0.0.7/tests/data/bad-node-kind.ttl +2 -2
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/bad-pattern-class.ttl +1 -1
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/bad-pattern-integer.ttl +1 -1
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/model/test-context.json +15 -7
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/model/test.ttl +51 -32
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/python/roundtrip.json +3 -1
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/jsonschema/test-context.json +161 -124
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/jsonschema/test.json +161 -124
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/python/test-context.py +444 -473
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/python/test.py +377 -364
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/raw/test-context.txt +8 -8
- shacl2code-0.0.7/tests/expect/raw/test.txt +17 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_jsonschema.py +65 -18
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_model_source.py +1 -1
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_python.py +237 -178
- shacl2code-0.0.6/src/shacl2code/version.py +0 -1
- shacl2code-0.0.6/tests/expect/raw/test.txt +0 -17
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.flake8 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.github/workflows/coverage-generate.yaml +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.github/workflows/coverage-report.yaml +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.github/workflows/publish.yaml +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.github/workflows/test.yaml +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/.gitignore +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/LICENSE +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/README.md +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/pyproject.toml +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/__init__.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/__main__.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/context.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/__init__.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/jinja.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/jsonschema.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/lang.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/lang/python.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/src/shacl2code/urlcontext.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/conftest.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/abort.j2 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/bad-id.j2 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/bad-reference.jsonld +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/context-url.j2 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/context.j2 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/missing-range.ttl +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/python/links.json +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/data/raw.j2 +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/expect/make_expect.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_cli.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_common_jinja.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_common_prefix.py +0 -0
- {shacl2code-0.0.6 → shacl2code-0.0.7}/tests/test_context.py +0 -0
|
@@ -8,6 +8,8 @@ import os
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from contextlib import contextmanager
|
|
10
10
|
from jinja2 import Environment, FileSystemLoader, TemplateRuntimeError
|
|
11
|
+
from rdflib.namespace import SH
|
|
12
|
+
from ..model import SHACL2CODE
|
|
11
13
|
|
|
12
14
|
THIS_DIR = Path(__file__).parent
|
|
13
15
|
|
|
@@ -97,6 +99,8 @@ class BasicJinjaRender(object):
|
|
|
97
99
|
env.globals[k] = v
|
|
98
100
|
env.globals["abort"] = abort_helper
|
|
99
101
|
env.globals["get_all_derived"] = get_all_derived
|
|
102
|
+
env.globals["SHACL2CODE"] = SHACL2CODE
|
|
103
|
+
env.globals["SH"] = SH
|
|
100
104
|
template = env.get_template(self.__template.name)
|
|
101
105
|
|
|
102
106
|
classes = ObjectList(model.classes)
|
|
@@ -61,19 +61,10 @@
|
|
|
61
61
|
"allOf": [
|
|
62
62
|
{
|
|
63
63
|
"properties": {
|
|
64
|
-
{
|
|
65
|
-
"{{ class.id_property or context.compact("@id") }}":
|
|
66
|
-
{%- if class.refable == "always" or class.refable == "yes" -%}
|
|
67
|
-
{ "$ref": "#/$defs/externalRef" }
|
|
68
|
-
{%- elif class.refable == "local" -%}
|
|
69
|
-
{ "$ref": "#/$defs/localRef" }
|
|
70
|
-
{%- elif class.refable == "optional" -%}
|
|
71
|
-
{ "$ref": "#/$defs/anyRef" }
|
|
72
|
-
{%- endif %},
|
|
73
|
-
{%- endif %}
|
|
64
|
+
"{{ class.id_property or "@id" }}": { "$ref": "#/$defs/{{ class.node_kind.split("#")[-1] }}" },
|
|
74
65
|
"{{ context.compact("@type") }}": { "const": "{{ context.compact_vocab(class._id) }}" }
|
|
75
|
-
}{%- if class.
|
|
76
|
-
"required": ["{{ class.id_property or
|
|
66
|
+
}{%- if class.node_kind == SH.IRI %},
|
|
67
|
+
"required": ["{{ class.id_property or "@id" }}"]
|
|
77
68
|
{%- endif %}
|
|
78
69
|
},
|
|
79
70
|
{ "$ref": "#/$defs/{{ varname(class.clsname) }}_props" }
|
|
@@ -82,27 +73,9 @@
|
|
|
82
73
|
"{{ varname(class.clsname) }}_derived": {
|
|
83
74
|
{%- set ns = namespace(external_ref=False, local_ref=False, any_ref=False, json_refs=[]) %}
|
|
84
75
|
{%- for d in get_all_derived(class) + [class._id] %}
|
|
85
|
-
{%-
|
|
86
|
-
{%- set ns.external_ref = True %}
|
|
87
|
-
{%- elif class.refable == "local" %}
|
|
88
|
-
{%- set ns.local_ref = True %}
|
|
89
|
-
{%- elif class.refable == "optional" %}
|
|
90
|
-
{%- set ns.any_ref = True %}
|
|
91
|
-
{%- endif %}
|
|
92
|
-
{%- if classes.get(d).refable != "always" %}
|
|
93
|
-
{%- set ns.json_refs = ns.json_refs + ["#/$defs/" + varname(classes.get(d).clsname)] %}
|
|
94
|
-
{%- endif %}
|
|
76
|
+
{%- set ns.json_refs = ns.json_refs + ["#/$defs/" + varname(classes.get(d).clsname)] %}
|
|
95
77
|
{%- endfor %}
|
|
96
|
-
{%-
|
|
97
|
-
{%- set ns.json_refs = ns.json_refs + ["#/$defs/anyRef"] %}
|
|
98
|
-
{%- else %}
|
|
99
|
-
{%- if ns.local_ref %}
|
|
100
|
-
{%- set ns.json_refs = ns.json_refs + ["#/$defs/localRef"] %}
|
|
101
|
-
{%- endif %}
|
|
102
|
-
{%- if ns.external_ref %}
|
|
103
|
-
{%- set ns.json_refs = ns.json_refs + ["#/$defs/externalRef"] %}
|
|
104
|
-
{%- endif %}
|
|
105
|
-
{%- endif %}
|
|
78
|
+
{%- set ns.json_refs = ns.json_refs + ["#/$defs/BlankNodeOrIRI"] %}
|
|
106
79
|
|
|
107
80
|
{%- if ns.json_refs | length == 1 %}
|
|
108
81
|
"$ref": "{{ ns.json_refs[0] }}",
|
|
@@ -185,6 +158,17 @@
|
|
|
185
158
|
{%- endif %}
|
|
186
159
|
"type": "string"
|
|
187
160
|
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#dateTime" %}
|
|
161
|
+
"type": "string",
|
|
162
|
+
"allOf": [
|
|
163
|
+
{
|
|
164
|
+
"pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](Z|[+-][0-9]{2}:[0-9]{2})?$"
|
|
165
|
+
}{%- if prop.pattern %},
|
|
166
|
+
{
|
|
167
|
+
"pattern": "{{ prop.pattern | replace("\\", "\\\\") }}"
|
|
168
|
+
}
|
|
169
|
+
{%- endif %}
|
|
170
|
+
]
|
|
171
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#dateTimeStamp" %}
|
|
188
172
|
"type": "string",
|
|
189
173
|
"allOf": [
|
|
190
174
|
{
|
|
@@ -227,17 +211,20 @@
|
|
|
227
211
|
},
|
|
228
212
|
{%- endfor %}
|
|
229
213
|
{%- endfor %}
|
|
230
|
-
"
|
|
231
|
-
"type": "string"
|
|
232
|
-
},
|
|
233
|
-
"externalRef": {
|
|
214
|
+
"IRI": {
|
|
234
215
|
"type": "string",
|
|
235
216
|
"pattern": "^(?!_:).*"
|
|
236
217
|
},
|
|
237
|
-
"
|
|
218
|
+
"BlankNode": {
|
|
238
219
|
"type": "string",
|
|
239
220
|
"pattern": "^_:.*"
|
|
240
221
|
},
|
|
222
|
+
"BlankNodeOrIRI": {
|
|
223
|
+
"oneOf": [
|
|
224
|
+
{ "$ref": "#/$defs/IRI" },
|
|
225
|
+
{ "$ref": "#/$defs/BlankNode" }
|
|
226
|
+
]
|
|
227
|
+
},
|
|
241
228
|
"anyURI": {
|
|
242
229
|
"type": "string"
|
|
243
230
|
},
|