updated schema to check if oneOf length, reflength or data is set.
This commit is contained in:
parent
94d24a8b19
commit
67485f775a
|
@ -2,9 +2,12 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="208c8f22-eeea-487d-8a23-c2fce1eb1434" name="Default" comment="">
|
<list default="true" id="208c8f22-eeea-487d-8a23-c2fce1eb1434" name="Default" comment="">
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/npd.iml" afterPath="$PROJECT_DIR$/.idea/npd.iml" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/example.yml" afterPath="$PROJECT_DIR$/example.yml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/protocols/osi1-2/arp.yml" afterPath="$PROJECT_DIR$/protocols/osi1-2/arp.yml" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/protocols/osi1-2/eth-frame.yml" afterPath="$PROJECT_DIR$/protocols/osi1-2/eth-frame.yml" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/protocols/osi1-2/eth-packet.yml" afterPath="$PROJECT_DIR$/protocols/osi1-2/eth-packet.yml" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/protocols/osi3/icmpv4.yml" afterPath="$PROJECT_DIR$/protocols/osi3/icmpv4.yml" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/protocols/osi3/ipv4.yml" afterPath="$PROJECT_DIR$/protocols/osi3/ipv4.yml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/schema.yml" afterPath="$PROJECT_DIR$/schema.yml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/schema.yml" afterPath="$PROJECT_DIR$/schema.yml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/validate.py" afterPath="$PROJECT_DIR$/validate.py" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/validate.py" afterPath="$PROJECT_DIR$/validate.py" />
|
||||||
</list>
|
</list>
|
||||||
|
@ -29,10 +32,10 @@
|
||||||
<file leaf-file-name="validate.py" pinned="false" current-in-tab="true">
|
<file leaf-file-name="validate.py" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/validate.py">
|
<entry file="file://$PROJECT_DIR$/validate.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="216">
|
<state relative-caret-position="410">
|
||||||
<caret line="12" column="33" selection-start-line="12" selection-start-column="33" selection-end-line="12" selection-end-column="33" />
|
<caret line="39" column="43" selection-start-line="39" selection-start-column="43" selection-end-line="39" selection-end-column="43" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -130,7 +133,7 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
|
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
|
||||||
<property name="settings.editor.splitter.proportion" value="0.2" />
|
<property name="settings.editor.splitter.proportion" value="0.2" />
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="Python.validate">
|
<component name="RunManager" selected="Python.validate">
|
||||||
|
@ -147,7 +150,7 @@
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
<module name="npd" />
|
<module name="npd" />
|
||||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/validate.py" />
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/validate.py" />
|
||||||
<option name="PARAMETERS" value="example.yml" />
|
<option name="PARAMETERS" value="--all -v" />
|
||||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
<method />
|
<method />
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -285,8 +288,26 @@
|
||||||
<option name="USE_KEYWORD" value="false" />
|
<option name="USE_KEYWORD" value="false" />
|
||||||
<method />
|
<method />
|
||||||
</configuration>
|
</configuration>
|
||||||
<list size="1">
|
<configuration default="false" name="validate single file" type="PythonConfigurationType" factoryName="Python">
|
||||||
<item index="0" class="java.lang.String" itemvalue="Python.validate" />
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<module name="npd" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/validate.py" />
|
||||||
|
<option name="PARAMETERS" value="-f example.yml" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
<list size="2">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="Python.validate single file" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="Python.validate" />
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list size="1">
|
<list size="1">
|
||||||
|
@ -351,7 +372,7 @@
|
||||||
<state relative-caret-position="0">
|
<state relative-caret-position="0">
|
||||||
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -361,7 +382,7 @@
|
||||||
<state relative-caret-position="234">
|
<state relative-caret-position="234">
|
||||||
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -378,7 +399,7 @@
|
||||||
<state relative-caret-position="234">
|
<state relative-caret-position="234">
|
||||||
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -395,7 +416,7 @@
|
||||||
<state relative-caret-position="234">
|
<state relative-caret-position="234">
|
||||||
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
<caret line="14" column="25" selection-start-line="14" selection-start-column="25" selection-end-line="14" selection-end-column="25" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -439,10 +460,10 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/validate.py">
|
<entry file="file://$PROJECT_DIR$/validate.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="216">
|
<state relative-caret-position="410">
|
||||||
<caret line="12" column="33" selection-start-line="12" selection-start-column="33" selection-end-line="12" selection-end-column="33" />
|
<caret line="39" column="43" selection-start-line="39" selection-start-column="43" selection-end-line="39" selection-end-column="43" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#1#11#0" expanded="true" />
|
<element signature="e#0#10#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -15,4 +15,5 @@ protocol: &icmpv4
|
||||||
desc: rest of header
|
desc: rest of header
|
||||||
length: 4
|
length: 4
|
||||||
- field: data
|
- field: data
|
||||||
optional: true
|
data: true
|
||||||
|
optional: true
|
||||||
|
|
20
schema.yml
20
schema.yml
|
@ -26,12 +26,16 @@ definitions:
|
||||||
field:
|
field:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
length:
|
||||||
|
type: integer
|
||||||
|
reflength:
|
||||||
|
type: string
|
||||||
|
data:
|
||||||
|
type: boolean
|
||||||
field:
|
field:
|
||||||
type: string
|
type: string
|
||||||
desc:
|
desc:
|
||||||
type: string
|
type: string
|
||||||
length:
|
|
||||||
type: integer
|
|
||||||
bitfield:
|
bitfield:
|
||||||
type: boolean
|
type: boolean
|
||||||
optional:
|
optional:
|
||||||
|
@ -40,16 +44,18 @@ definitions:
|
||||||
type: boolean
|
type: boolean
|
||||||
nextlayer:
|
nextlayer:
|
||||||
type: boolean
|
type: boolean
|
||||||
data:
|
|
||||||
type: boolean
|
|
||||||
reference:
|
reference:
|
||||||
type: string
|
type: string
|
||||||
reflength:
|
|
||||||
type: string
|
|
||||||
subfields:
|
subfields:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/definitions/field"
|
$ref: "#/definitions/field"
|
||||||
|
oneOf:
|
||||||
|
- required:
|
||||||
|
- length
|
||||||
|
- required:
|
||||||
|
- reflength
|
||||||
|
- required:
|
||||||
|
- data
|
||||||
required:
|
required:
|
||||||
- field
|
- field
|
||||||
- length
|
|
||||||
|
|
42
validate.py
42
validate.py
|
@ -1,24 +1,46 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
import yaml
|
import yaml
|
||||||
|
import argparse
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
schemafile = "schema.yml"
|
parser = argparse.ArgumentParser()
|
||||||
schema = None
|
parser.add_argument("--all", help="Validate all protocols.", action="store_true")
|
||||||
|
parser.add_argument("-f", help="Validate file.", default=None)
|
||||||
|
parser.add_argument("-s", help="Use schema file.", default="schema.yml")
|
||||||
|
parser.add_argument("-v", help="Verbosity...", action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
schemafile = args.s
|
||||||
schemadata = None
|
schemadata = None
|
||||||
with open(schemafile, "r") as f:
|
with open(schemafile, "r") as f:
|
||||||
schemadata = yaml.load(f)
|
schemadata = yaml.load(f)
|
||||||
data = None
|
if args.all:
|
||||||
with open(argv[1], "r") as f:
|
# search for files and validate them.
|
||||||
data = yaml.load(f)
|
print("Validating all files in protocols/osi*")
|
||||||
# get all yml files from protocols
|
list = glob.glob("protocols/osi*/*.yml", recursive=True)
|
||||||
# validate with
|
for file in list:
|
||||||
validate(data, schemadata)
|
print("Validating file: " + file)
|
||||||
|
validateFile(file, schemadata, True if args.v else False)
|
||||||
|
pass
|
||||||
|
elif args.f is not None:
|
||||||
|
validateFile(args.f, schemadata, True if args.v else False)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def validateFile(file, schema, verbose=False):
|
||||||
|
data = None
|
||||||
|
with open(file, "r") as f:
|
||||||
|
data = yaml.load(f)
|
||||||
|
try:
|
||||||
|
validate(data, schema)
|
||||||
|
print(file + " is valid.")
|
||||||
|
except:
|
||||||
|
print("Failed to validate: " + file)
|
||||||
|
if verbose:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
|
Reference in New Issue