Schema Validation
GraphQL already describes the vast majority of fields in detail. With complex JSON fields it reaches its limits. So we describe those with JSON Schema and check the data on every write.
Every schema we validate against can be found through our catalog:
https://api-prod.mileslearning.net/schemasAs a rule, invalid data is rejected with a JSON_INVALID error. The response carries the details of each validation error, so fixing them is easier.
Exercise content
Section titled “Exercise content”Every exercise type comes with two schemas:
-
exercise/<TYPE>.json
describes the structure and is checked whenevercreateExerciseorupdateExerciseis called. -
exercise/<TYPE>.complete.json
describes what else it takes to publish an exercise.Exercise.validthen reports the result of that check.
Some rules cannot be expressed in JSON Schema at all, such as an answer having to reference an existing key. We point such extra rules out in the schema, in the description of the field they apply to.
Validate before you write
Section titled “Validate before you write”To head off API errors in the first place, we recommend setting up a validator. For example:
- Ajv for JavaScript
- jsonschema for Python
- networknt for Java
Changes to the schemas are announced as usual in the API Changelog.