Skip to content

Commit

Permalink
Add schema URL reference in json(c) files
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinse committed Sep 11, 2024
1 parent 227aaf7 commit 185f4dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/objdictgen/jsonod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/objdictgen/schema/od.schema.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions tests/od/jsonod-comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -45,4 +46,4 @@
]
}
]
}
}
7 changes: 4 additions & 3 deletions tests/od/jsonod-comments.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -51,4 +52,4 @@
]
}
]
}
}

0 comments on commit 185f4dc

Please sign in to comment.