Skip to content

Commit

Permalink
add JSON schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gatamar committed Sep 14, 2024
1 parent 1568ba5 commit 88e5101
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-language-support-counters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Update language support counters in README
on:
push:
paths:
- '*.json' # Only trigger when JSON files are updated
- './src/*.json'

jobs:
count-json-entries:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/validate-json-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: JSON Schema Validation

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
validate-json-schema:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Set up Node.js (since we'll use a Node package for validation)
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # or any version you prefer

# Step 3: Install Ajv CLI for JSON schema validation
- name: Install Ajv JSON Schema Validator
run: npm install -g ajv-cli

# Step 4: Validate JSON files against the schema
- name: Validate JSON files
run: |
for file in ./src/*.json; do
ajv validate -s ./schema/schema.json -d "$file" || exit 1
done
9 changes: 0 additions & 9 deletions polish.json

This file was deleted.

40 changes: 40 additions & 0 deletions schema/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"base": {
"type": "string"
},
"pre_context": {
"type": "array",
"items": {
"type": "string"
}
},
"post_context": {
"type": "string"
},
"context": {
"type": "string"
},
"meaning": {
"type": "array",
"items": {
"type": "string"
}
},
"example": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["id", "base", "meaning"]
}
}
File renamed without changes.
9 changes: 9 additions & 0 deletions src/polish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"id": 1,
"base": "wyjść z siebie",
"meaning": ["silną reakcję emocjonalną, zwykle związaną ze złością, frustracją lub zdenerwowaniem"],
"example": []
}

]
2 changes: 1 addition & 1 deletion ukrainian.json → src/ukrainian.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"id": 2,
"base": "від Адама",
"pre_context": "починати",
"pre_context": ["починати"],
"meaning": ["дуже здалека, з самого початку"],
"example": ["з безперестанними охами, сапанням та умліванням Прохіра розказувала. Вона почала від Адама (М. Коцюбинський)"]
},
Expand Down

0 comments on commit 88e5101

Please sign in to comment.