Skip to content

Check_schema_boundary

FieldValue
TypeSkill Resource
Source~/.copilot/skills/frontend/scripts/check_schema_boundary.sh
DescriptionNot specified

Source Content

#!/usr/bin/env bash
# Check Zod usage follows the schema-at-boundary convention: every exported
# schema has a matching `z.infer<typeof X>` type export, and no schema uses
# `z.any()` (an escape hatch that defeats the point of validating boundaries).
#
# Usage: check_schema_boundary.sh <schema-file-or-dir>
set -uo pipefail
TARGET="${1:-.}"
fail=0
files=$(find "$TARGET" -name '*.ts' 2>/dev/null | xargs grep -l 'z\.object\|z\.union\|z\.discriminatedUnion' 2>/dev/null)
if [[ -z "$files" ]]; then
echo "⚠️ no zod schema files found under $TARGET"
exit 0
fi
for f in $files; do
schemas=$(grep -oE 'export const [A-Za-z0-9_]+Schema' "$f" | awk '{print $3}')
for s in $schemas; do
typename="${s%Schema}"
if grep -q "z\.infer<typeof ${s}>" "$f"; then
echo "$f: $s has a matching z.infer type export"
else
echo "$f: $s has no \`z.infer<typeof $s>\` export (expected something like: export type $typename = z.infer<typeof $s>)"
fail=1
fi
done
if grep -q 'z\.any()' "$f"; then
echo "$f: uses z.any() — replace with a real shape or z.unknown() + a narrowing check"
fail=1
fi
done
exit "$fail"