diff --git a/src/objdictgen/jsonod.py b/src/objdictgen/jsonod.py index c0405d5..4abfa9b 100644 --- a/src/objdictgen/jsonod.py +++ b/src/objdictgen/jsonod.py @@ -58,12 +58,13 @@ class ValidationError(Exception): # 1 - Default JSON format JSON_ID = "od data" JSON_DESCRIPTION = "Canfestival object dictionary data" +JSON_SCHEMA = "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json" JSON_INTERNAL_VERSION = "0" JSON_VERSION = "1" # Output order in JSON file JSON_TOP_ORDER = ( - "$id", "$version", "$description", "$tool", "$date", "$schema", + "$id", "$version", "$description", "$schema", "$tool", "$date", "$schema", "name", "description", "type", "id", "profile", "default_string_size", "dictionary", ) @@ -117,6 +118,7 @@ class ValidationError(Exception): } FIELDS_DATA_OPT = { '$description', # info only + '$schema', # info only '$tool', # info only '$date', # info only 'id', # default 0 @@ -519,6 +521,7 @@ def node_todict(node: "Node", sort=False, rich=True, internal=False, validate=Tr '$id': JSON_ID, '$version': JSON_INTERNAL_VERSION if internal else JSON_VERSION, '$description': JSON_DESCRIPTION, + '$schema': JSON_SCHEMA, '$tool': str(objdictgen.ODG_PROGRAM) + ' ' + str(objdictgen.__version__), '$date': datetime.now().astimezone().isoformat(), 'name': node.Name, @@ -1167,6 +1170,7 @@ def validate_fromdict(jsonobj: TODJson, objtypes_i2s: dict[int, str], objtypes_s # "type" (must) # Y "dictionary" (must) # "$description" (optional) + # "$schema" (optional) # "$tool" (optional) # "$date" (optional) # "id" (optional, default 0) diff --git a/src/objdictgen/schema/od.schema.json b/src/objdictgen/schema/od.schema.json index 9277d45..1f13134 100644 --- a/src/objdictgen/schema/od.schema.json +++ b/src/objdictgen/schema/od.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "$id": "https://raw.githubusercontent.com/laerdal-svg/python-objdictgen/main/src/objdictgen/schema/od.schema.json", + "$id": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json", "title": "Object Dictionary", "description": "A Object Dictionary description for canfestival", "type": "object", @@ -21,6 +21,10 @@ "description": "Description about the file", "type": "string" }, + "$schema": { + "description": "The schema that this file is based on", + "type": "string" + }, "$tool": { "description": "Tool that generated this file (optional)", "type": "string" diff --git a/tests/od/jsonod-comments.json b/tests/od/jsonod-comments.json index b549038..55ca5e9 100644 --- a/tests/od/jsonod-comments.json +++ b/tests/od/jsonod-comments.json @@ -2,8 +2,9 @@ "$id": "od data", "$version": "1", "$description": "Canfestival object dictionary data", - "$tool": "odg 3.5", - "$date": "2024-08-13T11:36:24.609168", + "$schema": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json", + "$tool": "odg 3.5.1a1", + "$date": "2024-09-11T18:14:48.704234+02:00", "name": "JSON comments", "description": "Test for JSON comments", "type": "slave", @@ -45,4 +46,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/tests/od/jsonod-comments.jsonc b/tests/od/jsonod-comments.jsonc index 61d8c5c..1e906f7 100644 --- a/tests/od/jsonod-comments.jsonc +++ b/tests/od/jsonod-comments.jsonc @@ -2,8 +2,9 @@ "$id": "od data", "$version": "1", "$description": "Canfestival object dictionary data", - "$tool": "odg 3.5", - "$date": "2024-08-13T11:36:24.609168", + "$schema": "https://raw.githubusercontent.com/Laerdal/python-objdictgen/main/src/objdictgen/schema/od.schema.json", + "$tool": "odg 3.5.1a1", + "$date": "2024-09-11T18:12:57.745309+02:00", "name": "JSON comments", "description": "Test for JSON comments", "type": "slave", @@ -51,4 +52,4 @@ ] } ] -} +} \ No newline at end of file