Skip to content

Commit 773fdb4

Browse files
Add TypeScript validation scripts for local testing
- Add package.json with npm test for schema and example validation - Add scripts/validate-schemas.ts to compile all JSON schemas - Add scripts/validate-examples.ts to validate example documents - Simplify CI workflow to use npm test - Use Ajv 2020-12 draft for JSON Schema validation
1 parent 3076ff2 commit 773fdb4

6 files changed

Lines changed: 884 additions & 58 deletions

File tree

.github/workflows/validate-schemas.yml

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ on:
55
paths:
66
- 'schemas/**'
77
- 'examples/**'
8+
- 'scripts/**'
9+
- 'package.json'
810
- '.github/workflows/validate-schemas.yml'
911
pull_request:
1012
paths:
1113
- 'schemas/**'
1214
- 'examples/**'
15+
- 'scripts/**'
16+
- 'package.json'
1317
- '.github/workflows/validate-schemas.yml'
1418

1519
jobs:
@@ -21,63 +25,10 @@ jobs:
2125
- uses: actions/setup-node@v4
2226
with:
2327
node-version: '20'
28+
cache: 'npm'
2429

25-
- name: Install ajv-cli
26-
run: npm install -g ajv-cli ajv-formats
30+
- name: Install dependencies
31+
run: npm ci
2732

28-
- name: Validate schemas compile
29-
run: |
30-
# Compile standalone schemas
31-
for f in schemas/anchor.schema.json schemas/asset-index.schema.json \
32-
schemas/content.schema.json schemas/dublin-core.schema.json \
33-
schemas/manifest.schema.json schemas/precise-layout.schema.json \
34-
schemas/presentation.schema.json schemas/provenance.schema.json \
35-
schemas/semantic.schema.json; do
36-
echo "Compiling $f..."
37-
ajv compile -s "$f" --spec=draft2020 --strict=false
38-
done
39-
40-
# Compile schemas with cross-references (need -r for referenced schemas)
41-
echo "Compiling schemas/annotations.schema.json..."
42-
ajv compile -s schemas/annotations.schema.json \
43-
-r schemas/anchor.schema.json --spec=draft2020 --strict=false
44-
echo "Compiling schemas/phantoms.schema.json..."
45-
ajv compile -s schemas/phantoms.schema.json \
46-
-r schemas/anchor.schema.json --spec=draft2020 --strict=false
47-
48-
- name: Validate example documents
49-
run: |
50-
# Validate simple-document
51-
ajv validate -s schemas/manifest.schema.json \
52-
-d examples/simple-document/manifest.json \
53-
--spec=draft2020 --strict=false
54-
ajv validate -s schemas/content.schema.json \
55-
-d examples/simple-document/content/document.json \
56-
--spec=draft2020 --strict=false
57-
ajv validate -s schemas/dublin-core.schema.json \
58-
-d examples/simple-document/metadata/dublin-core.json \
59-
--spec=draft2020 --strict=false
60-
61-
# Validate signed-document
62-
ajv validate -s schemas/manifest.schema.json \
63-
-d examples/signed-document/manifest.json \
64-
--spec=draft2020 --strict=false
65-
ajv validate -s schemas/content.schema.json \
66-
-d examples/signed-document/content/document.json \
67-
--spec=draft2020 --strict=false
68-
ajv validate -s schemas/dublin-core.schema.json \
69-
-d examples/signed-document/metadata/dublin-core.json \
70-
--spec=draft2020 --strict=false
71-
72-
# Validate comprehensive-document (if exists)
73-
if [ -d examples/comprehensive-document ]; then
74-
ajv validate -s schemas/manifest.schema.json \
75-
-d examples/comprehensive-document/manifest.json \
76-
--spec=draft2020 --strict=false
77-
ajv validate -s schemas/content.schema.json \
78-
-d examples/comprehensive-document/content/document.json \
79-
--spec=draft2020 --strict=false
80-
ajv validate -s schemas/dublin-core.schema.json \
81-
-d examples/comprehensive-document/metadata/dublin-core.json \
82-
--spec=draft2020 --strict=false
83-
fi
33+
- name: Validate schemas and examples
34+
run: npm test

0 commit comments

Comments
 (0)