Skip to content

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/schemas

As 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.

Every exercise type comes with two schemas:

  • exercise/<TYPE>.json
    describes the structure and is checked whenever createExercise or updateExercise is called.

  • exercise/<TYPE>.complete.json
    describes what else it takes to publish an exercise. Exercise.valid then 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.

To head off API errors in the first place, we recommend setting up a validator. For example:

Changes to the schemas are announced as usual in the API Changelog.