Skip to content

Commit

Permalink
🧹 Replace 'pajv' dependency with 'ajv-cli' (#5569)
Browse files Browse the repository at this point in the history
We were using a JSON Schema validator that was last updated 7 years ago, using a dependency called `deasync` that started causing problems building on Windows.

Replace with a different JSON Schema validator written in Python (`check-jsonschema`). An obvious alternative in NPM would have been `ajv-cli` which was last updated 3 years ago and also had vulnerable NPM dependencies. This removes all NPM vulnerability warnings and removes `deasync` from our dependency path.
  • Loading branch information
rix0rrr authored May 27, 2024
1 parent d3527a3 commit aeab6e3
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2,020 deletions.
10 changes: 4 additions & 6 deletions build-tools/github/validate-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ echo "------> Validating YAML"
# 'npx pajv validate' just hangs. Running the 'pajv' binary directly without the use of
# 'npx' does work... so we're just going to ¯\_(ツ)_/¯ and do that.

pajv=node_modules/.bin/pajv

all_schemas=$(find content -name \*.schema.json)

failures=false
Expand All @@ -33,16 +31,16 @@ for schema in $all_schemas; do
dir=$(dirname $schema)
echo "------> Validating $(basename $dir)"

# Run pajv, remove all the lines that end in the word ' valid' -- those are not interesting
# and just add noise.
if ! $pajv validate --errors=text -s $schema -d "$dir/*.yaml" > validate.txt; then
cat validate.txt | grep -vE ' valid$' || true
# Run the validator.
if ! check-jsonschema -o text --schemafile $schema $dir/*.yaml > validate.txt; then
cat validate.txt || true
failures=true
fi
rm validate.txt
done

# Also run the structure validator which compares en.yaml to the other languages
echo "------> Checking data completeness w.r.t en.yaml"
python tools/check-yaml-structure.py

if $failures; then
Expand Down
30 changes: 16 additions & 14 deletions content/achievements/achievements.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
"type": "object",
"description": "Achievements with title and text",
"additionalProperties": {
"$ref": "#/Achievement"
"$ref": "#/definitions/Achievement"
}
}
},
"required": [
"achievements"
],
"Achievement": {
"type": "object",
"additionalProperties": false,
"properties": {
"title": {
"type": "string",
"description": "Achievement title"
},
"text": {
"type": "string",
"description": "Achievement text"
}
}
"definitions": {
"Achievement": {
"type": "object",
"additionalProperties": false,
"properties": {
"title": {
"type": "string",
"description": "Achievement title"
},
"text": {
"type": "string",
"description": "Achievement text"
}
}
}
}
}
44 changes: 23 additions & 21 deletions content/parsons/parsons.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@
"type": "object",
"description": "Levels with exercise for the Hedy Parsons",
"additionalProperties": {
"$ref": "#/Level"
"$ref": "#/definitions/Level"
}
}
},
"required": [
"levels"
],
"Level": {
"type": "object",
"additionalProperties": {
"$ref": "#/Exercise"
}
},
"Exercise": {
"type": "object",
"properties": {
"story": {
"type": "string"
},
"code": {
"type": "string"
"definitions": {
"Level": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Exercise"
}
},
"required": [
"story",
"code"
]
},
"additionalProperties": false
"Exercise": {
"type": "object",
"properties": {
"story": {
"type": "string"
},
"code": {
"type": "string"
}
},
"required": [
"story",
"code"
],
"additionalProperties": false
}
}
}
112 changes: 57 additions & 55 deletions content/quizzes/quizzes.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,72 @@
"type": "object",
"description": "Levels with questions for the Hedy Quiz",
"additionalProperties": {
"$ref": "#/Level"
"$ref": "#/definitions/Level"
}
}
},
"required": [
"levels"
],
"Level": {
"type": "object",
"additionalProperties": {
"$ref": "#/Question"
}
},
"Question": {
"type": "object",
"properties": {
"question_text": {
"type": "string"
},
"code": {
"type": "string"
},
"output": {
"type": "string"
},
"mp_choice_options": {
"type": "array",
"items": {
"$ref": "#/Option"
}
},
"correct_answer": {
"type": "string",
"enum": [
"A",
"B",
"C",
"D"
]
},
"hint": {
"type": "string"
},
"question_score": {
"type": "string"
"definitions": {
"Level": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Question"
}
},
"required": [
"question_text",
"mp_choice_options",
"correct_answer",
"question_score"
]
},
"Option": {
"type": "object",
"properties": {
"option": {
"type": "string"
"Question": {
"type": "object",
"properties": {
"question_text": {
"type": "string"
},
"code": {
"type": "string"
},
"output": {
"type": "string"
},
"mp_choice_options": {
"type": "array",
"items": {
"$ref": "#/definitions/Option"
}
},
"correct_answer": {
"type": "string",
"enum": [
"A",
"B",
"C",
"D"
]
},
"hint": {
"type": "string"
},
"question_score": {
"type": "string"
}
},
"feedback": {
"type": "string"
}
"required": [
"question_text",
"mp_choice_options",
"correct_answer",
"question_score"
]
},
"additionalProperties": false
"Option": {
"type": "object",
"properties": {
"option": {
"type": "string"
},
"feedback": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
Loading

0 comments on commit aeab6e3

Please sign in to comment.