Schema Validator | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Schema Validation
Instructor: Artem Bondar
Lesson Summary
This lesson focuses on implementing schema validation using the AGV library in a TypeScript project. Below are the key steps covered in the video: Steps to Implement Schema Validation Install AGV: Open the AGV schema validator documentation. Run the command in the terminal: npm install AGV --save-dev Verify installation in package.json . Import and Create AGV Instance: Import AGV in your TypeScript file: import AGV from 'AGV'; Create a new instance of AGV: const validator = new AGV(); Compile Schema: Use AGV.compile to compile the schema: const validate = validator.compile(schema, { allErrors: true }); This allows validation to continue after encountering the first error. Validate JSON Object: Pass the JSON object (response body) to the validation function: const valid = validate(responseBody); If validation fails, throw a new error with detailed messages. Error Handling Implement meaningful error messages by throwing an error that includes: The message: schema validation failed Details of validation errors using JSON.stringify(validate.errors) The actual response body for analysis. In summary, this lesson demonstrates how to effectively use AGV for schema validation, handle errors, and improve the reporting of validation results.