{"_id":"playwright-ajv-schema-validator","_rev":"3-f1d809902a4598aa7abcc8dc8742ce50","name":"playwright-ajv-schema-validator","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"playwright-ajv-schema-validator","version":"1.0.0","keywords":["plugin","playwright","ajv","schema","validator","json"],"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","_id":"playwright-ajv-schema-validator@1.0.0","maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"homepage":"https://github.com/sclavijosuero/playwright-ajv-schema-validator#readme","bugs":{"url":"https://github.com/sclavijosuero/playwright-ajv-schema-validator/issues"},"dist":{"shasum":"abbb8c5a8cab0cdae74a6cb891c13a8760286e4c","tarball":"https://registry.npmjs.org/playwright-ajv-schema-validator/-/playwright-ajv-schema-validator-1.0.0.tgz","fileCount":12,"integrity":"sha512-YR7wLfNgRmhrDvruegkJWiAOkXWctXXRL2kNDYnuh4Ix/R2CzvD0H4/B4zn5hIb7iNDNNdXv0HY7Yz8EzpLckA==","signatures":[{"sig":"MEUCIQCEvDTzTBWCWxcpQgBAvCyC01VyG2WysWLK5jRIiYl3UgIgTN+H0TnhtGtL2ZRunefvQymQMA4hR4x7jSEHNYsoRPE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":60588},"main":"dist/src/index.js","types":"dist/src/types.d.ts","gitHead":"cfbd5a36addd5daed61119e9869756435e66c18a","scripts":{"build":"tsc","release":"npm cache clean --force && npm version patch && npm publish --force","prebuild":"rm -rf dist","prerelease":"npm run build"},"_npmUser":{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"},"repository":{"url":"git+https://github.com/sclavijosuero/playwright-ajv-schema-validator.git","type":"git"},"_npmVersion":"10.9.2","description":"A Playwright plugin for API schema validation against plain JSON schemas, Swagger schema documents. Built on the robust core-ajv-schema-validator plugin and powered by the Ajv JSON Schema Validator, it delivers results in a clear, user-friendly format, si","directories":{},"_nodeVersion":"22.13.1","dependencies":{"highlight.js":"^11.11.1"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.8.2","@types/node":"^22.13.17","pw-api-plugin":"^2.0.1","@playwright/test":"^1.51.1","core-ajv-schema-validator":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/playwright-ajv-schema-validator_1.0.0_1743997651801_0.032449168307032705","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"playwright-ajv-schema-validator","version":"1.0.1","keywords":["plugin","playwright","ajv","schema","validator","json"],"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","_id":"playwright-ajv-schema-validator@1.0.1","maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"homepage":"https://github.com/sclavijosuero/playwright-ajv-schema-validator#readme","bugs":{"url":"https://github.com/sclavijosuero/playwright-ajv-schema-validator/issues"},"dist":{"shasum":"7d0582ef52dcd72d4fd46e889fa42abb7e35ee0b","tarball":"https://registry.npmjs.org/playwright-ajv-schema-validator/-/playwright-ajv-schema-validator-1.0.1.tgz","fileCount":12,"integrity":"sha512-uxHIj8/1V157/1bTfWHPzN83T3cYk+JBGlJ+yzy/MQjmvOXoPlrSfssZ6gYf8SUjDlmGrvtKRe6zYkYwxs4myw==","signatures":[{"sig":"MEUCIQCKa863LgmCzLhK4NNfvF0X6xaHHu0biLmQCyzn26meFAIgV0jB7YS7Be7pm2/lEpjlIUU4ZNsPN9DPEDiTyYDlQeo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59772},"main":"dist/src/index.js","types":"dist/src/types.d.ts","gitHead":"c0c4d99325c59176844f8fd9129a5be6e055a52d","scripts":{"build":"tsc","release":"npm cache clean --force && npm version patch && npm publish --force","prebuild":"rm -rf dist","prerelease":"npm run build"},"_npmUser":{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"},"repository":{"url":"git+https://github.com/sclavijosuero/playwright-ajv-schema-validator.git","type":"git"},"_npmVersion":"10.9.2","description":"A Playwright plugin for API schema validation against plain JSON schemas, Swagger schema documents. Built on the robust core-ajv-schema-validator plugin and powered by the Ajv JSON Schema Validator, it delivers results in a clear, user-friendly format, si","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@types/node":"^22.13.17","highlight.js":"^11.11.1","core-ajv-schema-validator":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.8.2","pw-api-plugin":"^2.0.1","@playwright/test":"^1.51.1"},"_npmOperationalInternal":{"tmp":"tmp/playwright-ajv-schema-validator_1.0.1_1744060567966_0.1436574394742416","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"playwright-ajv-schema-validator","version":"1.0.2","description":"A Playwright plugin for API schema validation against plain JSON schemas, Swagger schema documents. Built on the robust core-ajv-schema-validator plugin and powered by the Ajv JSON Schema Validator, it delivers results in a clear, user-friendly format, si","main":"dist/src/index.js","types":"dist/src/types.d.ts","scripts":{"prebuild":"rm -rf dist","build":"tsc","prerelease":"npm run build","release":"npm cache clean --force && npm version patch && npm publish --force"},"repository":{"type":"git","url":"git+https://github.com/sclavijosuero/playwright-ajv-schema-validator.git"},"keywords":["plugin","playwright","ajv","schema","validator","json"],"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","bugs":{"url":"https://github.com/sclavijosuero/playwright-ajv-schema-validator/issues"},"homepage":"https://github.com/sclavijosuero/playwright-ajv-schema-validator#readme","devDependencies":{"@playwright/test":"^1.51.1","pw-api-plugin":"^2.0.2","typescript":"^5.8.2"},"dependencies":{"@types/node":"^22.13.17","core-ajv-schema-validator":"^1.0.0","highlight.js":"^11.11.1"},"_id":"playwright-ajv-schema-validator@1.0.2","gitHead":"9fbeb9402920822318877474f8b70af8f2fac83a","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-TynE6jtWWw4aj5DSZjFNwwqP4wsTit1OXgoiM3WrGIsyK40bYgBejBxc3EDA2TngeduuDmEPigArY28AxqQ3oA==","shasum":"25111158ed8a0c5c6958e0ed3d6440930ade0290","tarball":"https://registry.npmjs.org/playwright-ajv-schema-validator/-/playwright-ajv-schema-validator-1.0.2.tgz","fileCount":13,"unpackedSize":61923,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHBJSMMCV08xu+Nb6ChnXwlIeW4rRn+DILhnVX1vnXp0AiBdSKLep35nx7M1AD3B3Lepwe9kMRCPQCh3rZl5mVBHVw=="}]},"_npmUser":{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"},"directories":{},"maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/playwright-ajv-schema-validator_1.0.2_1744582915876_0.28496924935109913"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-07T03:47:31.800Z","modified":"2025-04-13T22:21:56.240Z","1.0.0":"2025-04-07T03:47:31.997Z","1.0.1":"2025-04-07T21:16:08.161Z","1.0.2":"2025-04-13T22:21:56.088Z"},"bugs":{"url":"https://github.com/sclavijosuero/playwright-ajv-schema-validator/issues"},"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","homepage":"https://github.com/sclavijosuero/playwright-ajv-schema-validator#readme","keywords":["plugin","playwright","ajv","schema","validator","json"],"repository":{"type":"git","url":"git+https://github.com/sclavijosuero/playwright-ajv-schema-validator.git"},"description":"A Playwright plugin for API schema validation against plain JSON schemas, Swagger schema documents. Built on the robust core-ajv-schema-validator plugin and powered by the Ajv JSON Schema Validator, it delivers results in a clear, user-friendly format, si","maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"readme":"# playwright-ajv-schema-validator\r\n\r\nA Playwright plugin for API schema validation against plain JSON schemas, Swagger schema documents. Built on the robust core-ajv-schema-validator plugin and powered by the Ajv JSON Schema Validator, it delivers results in a clear, user-friendly format, simplifying the process of identifying and addressing schema issues.\r\n\r\n![Overview](videos/overview.gif) \r\n\r\n\r\n## MAIN FEATURES\r\n\r\n- Function **`validateSchema()`** to report JSON Schema errors in the response obtained from network requests.\r\n\r\n- Uses the **core-ajv-schema-validator** plugin, which leverages the **Ajv JSON Schema Validator** as its engine .\r\n  \r\n- Supports schemas provided as **plain JSON schema**, **OpenAPI 3 schema document** and **Swagger 2 schema document**.\r\n  \r\n- Provides a user-friendly view of schema errors and mismatches between the validated data and the JSON schema, clearly highlighting where each validation error occurred and the exact reason for the mismatch:\r\n  -  Number of schema errors.\r\n  -  Full list of schema errors as provided by Ajv.\r\n  -  A nested tree view of the validated data, clearly indicating the errors and where they occurred in an easy-to-understand format.\r\n\r\n- Environment variables:\r\n  -  `DISABLE_SCHEMA_VALIDATION` to disable schema validation in your tests even when function `validateSchema()` is present.\r\n  -  `LOG_API_UI` to enable the display of API call details in **Playwright UI** and **Trace Viewer** .\r\n  -  `LOG_API_REPORT` to enable the display of API call details in **HTML Report** .\r\n\r\n- ⭐⭐⭐⭐⭐ Integrates seamlessly with the **`pw-api-plugin`** but also functions independently with **standard Playwright API requests**.\r\n\r\n\r\n## TABLE OF CONTENT\r\n\r\n- [playwright-ajv-schema-validator](#playwright-ajv-schema-validator)\r\n  - [MAIN FEATURES](#main-features)\r\n  - [TABLE OF CONTENT](#table-of-content)\r\n  - [ABOUT JSON SCHEMAS AND AJV JSON SCHEMA VALIDATOR](#about-json-schemas-and-ajv-json-schema-validator)\r\n    - [JSON Schema](#json-schema)\r\n    - [OpenAPI 3.0.1 and Swagger 2.0 Schema Documents](#openapi-301-and-swagger-20-schema-documents)\r\n    - [Ajv JSON Schema Validator](#ajv-json-schema-validator)\r\n  - [INSTALLATION](#installation)\r\n  - [COMPATIBILITY](#compatibility)\r\n  - [CONFIGURATION](#configuration)\r\n  - [API Reference](#api-reference)\r\n    - [`validateSchema(fixtures, data, schema[, path[, issuesStyles]])`](#validateschemafixtures-data-schema-path-issuesstyles)\r\n      - [Parameters](#parameters)\r\n      - [Returns](#returns)\r\n  - [USAGE](#usage)\r\n    - [Environment variables](#environment-variables)\r\n      - [Setting Environment Variables in the Terminal](#setting-environment-variables-in-the-terminal)\r\n    - [Using **`pw-api-plugin`**](#using-pw-api-plugin)\r\n      - [**`pwApi`** Class](#pwapi-class)\r\n      - [**`axiosApi`** Class](#axiosapi-class)\r\n    - [Using Playwright Standard Requests](#using-playwright-standard-requests)\r\n  - [PRESENTATION OF RESULTS](#presentation-of-results)\r\n    - [Schema Validation Pass](#schema-validation-pass)\r\n    - [Schema Validation Fail Using **`pw-api-plugin`**](#schema-validation-fail-using-pw-api-plugin)\r\n    - [Schema Validation Fail Using Playwright Standard API **`request`**](#schema-validation-fail-using-playwright-standard-api-request)\r\n    - [Schema Validation Fails with Custom Styles Used in your Tests](#schema-validation-fails-with-custom-styles-used-in-your-tests)\r\n    - [Disable Schema Validation](#disable-schema-validation)\r\n    - [Attach Schema Validation Failure Details in HTML Report](#attach-schema-validation-failure-details-in-html-report)\r\n    - [Schema Validation Details in Trace Viewer](#schema-validation-details-in-trace-viewer)\r\n  - [LICENSE](#license)\r\n  - [CONTRIBUTING](#contributing)\r\n  - [CHANGELOG](#changelog)\r\n    - [\\[1.0.0\\]](#100)\r\n\r\n\r\n## ABOUT JSON SCHEMAS AND AJV JSON SCHEMA VALIDATOR\r\n\r\n### JSON Schema\r\n\r\nJSON Schema is a hierarchical, declarative language that describes and validates JSON data.\r\n\r\n### OpenAPI 3.0.1 and Swagger 2.0 Schema Documents\r\n\r\nThe OpenAPI Specification (formerly Swagger Specification) are schema documents to describe your entire API (in JSON format or XML format). So a schema document will contain multiple schemas, one for each supported combination of **_Endpoint - Method - Expected Response Status_** (also called _path_) by that API.\r\n\r\n### Ajv JSON Schema Validator\r\n\r\nAJV, or Another JSON Schema Validator, is a JavaScript library that validates data objects against a JSON Schema structure.\r\n\r\nIt was chosen as the core engine of the `playwright-ajv-schema-validator` plugin because of its versatility, speed, capabilities, continuous maintenance, and excellent documentation. For more information on Ajv, visit the [Ajv official website](https://ajv.js.org/).\r\n\r\nAjv supports validation of the following schema formats: **JSON Schema**, **OpenAPI 3** specification, and **Swagger 2** specification. However, Ajv needs to be provided with the specific schema to be validated for an endpoint, method, and expected response; it cannot process a full OpenAPI 3.0.1 or Swagger 2.0 schema document by itself.\r\n\r\nThe `playwright-ajv-schema-validator` plugin simplifies this by obtaining the correct schema definition for the endpoint you want to test. You just need to provide the full schema document (OpenAPI or Swagger) and the path to the schema definition of the service you want to validate for your API (_Endpoint - Method - Expected Response Status_).\r\n\r\n> **Note:** The Ajv instance used in this plugin (`playwright-ajv-schema-validator`) is configured with the options `{ allErrors: true, strict: false }` to display all validation errors and disable strict mode.\r\n\r\n&nbsp; \r\n\r\n## INSTALLATION\r\n\r\n```sh\r\nnpm install -D playwright-ajv-schema-validator\r\n```\r\n\r\n\r\n## COMPATIBILITY\r\n\r\n- Ajv 8.16.0 or higher\r\n- ajv-formats 3.0.1 or higher\r\n\r\n\r\n## CONFIGURATION\r\n\r\n- Add the following lineto your test file:\r\n\r\n  ```js\r\n  import { validateSchema } from 'playwright-ajv-schema-validator';\r\n  ```\r\n\r\n\r\n## API Reference\r\n\r\n### `validateSchema(fixtures, data, schema[, path[, issuesStyles]])`\r\n\r\nValidates the response body against a given schema. Note that the function already asserts the validity of the schema, so there is no need to add additional assertions on the results.\r\n\r\n#### Parameters\r\n\r\n- **`fixtures`** (required)\r\n  - **Type**: `object`\r\n  - **Description**: An object containing test fixtures, such as the page object: `{ page }`.\r\n\r\n- **`data`** (required)\r\n  - **Type**: `object`\r\n  - **Description**: The JSON data to validate against the schema.\r\n\r\n- **`schema`** (required)\r\n  - **Type**: `any`\r\n  - **Description**: The schema to validate against. Supported formats include:\r\n    - JSON Schema\r\n    - OpenAPI 3 specification document\r\n    - Swagger 2 specification document\r\n    See the [Ajv JSON Schema documentation](https://ajv.js.org/json-schema.html) for more information.\r\n\r\n- **`path`** (optional)\r\n  - **Type**: `object`\r\n  - **Description**: The path object to the schema definition in a Swagger or OpenAPI document. Not required if the schema is a plain JSON schema.\r\n    - **`path.endpoint`** (required if `path` is provided)\r\n      - **Type**: `string`\r\n      - **Description**: The endpoint path in the Swagger or OpenAPI document.\r\n    - **`path.method`** (optional)\r\n      - **Type**: `string`\r\n      - **Default**: `\"GET\"`\r\n      - **Description**: The HTTP method (e.g., `GET`, `POST`) of the API request.\r\n    - **`path.status`** (optional)\r\n      - **Type**: `number`\r\n      - **Default**: `200`\r\n      - **Description**: The expected status code of the API response.\r\n\r\n- **`issuesStyles`** (optional)\r\n  - **Type**: `object`\r\n  - **Description**: An optional object to override the default icons and HEX colors used to flag schema issues.\r\n    - **`issuesStyles.iconPropertyError`** (optional)\r\n      - **Type**: `string`\r\n      - **Description**: Custom icon to flag property errors.\r\n    - **`issuesStyles.colorPropertyError`** (optional)\r\n      - **Type**: `string`\r\n      - **Description**: Custom HEX color to flag property errors.\r\n    - **`issuesStyles.iconPropertyMissing`** (optional)\r\n      - **Type**: `string`\r\n      - **Description**: Custom icon to indicate missing properties.\r\n    - **`issuesStyles.colorPropertyMissing`** (optional)\r\n      - **Type**: `string`\r\n      - **Description**: Custom HEX color to indicate missing properties.\r\n\r\n#### Returns\r\n\r\n- **Type**: `Promise<object>`\r\n- **Description**: A Promise resolving to an object containing the validation results:\r\n  - **`errors`**  \r\n    - **Type:** `array`  \r\n    - **Description:** An array of validation errors as provided by Ajv, or `null` if the data is valid against the schema.\r\n  - **`dataMismatches`**  \r\n    - **Type:** `object`  \r\n    - **Description:** The original response data with all schema mismatches directly flagged.\r\n\r\n\r\nExample providing an OpenAPI 3.0.1 or Swagger 2.0 schema documents, a path to the schema definition, and issuesStyles:\r\n\r\n```js\r\nconst issuesStyles = {\r\n    iconPropertyError: '☣️',\r\n    colorPropertyError: '#8B8000',\r\n    iconPropertyMissing: '⛔',\r\n    colorPropertyMissing: '#FF0000'\r\n}\r\nconst data = response.body\r\nconst validationResult = await validateSchema({ page }, data,\r\n    schemaDoc, { endpoint: '/api/resource', method: 'POST', status: 201},\r\n    issuesStyles\r\n);\r\n\r\nconsole.log(validationResult.errors, validationResult.dataMismatches);\r\n```\r\n\r\n> ⭐⭐⭐⭐⭐ **If you are using the Playwright `pw-api-plugin` in your API tests to display API call details, the `playwright-ajv-schema-validation` plugin will automatically detect and display schema errors directly alongside the details.**\r\n\r\n\r\n## USAGE\r\n\r\n### Environment variables\r\n\r\n- To **disable schema validation** completely even when the `validateSchema()` function is present in the test, set the environment variable `DISABLE_SCHEMA_VALIDATION` to `true`. By default, schema validation is enabled.\r\n\r\n- When the environment variable **`LOG_API_UI`** is set to **`\"false\"`**, the results of the schema validation are NOT displayed in the **Playwright UI** and **Trace Viewer** in a user-friendly format. By default, these results are shown.\r\n\r\n>This environment variable `LOG_API_UI` is also shared with the Playwright `pw-api-plugin`.\r\n\r\n- If the environment variable **`LOG_API_REPORT`** is set to **`\"true\"`**, the dresults of the schema validation are included as attachments in the **HTML Report**. By default, these results are not attached.\r\n\r\n>This environment variable `LOG_API_REPORT` is also shared with the Playwright `pw-api-plugin`.\r\n\r\n#### Setting Environment Variables in the Terminal\r\n\r\nIn PowerShell (Note: by default LOG_API_UI is already `\"true\"`):\r\n\r\n```shell\r\n$env:DISABLE_SCHEMA_VALIDATION=\"true\"\r\n$env:LOG_API_UI=\"true\"\r\n$env:LOG_API_REPORT=\"true\"\r\nnpx playwright test --ui\r\n```\r\n\r\nIn Bash:\r\n\r\n```shell\r\nDISABLE_SCHEMA_VALIDATION=\"true\" LOG_API_UI=\"true\" LOG_API_REPORT=\"true\" npx playwright test --ui\r\n```\r\n\r\nIn Batch\r\n\r\n```shell\r\nset DISABLE_SCHEMA_VALIDATION=\"true\"\r\nset LOG_API_UI=\"true\"\r\nset LOG_API_REPORT=\"true\"\r\nnpx playwright test --ui\r\n```\r\n\r\n> For more information, read the official documentation on [Passing Environment Variables](https://playwright.dev/docs/test-parameterize#passing-environment-variables \"Passing Environment Variables\").\r\n\r\n\r\n### Using **`pw-api-plugin`**\r\n\r\n#### **`pwApi`** Class\r\n\r\n```js\r\nimport { expect } from '@playwright/test';\r\nimport { pwApi, test } from 'pw-api-plugin';\r\n\r\nimport { validateSchema } from 'playwright-ajv-schema-validator';\r\n\r\n// Swagger 2.0 Schema Document for the API under test\r\nimport petStoreSwagger from '../tests-data/schemas/petstore-swagger.json';\r\n\r\ntest.describe('Petstore API', () => {\r\n\r\n    const baseUrl = 'https://petstore.swagger.io/v2';\r\n\r\n    test('Should validate schema of POST \"/store/order\" endpoint ', async ({ request, page }) => {\r\n\r\n        // EXAMPLE POST 1 (PASS)\r\n        const requestBody1 = {\r\n            \"id\": 0,\r\n            \"petId\": 0,\r\n            \"quantity\": 0,\r\n            \"shipDate\": \"2024-01-01T00:57:29.231Z\",\r\n            \"status\": \"placed\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost1 = await pwApi.post({ request, page }, `${baseUrl}/store/order`,\r\n            {\r\n                data: requestBody1,\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost1.status()).toBe(200)\r\n        const responseBodyPost1 = await responsePost1.json()\r\n\r\n        await validateSchema({ page }, responseBodyPost1, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n\r\n        // EXAMPLE POST 2 (FAIL: \"status\" not a valid value & \"shipDate\" is missing)\r\n        const requestBody2 = {\r\n            \"id\": 0,\r\n            \"petId\": 1,\r\n            \"quantity\": 11,\r\n            \"status\": \"unknown\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost2 = await pwApi.post({ request, page }, `${baseUrl}/store/order`,\r\n            {\r\n                data: requestBody2,\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost2.status()).toBe(200)\r\n        const responseBodyPost2 = await responsePost2.json()\r\n\r\n        await validateSchema({ page }, responseBodyPost2, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n    })\r\n})\r\n```\r\n\r\n#### **`axiosApi`** Class\r\n\r\n```js\r\nimport { expect } from '@playwright/test';\r\nimport { axiosApi, test } from 'pw-api-plugin';\r\n\r\nimport { validateSchema } from 'playwright-ajv-schema-validator';\r\n\r\n// Swagger 2.0 Schema Document for the API under test\r\nimport petStoreSwagger from '../tests-data/schemas/petstore-swagger.json';\r\n\r\ntest.describe('Petstore API', () => {\r\n\r\n    const baseUrl = 'https://petstore.swagger.io/v2';\r\n\r\n    test('Should validate schema of POST \"/store/order\" endpoint ', async ({ request, page }) => {\r\n\r\n        // EXAMPLE POST 1 (PASS)\r\n        const requestBody1 = {\r\n            \"id\": 0,\r\n            \"petId\": 0,\r\n            \"quantity\": 0,\r\n            \"shipDate\": \"2024-01-01T00:57:29.231Z\",\r\n            \"status\": \"placed\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost1 = await axiosApi.post({ page }, `${baseUrl}/store/order`,\r\n            requestBody1,\r\n            {\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost1.status).toBe(200)\r\n        const responseBodyPost1 = await responsePost1.data\r\n\r\n        await validateSchema({ page }, responseBodyPost1, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n\r\n        // EXAMPLE POST 2 (FAIL: \"status\" not a valid value & \"shipDate\" is missing)\r\n        const requestBody2 = {\r\n            \"id\": 0,\r\n            \"petId\": 1,\r\n            \"quantity\": 11,\r\n            \"status\": \"unknown\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost2 = await axiosApi.post({ page }, `${baseUrl}/store/order`,\r\n            requestBody2,\r\n            {\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost2.status).toBe(200)\r\n        const responseBodyPost2 = await responsePost2.data\r\n\r\n        await validateSchema({ page }, responseBodyPost2, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n    })\r\n})\r\n```\r\n\r\n### Using Playwright Standard Requests\r\n\r\n```js\r\nimport { expect } from '@playwright/test';\r\nimport { pwApi, test } from 'pw-api-plugin';\r\n\r\nimport { validateSchema } from 'playwright-ajv-schema-validator';\r\n\r\n// Swagger 2.0 Schema Document for the API under test\r\nimport petStoreSwagger from '../tests-data/schemas/petstore-swagger.json';\r\n\r\ntest.describe('Petstore API', () => {\r\n\r\n    const baseUrl = 'https://petstore.swagger.io/v2';\r\n\r\n    test('Should validate schema of POST \"/store/order\" endpoint ', async ({ request, page }) => {\r\n\r\n        // EXAMPLE POST 1 (PASS)\r\n        const requestBody1 = {\r\n            \"id\": 0,\r\n            \"petId\": 0,\r\n            \"quantity\": 0,\r\n            \"shipDate\": \"2024-01-01T00:57:29.231Z\",\r\n            \"status\": \"placed\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost1 = await request.post(`${baseUrl}/store/order`,\r\n            {\r\n                data: requestBody1,\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost1.status()).toBe(200)\r\n        const responseBodyPost1 = await responsePost1.json()\r\n\r\n        await validateSchema({ page }, responseBodyPost1, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n\r\n        // EXAMPLE POST 2 (FAIL: \"status\" not a valid value & \"shipDate\" is missing)\r\n        const requestBody2 = {\r\n            \"id\": 0,\r\n            \"petId\": 1,\r\n            \"quantity\": 11,\r\n            \"status\": \"unknown\",\r\n            \"complete\": false\r\n        }\r\n\r\n        const responsePost2 = await request.post(`${baseUrl}/store/order`,\r\n            {\r\n                data: requestBody2,\r\n                headers: {\r\n                    'Content-type': 'application/json; charset=UTF-8',\r\n                },\r\n            }\r\n        );\r\n        expect(responsePost2.status()).toBe(200)\r\n        const responseBodyPost2 = await responsePost2.json()\r\n\r\n        await validateSchema({ page }, responseBodyPost2, petStoreSwagger, { endpoint: '/store/order', method: 'post', status: 200 });\r\n\r\n    })\r\n})\r\n```\r\n\r\n\r\n## PRESENTATION OF RESULTS\r\n\r\n### Schema Validation Pass\r\n\r\n![Schema Validation Pass](images/validation-pass.png)\r\n\r\n### Schema Validation Fail Using **`pw-api-plugin`**\r\n\r\n![Schema Validation Fail Using pw-api-plugin](images/fail-pw-api-plugin.png)\r\n\r\n\r\n### Schema Validation Fail Using Playwright Standard API **`request`**\r\n\r\n![Schema Validation Fail Using Playwright Standard API request](images/fail-pw-standard.png)\r\n\r\n\r\n### Schema Validation Fails with Custom Styles Used in your Tests\r\n\r\n![Schema Validation Fails with Custom Styles Used in your Tests](images/fail-custom.png)\r\n\r\n\r\n### Disable Schema Validation\r\n\r\nSetting environment variable `DISABLE_SCHEMA_VALIDATION` to `\"true\"`.\r\n\r\n![Disable Schema Validation](images/disable-validation.png)\r\n\r\n\r\n### Attach Schema Validation Failure Details in HTML Report\r\n\r\nSetting environment variable `LOG_API_REPORT` to `\"true\"`.\r\n\r\n![Attach Schema Validation Details in HTML Report - Schema Validation Test Results](images/html-report-pw-api-plugin-1.png)\r\n\r\n\r\n![Attach Schema Validation Details in HTML Report - Schema Validation Failure Details](images/html-report-pw-api-plugin-2.png)\r\n\r\n\r\n### Schema Validation Details in Trace Viewer\r\n\r\nExecuting command `npx playwright test --trace on`.\r\n\r\n![Schema Validation Details in Trace Viewer - Using pw-api-plugin](images/trace-viewer-1.png)\r\n\r\n_Schema Validation Details in Trace Viewer - Using pw-api-plugin._\r\n\r\n\r\n![Schema Validation Details in Trace Viewer - Using Playwright Standard API request](images/trace-viewer-2.png)\r\n_Schema Validation Details in Trace Viewer - Using Playwright Standard API request._\r\n\r\n\r\n## LICENSE\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\r\n\r\n\r\n## CONTRIBUTING\r\n\r\nFirst off, thanks for taking the time to contribute!\r\n\r\nTo contribute, please follow the best practices promoted by GitHub on the [Contributing to a project](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project \"Contributing to a project\") page.\r\n\r\nAnd if you like the project but just don't have the time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:\r\n- Star the project\r\n- Promote it on social media\r\n- Refer this project in your project's readme\r\n- Mention the project at local meetups and tell your friends/colleagues\r\n- Buying me a coffee or contributing to a training session, so I can keep learning and sharing cool stuff with all of you.\r\n\r\n<a href=\"https://www.buymeacoffee.com/sclavijosuero\" target=\"_blank\"><img src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 40px !important;width: 150px !important;\" ></a>\r\n\r\nThank you for your support!\r\n\r\n\r\n## CHANGELOG\r\n\r\n### [1.0.2]\r\n- Use of pw-api-plugin v2.0.2.\r\n- Fix hover information for public functions.\r\n\r\n### [1.0.1]\r\n- Fix @types/node dependencies and use target \"es2017\".\r\n\r\n### [1.0.0]\r\n- Initial release.\r\n\r\n","readmeFilename":"README.md"}