Registry / testing / cypress-ajv-schema-validator

cypress-ajv-schema-validator

JSON →
library2.0.2jsnpmunverified

Cypress plugin (v2.0.2, last release 2023) for API schema validation against JSON schemas, Swagger, or OpenAPI documents. Uses Ajv as the validation engine. Now legacy: replaced by cypress-schema-validator (backward compatible, adds Zod support). Key features: chainable cy.validateSchema() command, supports environment variable disableSchemaValidation, integration with @bahmutov/cy-api and cypress-plugin-api. No recent updates; users should migrate to successor.

npm install cypress-ajv-schema-validator
INSTALL
IMPORT
SIG · CYPRESS-AJV-SCHEMA
C
cypress-ajv-schema-validator
testingjavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import 'cypress-ajv-schema-validator'
import * as validator from 'cypress-ajv-schema-validator'
Plugin must be imported in cypress/support/e2e.js or commands.js to register cy.validateSchema(). Do not import a named export; the side-effect import adds the command.
validateSchema
cy.get(...).validateSchema(schema)
cy.validateSchema(schema).get(...)
validateSchema is a command chained after cy.request() or cy.api(), not a standalone function. It returns the original response.
Cypress.env
Cypress.env('disableSchemaValidation', true)
require('cypress-ajv-schema-validator').disableSchemaValidation = true
Control validation via environment variable, not direct import.

Shows how to import the plugin, define a JSON schema, use cy.validateSchema() chained after cy.request(), and optionally disable validation via Cypress environment variable.

import 'cypress-ajv-schema-validator'; // In Cypress test it('validates API response against schema', () => { const schema = { type: 'object', required: ['id', 'name'], properties: { id: { type: 'integer' }, name: { type: 'string' } } }; cy.request('GET', '/api/user/1') .validateSchema(schema) .its('status') .should('eq', 200); }); // Disable validation via environment variable (e.g., in cypress.config.js) // env: { disableSchemaValidation: true }
Debug
Known issues
deprecatedThis package is deprecated and replaced by cypress-schema-validator. New features and support only for the successor.
fix
Migrate to cypress-schema-validator: npm uninstall cypress-ajv-schema-validator && npm install cypress-schema-validator (backward compatible)
affects: >=2.0.0
breakingVersion 2.0.0 switched the underlying validation engine from custom to core-ajv-schema-validator. Existing schema may behave differently due to Ajv defaults.
fix
Review your schemas for strict mode compatibility (e.g., remove additionalProperties if not allowed). See Ajv breaking changes.
affects: >=2.0.0 <3.0.0
gotchaThe plugin must be imported as a side-effect before any tests that use cy.validateSchema(). Importing it inside a test or after commands will not register the command.
fix
Add import 'cypress-ajv-schema-validator' to cypress/support/e2e.js or the equivalent support file.
affects: >=1.0.0
gotchadisableSchemaValidation environment variable only works when set before tests run (e.g., in cypress.config.js). Changing it at runtime via Cypress.env() may not take effect.
fix
Set disableSchemaValidation in your Cypress config or via command line: cypress run --env disableSchemaValidation=true
affects: >=1.2.0
Errors
Common errors & fixes
cy.validateSchema is not a function
Plugin not imported as side-effect. The import 'cypress-ajv-schema-validator' is required in the support file.
fix
import 'cypress-ajv-schema-validator' in cypress/support/e2e.js
Cannot find module 'ajv'
Missing peer dependency ajv. The plugin requires ajv to be installed.
fix
npm install ajv --save-dev
options should NOT have additional properties
Schema uses additionalProperties: false and response includes extra fields not defined in properties.
fix
Either remove additionalProperties from schema or add the extra fields to the properties.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
cypressrequiredThis is a Cypress plugin; requires Cypress as peer dependency.
ajvrequiredCore validation engine used by core-ajv-schema-validator.
Agent activity
6 hits · last 30 days
node
6
Resources
cypress-ajv-schema-validator — npm install cypress-ajv-schema-validator · libregistry