|
7 | 7 | import re |
8 | 8 | from pathlib import Path |
9 | 9 | import jsonschema.validators |
| 10 | +import referencing |
| 11 | +from referencing import Registry, Resource |
10 | 12 | from jsonschema.validators import Draft7Validator |
11 | | -from jsonschema import validate, RefResolver |
| 13 | +from jsonschema import validate |
12 | 14 | from jsonschema import exceptions as JSONSchemaExceptions |
13 | 15 |
|
14 | 16 | schemas = {} |
|
20 | 22 | schemaDir = os.path.join(".", "schema") |
21 | 23 | schemaAbsPath = os.path.abspath(schemaDir) |
22 | 24 | schemaURI = Path(schemaAbsPath).as_uri() + "/" |
| 25 | +resource_list = [] |
23 | 26 | for schemaFileName in os.listdir(schemaDir): |
24 | 27 | with open( |
25 | 28 | os.path.join( |
|
39 | 42 | if gameKey not in schemas: |
40 | 43 | schemas[gameKey] = {} |
41 | 44 | try: |
42 | | - schemas[gameKey][schemaKey] = json.load(schemaFile) |
| 45 | + schema = json.load(schemaFile) |
| 46 | + schemas[gameKey][schemaKey] = schema |
| 47 | + resource = Resource.from_contents(schema) |
| 48 | + resource_list.append((schemaFileName, resource)) |
43 | 49 | except json.JSONDecodeError as e: |
44 | 50 | jsonFile.seek(0) |
45 | 51 | errorLine = "" |
|
62 | 68 | ]) |
63 | 69 | bail = True |
64 | 70 |
|
| 71 | +registry = Registry().with_resources(resource_list).crawl() |
65 | 72 | print("VALIDATE") |
66 | 73 |
|
67 | 74 | # connections |
|
113 | 120 | result = validate( |
114 | 121 | instance=connectionJSON, |
115 | 122 | schema=schemas["m3"]["connection"], |
116 | | - resolver=RefResolver( |
117 | | - base_uri=schemaURI, |
118 | | - referrer=schemas["m3"]["connection"] |
119 | | - ) |
| 123 | + registry=registry, |
120 | 124 | ) |
121 | 125 | except JSONSchemaExceptions.ValidationError as e: |
122 | 126 | errors.append([ |
|
175 | 179 | result = validate( |
176 | 180 | instance=enemiesJSON, |
177 | 181 | schema=schema, |
178 | | - resolver=RefResolver( |
179 | | - base_uri=schemaURI, |
180 | | - referrer=schema |
181 | | - ) |
| 182 | + registry=registry, |
182 | 183 | ) |
183 | 184 | except JSONSchemaExceptions.ValidationError as e: |
184 | 185 | errors.append([ |
|
197 | 198 | print(" REGIONS") |
198 | 199 | room_validator = Draft7Validator( |
199 | 200 | schema=schemas["m3"]["room"], |
200 | | - resolver=RefResolver( |
201 | | - base_uri=schemaURI, |
202 | | - referrer=schemas["m3"]["room"] |
203 | | - ) |
| 201 | + registry=registry, |
204 | 202 | ) |
205 | 203 | for region in os.listdir(os.path.join(".", "region")): |
206 | 204 | if os.path.isdir(os.path.join(".", "region", region)): |
|
304 | 302 | result = validate( |
305 | 303 | instance=weaponsJSON, |
306 | 304 | schema=schemas["m3"]["weapons"], |
307 | | - resolver=RefResolver( |
308 | | - base_uri=schemaURI, |
309 | | - referrer=schemas["m3"]["weapons"] |
310 | | - ) |
| 305 | + registry=registry, |
311 | 306 | ) |
312 | 307 | except JSONSchemaExceptions.ValidationError as e: |
313 | 308 | errors.append([ |
|
363 | 358 | result = validate( |
364 | 359 | instance=fileJSON, |
365 | 360 | schema=schemas["m3"][rootType], |
366 | | - resolver=RefResolver( |
367 | | - base_uri=schemaURI, |
368 | | - referrer=schemas["m3"][rootType] |
369 | | - ) |
| 361 | + registry=registry, |
370 | 362 | ) |
371 | 363 | except JSONSchemaExceptions.ValidationError as e: |
372 | 364 | errors.append([ |
|
0 commit comments