Skip to content

Commit 471d05a

Browse files
authored
Add schema URL reference in json(c) files (#43)
1 parent 227aaf7 commit 471d05a

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/objdictgen/jsonod.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ class ValidationError(Exception):
5858
# 1 - Default JSON format
5959
JSON_ID = "od data"
6060
JSON_DESCRIPTION = "Canfestival object dictionary data"
61+
JSON_SCHEMA = "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json"
6162
JSON_INTERNAL_VERSION = "0"
6263
JSON_VERSION = "1"
6364

6465
# Output order in JSON file
6566
JSON_TOP_ORDER = (
66-
"$id", "$version", "$description", "$tool", "$date", "$schema",
67+
"$id", "$version", "$description", "$schema", "$tool", "$date", "$schema",
6768
"name", "description", "type", "id", "profile",
6869
"default_string_size", "dictionary",
6970
)
@@ -117,6 +118,7 @@ class ValidationError(Exception):
117118
}
118119
FIELDS_DATA_OPT = {
119120
'$description', # info only
121+
'$schema', # info only
120122
'$tool', # info only
121123
'$date', # info only
122124
'id', # default 0
@@ -519,6 +521,7 @@ def node_todict(node: "Node", sort=False, rich=True, internal=False, validate=Tr
519521
'$id': JSON_ID,
520522
'$version': JSON_INTERNAL_VERSION if internal else JSON_VERSION,
521523
'$description': JSON_DESCRIPTION,
524+
'$schema': JSON_SCHEMA,
522525
'$tool': str(objdictgen.ODG_PROGRAM) + ' ' + str(objdictgen.__version__),
523526
'$date': datetime.now().astimezone().isoformat(),
524527
'name': node.Name,
@@ -1167,6 +1170,7 @@ def validate_fromdict(jsonobj: TODJson, objtypes_i2s: dict[int, str], objtypes_s
11671170
# "type" (must)
11681171
# Y "dictionary" (must)
11691172
# "$description" (optional)
1173+
# "$schema" (optional)
11701174
# "$tool" (optional)
11711175
# "$date" (optional)
11721176
# "id" (optional, default 0)

src/objdictgen/schema/od.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
3-
"$id": "https://raw.githubusercontent.com/laerdal-svg/python-objdictgen/main/src/objdictgen/schema/od.schema.json",
3+
"$id": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json",
44
"title": "Object Dictionary",
55
"description": "A Object Dictionary description for canfestival",
66
"type": "object",
@@ -21,6 +21,10 @@
2121
"description": "Description about the file",
2222
"type": "string"
2323
},
24+
"$schema": {
25+
"description": "The schema that this file is based on",
26+
"type": "string"
27+
},
2428
"$tool": {
2529
"description": "Tool that generated this file (optional)",
2630
"type": "string"

tests/od/jsonod-comments.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"$id": "od data",
33
"$version": "1",
44
"$description": "Canfestival object dictionary data",
5-
"$tool": "odg 3.5",
6-
"$date": "2024-08-13T11:36:24.609168",
5+
"$schema": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json",
6+
"$tool": "odg 3.5.1a1",
7+
"$date": "2024-09-11T18:14:48.704234+02:00",
78
"name": "JSON comments",
89
"description": "Test for JSON comments",
910
"type": "slave",
@@ -45,4 +46,4 @@
4546
]
4647
}
4748
]
48-
}
49+
}

tests/od/jsonod-comments.jsonc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"$id": "od data",
33
"$version": "1",
44
"$description": "Canfestival object dictionary data",
5-
"$tool": "odg 3.5",
6-
"$date": "2024-08-13T11:36:24.609168",
5+
"$schema": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json",
6+
"$tool": "odg 3.5.1a1",
7+
"$date": "2024-09-11T18:12:57.745309+02:00",
78
"name": "JSON comments",
89
"description": "Test for JSON comments",
910
"type": "slave",
@@ -51,4 +52,4 @@
5152
]
5253
}
5354
]
54-
}
55+
}

0 commit comments

Comments
 (0)