Skip to main content

Input Santization

Writing a Validation#

APIs which support the “validations” tag uses standard AJV validation schemas and detailed design options can be found here. Most of the resources provided by data trucker use the input of JSON format, this data needs to be sanitized for processing before the job handler picks up the data. AJV schemas servers as input sanitization and verifies the input schema before the actual workload.

AJV provides us a run kit to test various input schemas available here

Here is a sample code block on writing ajv schemas for#

URL: /api/v1/resourcesTYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): {        "resourcename": "ajvtest",        ...        ...        ...        "validations": {          "type": "object",          "properties": {            "field1": {         ----> field1 represents data input when this resource is queried              "type": "string",              "pattern": "^[a-z0-9]*$",              "maxLength": 8            }          }        }      }
Response: 201 OK