@@ -27,7 +27,7 @@ def make_asn1_parsable(json_str, json_tweaks_callback):
2727 return json_str
2828
2929
30- def path_to_schema_name (path ):
30+ def path_to_root_type (path ):
3131 # Strip the directory path and extension
3232 name = os .path .splitext (os .path .basename (path ))[0 ]
3333 # Remove "_X" if it ends with a number
@@ -39,22 +39,22 @@ def path_to_schema_name(path):
3939 return name
4040
4141
42- def validate (schema , path , schema_name = None , json_tweaks_callback = None ):
43- print ("* Validating: " , path )
42+ def validate (schema , json_file , root_type = None , json_tweaks_callback = None ):
43+ print ("* Validating: " , json_file )
4444
45- if schema_name is None :
46- schema_name = path_to_schema_name ( path )
45+ if root_type is None :
46+ root_type = path_to_root_type ( json_file )
4747
4848 # Decode from json using the schema
49- json_bytes = open (path , "rb" ).read ()
49+ json_bytes = open (json_file , "rb" ).read ()
5050 json_str_org = json_bytes .decode ('utf-8' )
5151 json_str_org = make_asn1_parsable (json_str_org , json_tweaks_callback )
5252
5353 json_bytes = json_str_org .encode ('utf-8' )
54- decoded = schema .decode (schema_name , json_bytes , check_constraints = True )
54+ decoded = schema .decode (root_type , json_bytes , check_constraints = True )
5555
5656 # Encode to json using the schema
57- encoded = schema .encode (schema_name , decoded , check_constraints = True )
57+ encoded = schema .encode (root_type , decoded , check_constraints = True )
5858 # Original json uses snake case, asn1 requires kebab case
5959 json_str = encoded .decode ('utf-8' )
6060 json_obj = json .loads (json_str )
@@ -66,7 +66,15 @@ def validate(schema, path, schema_name = None, json_tweaks_callback = None):
6666
6767def validate_group (group_name , group_schema , spec_name ):
6868 print (f"\n [Validating { group_name } ({ spec_name } )]" )
69- schema = asn1tools .compile_files (get_schema_files (spec_name == "full" ) + [group_schema ], codec = "jer" )
69+ schema_files = get_schema_files (spec_name == "full" )
70+ if group_schema is not None :
71+ schema_files += [group_schema ]
72+ schema = asn1tools .compile_files (schema_files , codec = "jer" )
73+ # A bit of a hack. Consider passing the schema root type as param
74+ if group_name == "codec" :
75+ root_type = None
76+ else :
77+ root_type = "TestCase"
7078 for json_file in glob .glob (f"{ spec_name } /*.json" ):
71- validate (schema , json_file , "TestCase" )
79+ validate (schema , json_file , root_type )
7280
0 commit comments