Additional Data Formats | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Schema Validation
Instructor: Artem Bondar
Lesson Summary
This lesson covers the schema validation feature in the AJV library, specifically focusing on adding custom formats for more granular validation. Key Steps to Add Custom Formats Install AJV Formats: Search for "AJV formats" and install the package using npm. npm install ajv-formats Import the Package: Add the import statement in your project: import addFormats from 'ajv-formats'; Integrate with AJV: Call the method and pass the AJV instance: addFormats(ajv); Using Custom Formats After adding formats, you can validate specific types such as: date-time email URI IP For example, to validate the createdAt and updatedAt properties as date-time , you would modify your schema: "createdAt": { "type": "string", "format": "date-time" }, "updatedAt": { "type": "string", "format": "date-time" } Trade-offs Be aware that if you regenerate your schema using json.js , any custom formats will be lost. To automate the addition of formats, implement a post-processing function that loops through properties and adds the necessary formats. In summary, the AJV library allows for enhanced schema validation by adding formats like date-time and email . For automation, custom code is required to maintain these formats after schema generation.