|
| 1 | +# Grading Function Request/Response Schema |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This repo holds the schemas used for the grading function request and response bodies. This is used to check that: |
| 6 | + |
| 7 | +- All requests from the frontend have the correct JSON structure so they can be interpreted by a grading function. |
| 8 | +- All grading function responses have the correct JSON structure so they can be interpeted by the frontend to show the correct answer and any feedback. |
| 9 | + |
| 10 | +## Structure (v1) |
| 11 | + |
| 12 | +### Request |
| 13 | + |
| 14 | +The request body can have three fields: |
| 15 | + |
| 16 | +- `response`, which contains the answers provided by the student. This can be anything: a string, boolean, number, array or object. |
| 17 | +- `answer`, which contains the correct answer held in the problem set database. This can also be anything. |
| 18 | +- `params`, which contains extra arguments for determining whether the student's answer is correct. |
| 19 | + |
| 20 | +Only `response` and `answer` are required. Any extra fields will cause the validation to fail. |
| 21 | + |
| 22 | +### Response |
| 23 | + |
| 24 | +The response body can have three fields: |
| 25 | + |
| 26 | +- `command`, which can only be either `"healthcheck"` or `"grade"`. |
| 27 | + |
| 28 | + `"healthcheck"` is used only by the backend to check the grading function is alive and working correctly. `"grade"` is used for carrying out a grading request. |
| 29 | + |
| 30 | +- `result`, which contains the results from the healthcheck or grading request. If the results are from a grading request, this is the dictionary that is returned from `grading_function()`. |
| 31 | + |
| 32 | + - If the command is `grade`, then `results` must be an object and can have two fields: |
| 33 | + |
| 34 | + - `is_correct`, which must be a boolean. |
| 35 | + - `feedback`, which contains any feedback about the student's answer. This can be an object, array or string. |
| 36 | + |
| 37 | + Only `is_correct` is required. |
| 38 | + |
| 39 | + - If the command is `healthcheck`, then `results` must contain: |
| 40 | + |
| 41 | + - `tests_passed`, which must be a boolean. |
| 42 | + - `successes`, which contains the names of tests that passed and the time it took. |
| 43 | + - `failures`, which contains the names of tests that failed. |
| 44 | + - `errors`, which contains the names of tests that resulted in an error. |
| 45 | + |
| 46 | + All fields are required. |
| 47 | + |
| 48 | +- `error`, which contains information about any error that was thrown from a request. This can have two fields: |
| 49 | + |
| 50 | + - `message`, i.e. a human-readable explanation of the cause. This must be a string. |
| 51 | + |
| 52 | + - `error_thrown`, which contains more details about the error, in particular if the validation, parsing or the grading function caused an error. This must be an object although its content isn't validated. |
| 53 | + |
| 54 | + Only `message` is required. |
| 55 | + |
| 56 | +Both `command` and `result` are required, unless an error is thrown, in which only `error` can exist. Any extra fields will cause the validation to fail. |
| 57 | + |
| 58 | +## Contact |
| 59 | + |
| 60 | +For questions about these schemas or you would like to discuss possible changes, please [email Peter Johnson](mailto:peter.johnson@imperial.ac.uk). |
0 commit comments