- 3 CRUD JSON files: customer_balance, accounting_records, sync_state - Build script with model validation, CRUD validation, DDL generation - DDL: db/schema.sql (72 lines, 7 tables) - Scripts: validate_models.py, validate_crud.py, generate_ddl.py
33 lines
940 B
Python
Executable File
33 lines
940 B
Python
Executable File
#!/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()
|