- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains - Omit embedded publish git dirs and empty placeholders from index Made-with: Cursor
76 lines
3.4 KiB
Bash
Executable File
76 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Validate dbis-institutional examples against JSON Schemas (draft 2020-12).
|
|
# Uses `check-jsonschema` when available (pip install check-jsonschema).
|
|
# In CI, install first: pip install check-jsonschema
|
|
#
|
|
# Env:
|
|
# SCHEMA_STRICT=1 exit 1 if check-jsonschema is missing (default: skip with 0)
|
|
#
|
|
set -euo pipefail
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
SCHEMA_DIR="$ROOT/config/dbis-institutional/schemas"
|
|
EX_DIR="$ROOT/config/dbis-institutional/examples"
|
|
|
|
# validate_json_array EX_FILE SCHEMA_FILE LABEL
|
|
validate_json_array() {
|
|
local ex_file="$1" schema_file="$2" label="$3"
|
|
if [[ ! -f "$ex_file" ]]; then
|
|
return 0
|
|
fi
|
|
if ! command -v jq &>/dev/null; then
|
|
echo "error: jq is required for $label validation" >&2
|
|
exit 1
|
|
fi
|
|
local n
|
|
n=$(jq 'length' "$ex_file")
|
|
if [[ "${n:-0}" -lt 1 ]]; then
|
|
echo "error: $ex_file must be a non-empty array" >&2
|
|
exit 1
|
|
fi
|
|
local batch_tmp idx
|
|
batch_tmp="$(mktemp)"
|
|
trap 'rm -f "$batch_tmp"' RETURN
|
|
idx=0
|
|
while IFS= read -r line; do
|
|
echo "$line" >"$batch_tmp"
|
|
check-jsonschema --schemafile "$schema_file" "$batch_tmp"
|
|
idx=$((idx + 1))
|
|
done < <(jq -c '.[]' "$ex_file")
|
|
echo "OK $label ($idx items)"
|
|
rm -f "$batch_tmp"
|
|
trap - RETURN
|
|
}
|
|
|
|
if ! command -v check-jsonschema &>/dev/null; then
|
|
if [[ "${SCHEMA_STRICT:-0}" == "1" ]]; then
|
|
echo "error: check-jsonschema not found; pip install check-jsonschema" >&2
|
|
exit 1
|
|
fi
|
|
echo "skip: check-jsonschema not installed (pip install check-jsonschema); JSON parse still covered by validate-dbis-institutional-json.sh"
|
|
if command -v node &>/dev/null && [[ -f "$ROOT/scripts/verify/validate-address-registry-xe-aliases.mjs" ]]; then
|
|
node "$ROOT/scripts/verify/validate-address-registry-xe-aliases.mjs" || exit 1
|
|
echo "OK web3_eth_iban (XE) examples only (no schema tool)"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/settlement-event.schema.json" "$EX_DIR/settlement-event.example.json"
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/settlement-event.schema.json" "$EX_DIR/settlement-event.chain138-primary.example.json"
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/settlement-event.schema.json" "$EX_DIR/settlement-event.min.json"
|
|
validate_json_array "$EX_DIR/settlement-events-batch.example.json" "$SCHEMA_DIR/settlement-event.schema.json" "settlement-events-batch"
|
|
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/address-registry-entry.schema.json" "$EX_DIR/address-registry-entry.example.json"
|
|
validate_json_array "$EX_DIR/address-registry-entries-batch.example.json" "$SCHEMA_DIR/address-registry-entry.schema.json" "address-registry-entries-batch"
|
|
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/trust.schema.json" "$EX_DIR/trust.json"
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/governance.schema.json" "$EX_DIR/governance.json"
|
|
check-jsonschema --schemafile "$SCHEMA_DIR/policy-manifest.schema.json" "$EX_DIR/policy.json"
|
|
|
|
if command -v node &>/dev/null && [[ -f "$ROOT/scripts/verify/validate-address-registry-xe-aliases.mjs" ]]; then
|
|
node "$ROOT/scripts/verify/validate-address-registry-xe-aliases.mjs" || exit 1
|
|
else
|
|
echo "skip: node or validate-address-registry-xe-aliases.mjs missing (XE alias check)"
|
|
fi
|
|
|
|
echo "OK dbis-institutional schema validation (settlement-event, settlement-event.chain138-primary, settlement-events-batch, address-registry-entry, address-registry-entries-batch, trust, governance, policy-manifest, web3_eth_iban examples)"
|