Replace tabs, allow validation of any valid json schema

This commit is contained in:
Jack Marriott
2018-11-19 22:08:04 -05:00
parent e09c3bed9a
commit 94bcc78c2b
5 changed files with 97 additions and 87 deletions

View File

@@ -0,0 +1,4 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description" : "General purpose JSON validator"
}

View File

@@ -1,14 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title" : "OC-SDR schema",
"description" : "OC-SDR system specification",
"title" : "OC-SDR schema",
"description" : "OC-SDR system specification",
"type": "array",
"items": {
"$ref": "#/definitions/Subsystem"
},
"definitions": {
"Subsystem": {
"title": "Subsystem",
"title": "Subsystem",
"type": "object",
"properties": {
"name": {"type": "string"},
@@ -18,19 +18,19 @@
"$ref": "#/definitions/Component"
}
},
"driver_cfg": {"type": "string"},
"ssHookSet" : {
"type" : "object",
"items" : {
"driver_cfg": {"type": "string"},
"ssHookSet" : {
"type" : "object",
"items" : {
"$ref": "#/definitions/SsHookSet"
}
}
}
}
},
"required": ["name", "components"],
"additionalProperties" : false
"additionalProperties" : false
},
"Component": {
"title" : "Component",
"title" : "Component",
"type": "object",
"properties": {
"name": {"type": "string"},
@@ -49,20 +49,20 @@
"$ref": "#/definitions/Command"
}
},
"ssHookSet" : {
"type" : "object",
"items" : {
"ssHookSet" : {
"type" : "object",
"items" : {
"$ref": "#/definitions/SsHookSet"
}
},
}
},
"postDisabled": {"type" : "string"},
"ss" : {"type" : "string"}
"ss" : {"type" : "string"}
},
"required": ["name"],
"additionalProperties" : false
"additionalProperties" : false
},
"Subcomponent" : {
"title" : "Subcomponent",
"Subcomponent" : {
"title" : "Subcomponent",
"type" : "object",
"properties": {
"name" : {"type" : "string"},
@@ -72,28 +72,28 @@
"factory_config" : {"type" : "string"}
},
"required" : ["name"],
"additionalProperties" : false
},
"Command" : {
"title" : "Command",
"type" : "object",
"properties" : {
"name": {"type" : "string"},
"parameters" : {"type" : "string"},
"cb_cmd" : {"type" : "string"}
},
"required" : ["name"],
"additionalProperties" : false
},
"SsHookSet" : {
"title" : "SSHookSet",
"type" : "object",
"properties" : {
"preInitFxn": {"type" : "string"},
"postInitFxn" : {"type" : "string"}
},
"required" : ["preInitFxn", "postInitFxn"],
"additionalProperties" : false
}
}
"additionalProperties" : false
},
"Command" : {
"title" : "Command",
"type" : "object",
"properties" : {
"name": {"type" : "string"},
"parameters" : {"type" : "string"},
"cb_cmd" : {"type" : "string"}
},
"required" : ["name"],
"additionalProperties" : false
},
"SsHookSet" : {
"title" : "SSHookSet",
"type" : "object",
"properties" : {
"preInitFxn": {"type" : "string"},
"postInitFxn" : {"type" : "string"}
},
"required" : ["preInitFxn", "postInitFxn"],
"additionalProperties" : false
}
}
}

View File

@@ -1,14 +1,14 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title" : "OC-SDR schema",
"description" : "OC-SDR system specification",
"title" : "OC-SDR schema",
"description" : "OC-SDR system specification",
"type": "array",
"items": {
"$ref": "#/definitions/Subsystem"
},
"definitions": {
"Subsystem": {
"title": "Subsystem",
"title": "Subsystem",
"type": "object",
"properties": {
"name": {"type": "string"},
@@ -18,18 +18,18 @@
"$ref": "#/definitions/Component"
}
},
"driver_cfg": {"type": "string"},
"ssHookSet" : {
"type" : "object",
"items" : {
"driver_cfg": {"type": "string"},
"ssHookSet" : {
"type" : "object",
"items" : {
"$ref": "#/definitions/SsHookSet"
}
}
}
}
},
"required": ["name", "components"]
},
"Component": {
"title" : "Component",
"title" : "Component",
"type": "object",
"properties": {
"name": {"type": "string"},
@@ -48,19 +48,19 @@
"$ref": "#/definitions/Command"
}
},
"ssHookSet" : {
"type" : "object",
"items" : {
"ssHookSet" : {
"type" : "object",
"items" : {
"$ref": "#/definitions/SsHookSet"
}
},
}
},
"postDisabled": {"type" : "string"},
"ss" : {"type" : "string"}
"ss" : {"type" : "string"}
},
"required": ["name"]
},
"Subcomponent" : {
"title" : "Subcomponent",
"Subcomponent" : {
"title" : "Subcomponent",
"type" : "object",
"properties": {
"name" : {"type" : "string"},
@@ -70,25 +70,25 @@
"factory_config" : {"type" : "string"}
},
"required" : ["name"]
},
"Command" : {
"title" : "Command",
"type" : "object",
"properties" : {
"name": {"type" : "string"},
"parameters" : {"type" : "string"},
"cb_cmd" : {"type" : "string"}
},
"required" : ["name"]
},
"SsHookSet" : {
"title" : "SSHookSet",
"type" : "object",
"properties" : {
"preInitFxn": {"type" : "string"},
"postInitFxn" : {"type" : "string"}
},
"required" : ["preInitFxn", "postInitFxn"]
}
}
}
},
"Command" : {
"title" : "Command",
"type" : "object",
"properties" : {
"name": {"type" : "string"},
"parameters" : {"type" : "string"},
"cb_cmd" : {"type" : "string"}
},
"required" : ["name"]
},
"SsHookSet" : {
"title" : "SSHookSet",
"type" : "object",
"properties" : {
"preInitFxn": {"type" : "string"},
"postInitFxn" : {"type" : "string"}
},
"required" : ["preInitFxn", "postInitFxn"]
}
}
}

View File

@@ -14,7 +14,8 @@ import jsonschema as js
class SchemaUtils:
draftFiles = {'d4' : 'meta_sys_schema_d4.json',
draftFiles = {'d0' : 'meta_sys_schema_d0.json',
'd4' : 'meta_sys_schema_d4.json',
'd6' : 'meta_sys_schema_d6.json'}
def __init__(self, md, json_fname, c_fname, draft):
@@ -108,7 +109,7 @@ class SchemaUtils:
# self.cfgschema[0]['name'] = []
try:
try:
if self.draft == 'd4':
if (self.draft == 'd4') or (self.draft == 'd0'):
js.Draft4Validator.check_schema(self.metaschema)
else:
# not supported until jsonschema 3.0

View File

@@ -32,6 +32,11 @@
Same as previous example but with all defaults
$ python3 sdtester.py -g
Example 5:
Check that any arbitrary JSON schema declaration generates a C-file.
Use d0 validation for development purposes
$ python3 sdtester.py -j test_schema.json -c test_schema.c -d d0
"""
import sys
@@ -98,7 +103,7 @@ if __name__ == "__main__":
action='store',
default='d4',
type=str,
help='JSON draft version, e.g. \'d4\' or \'d6\'',
help='JSON draft version, e.g. \'d4\' or \'d6\' for build; \'d0\' for general purpose',
)
# Schema source C-file to convert into JSON schema
parser.add_argument(