#!/usr/bin/env python3 """Validate SageAPI CRUD JSON definitions.""" import json import os import sys def validate_crud(json_dir='json'): errors = 0 for f in sorted(os.listdir(json_dir)): if not f.endswith('.json'): continue filepath = os.path.join(json_dir, f) with open(filepath) as fh: data = json.load(fh) for tblname, config in data.items(): if 'params' not in config: print(f'ERROR: {f} root key "{tblname}" missing "params"') errors += 1 if 'fields' not in config: print(f'ERROR: {f} root key "{tblname}" missing "fields"') errors += 1 if not errors: print(f' OK: {f} ({tblname})') if errors: print(f'\n{errors} error(s) found') sys.exit(1) print('All CRUD definitions valid') if __name__ == '__main__': validate_crud()