Skip to content

Commit

Permalink
Fix deprecated draft7_format_checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nusantara-self committed Oct 22, 2024
1 parent f7917e4 commit 3c80ac0
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions utils/flavors/check_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"""

import json
import jsonschema
from jsonschema import validate
from jsonschema import Draft7Validator, FormatChecker
import sys
import os
import argparse
Expand Down Expand Up @@ -62,23 +61,23 @@ def fixJsonFlavorFile(jsonfile:dict) -> dict:
jsonfile["screenshots"] = screenshots
return jsonfile

def validateFlavorFormat(flavorfile:str, schemafile:str, fix:bool) -> str:
def validateFlavorFormat(flavorfile: str, schemafile: str, fix: bool) -> str:
flavorSchema = openJsonFile(schemafile)
fjson = openJsonFile(flavorfile)
validator = jsonschema.Draft7Validator(flavorSchema, format_checker=jsonschema.draft7_format_checker)
errors = sorted(validator.iter_errors(fjson),key=lambda e: e.path)
if not errors:
formatchecker = FormatChecker()
validator = Draft7Validator(flavorSchema, format_checker=formatchecker)
errors = sorted(validator.iter_errors(fjson), key=lambda e: e.path)
if not errors:
printSuccess(True, flavorfile)
else:
printSuccess(False, flavorfile)
for error in errors:
print("{}: {}".format(error.path,error.message))
print("{}: {}".format(error.path, error.message))
if fix:
print("Fixing {}".format(flavorfile))
j = fixJsonFlavorFile(fjson)
with open(flavorfile, 'w+') as fj:
fj.write(json.dumps(j,indent=4))
fj.write(json.dumps(j, indent=4))
fj.close()


Expand Down Expand Up @@ -118,4 +117,4 @@ def run():
print(e)

if __name__ == '__main__':
run()
run()

0 comments on commit 3c80ac0

Please sign in to comment.