{"_id":"core-zod-schema-validator","_rev":"2-ef64f3e168e772054884ed3cfc63dcda","name":"core-zod-schema-validator","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"core-zod-schema-validator","version":"1.0.0","keywords":["plugin","zod","schema","validator","json"],"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","_id":"core-zod-schema-validator@1.0.0","maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"homepage":"https://github.com/sclavijosuero/zod-ajv-schema-validator#readme","bugs":{"url":"https://github.com/sclavijosuero/zod-ajv-schema-validator/issues"},"dist":{"shasum":"d4d48060528a7f00438dd6048c8ffb6fd8b474bf","tarball":"https://registry.npmjs.org/core-zod-schema-validator/-/core-zod-schema-validator-1.0.0.tgz","fileCount":15,"integrity":"sha512-62Eisq6GD5+DZ2V6oXhOSVxwUGAGWDmBaZhLdQgBqp12H8V9M0oTavWS9IDQPpKED+Wl24k/3zo6vMK2WVN7gA==","signatures":[{"sig":"MEUCIQDA0EBEYJYSgp/EAY5LLWnLBBd5QLmkvIRZ9frybgfnLwIgbZntLTR4Urt4LiupNF+KTPFFrMhZBR8D3sw3k6XFHwA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":94349},"main":"src/index.js","types":"src/index.d.ts","gitHead":"fff9b5b9d8c2a7322595e868acc7fee1e199e5fb","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"},"repository":{"url":"git+https://github.com/sclavijosuero/zod-ajv-schema-validator.git","type":"git"},"_npmVersion":"10.9.2","description":"Lightweight package for API testing to validate API responses against ZOD schemas. It can be used directly in any project.","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.4","lodash":"^4.17.21","@types/node":"^22.13.5"},"_hasShrinkwrap":false,"devDependencies":{"cypress":"^14.3.3","typescript":"^5.7.3"},"_npmOperationalInternal":{"tmp":"tmp/core-zod-schema-validator_1.0.0_1747621928156_0.043359564417123186","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"core-zod-schema-validator","version":"1.0.1","description":"Lightweight package for API testing to validate API responses against ZOD schemas. It can be used directly in any project.","main":"src/index.js","types":"src/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/sclavijosuero/core-zod-schema-validator.git"},"keywords":["plugin","zod","schema","validator","json"],"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","bugs":{"url":"https://github.com/sclavijosuero/core-zod-schema-validator/issues"},"homepage":"https://github.com/sclavijosuero/core-zod-schema-validator#readme","dependencies":{"@types/node":"^22.13.5","lodash":"^4.17.21","zod":"^3.24.4"},"devDependencies":{"cypress":"^14.3.3","typescript":"^5.7.3"},"_id":"core-zod-schema-validator@1.0.1","gitHead":"e4494f8180873a4cc9875c77d39aa6d197f6345c","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-ndpA5YpS62Aydysq4mZxGWWydstPWn3JpwxSRwA6HVJuH45Atj0CgZolX6AI0gelbqIOh1Or3Z22TVK2xtWGFg==","shasum":"8f1507e1ce2cc30873a2a87034d4af88f335e3ca","tarball":"https://registry.npmjs.org/core-zod-schema-validator/-/core-zod-schema-validator-1.0.1.tgz","fileCount":15,"unpackedSize":94405,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCID5OccnGZSe+YbYHcXBELPvEY3knvg4Ye4OFHSZMheEJAiAAlUKB+5UfZ0g7gRsLgZU1tw9GS8tFeu9ihwyTWe7U7w=="}]},"_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/core-zod-schema-validator_1.0.1_1747634233999_0.16781071739541975"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-19T02:32:08.156Z","modified":"2025-05-19T05:57:14.341Z","1.0.0":"2025-05-19T02:32:08.370Z","1.0.1":"2025-05-19T05:57:14.181Z"},"bugs":{"url":"https://github.com/sclavijosuero/core-zod-schema-validator/issues"},"author":{"name":"Sebastian Clavijo Suero"},"license":"MIT","homepage":"https://github.com/sclavijosuero/core-zod-schema-validator#readme","keywords":["plugin","zod","schema","validator","json"],"repository":{"type":"git","url":"git+https://github.com/sclavijosuero/core-zod-schema-validator.git"},"description":"Lightweight package for API testing to validate API responses against ZOD schemas. It can be used directly in any project.","maintainers":[{"name":"sclavijosuero","email":"sclavijosuero@gmail.com"}],"readme":"# core-zod-schema-validator\r\n\r\nPlugin for API testing to validate API responses against ZOD schemas. It can be used directly in any project.\r\n\r\n![Overview](images/overview.png)\r\n\r\n\r\n## Main Features\r\n\r\n- Function **`validateSchemaZod()`** to report Zod validation errors in the response obtained from any network request.\r\n  \r\n- The schema is provided as a Zod object.\r\n\r\n- Provides the full list of errors as delivered by the Zod package, and a user-friendly view of the mismatches between the validated data and the Zod schema, highlighting where each validation error occurred and the exact reason for the mismatch\r\n\r\n- Relies on the **Zod Schema Validator** as its powerful core engine for schema validation.\r\n\r\n\r\n## About ZOD Schemas and Ajv JSON Schema Validator\r\n\r\n### ZOD Schema\r\n\r\nA Zod schema is aTypeScript-first schema declaration and type generator that ensures data conforms to a specific structure and types at runtime. It is used to validate and infer TypeScript types for objects, arrays, and other data constructs.\r\n\r\n### ZOD Schema Validator\r\n\r\nThe Zod Schema Validator plugin is a tool used to define, validate, and ensure data structures conform to predefined schemas according defined Zod Schemas. It helps developers validate data at runtime while seamlessly integrating with TypeScript for type inference, ensuring consistent and error-free data handling across applications.\r\n\r\nFor more information on Zod, visit the [Zod official website](https://zod.dev/).\r\n\r\n&nbsp; \r\n\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm install -D core-zod-schema-validator\r\n```\r\n\r\n\r\n## Compatibility\r\n\r\n- TypeScript 4.5+\r\n- You must enable strict mode in your `tsconfig.json`. This is a best practice for all TypeScript projects.\r\n\r\n\r\n## API Reference\r\n\r\n### `validateSchema(data, schema[, issuesStyles])`\r\n\r\nFunction that validates the given JSON data against the provided Zod schema.\r\n\r\n#### Parameters\r\n\r\n- **`data`** (required)\r\n  - **Type:** `any`\r\n  - **Description:** The data to be validated.\r\n\r\n- **`schema`** (required)\r\n  - **Type:** `object`\r\n  - **Description:** Zod schema to validate against.\r\n    See the [Zod Schema documentation](https://zod.dev/) for more information.\r\n\r\n- **`issuesStyles`**  (optional)\r\n  - **Type:** `object`  \r\n  - **Description:**  An object with the icons used to flag the schema issues. If not provided, it will use the default icons defined in the plugin. Includes the following properties:\r\n    - **`iconPropertyError`**: The icon used to flag type errors in the data.\r\n    - **`iconPropertyMissing`**: The icon used to flag missing properties in the data.\r\n\r\n\r\n#### Returns\r\n\r\nAn object containing the following properties:\r\n\r\n- **`errors`**  \r\n  - **Type:** `array`  \r\n  - **Description:** An array of validation errors as provided by Zof, or `null` if the data is valid against the schema.\r\n\r\n- **`dataMismatches`**  \r\n  - **Type:** `object`  \r\n  - **Description:** The original response data with all schema mismatches directly flagged.\r\n\r\n- **`issuesStyles`**\r\n  - **Type:** `object`  \r\n  - **Description:**  Object `issuesStyles` used to flag schema issues in `dataMismatches` results.\r\n\r\n\r\n#### Throws\r\n- **Error:** If any of the required parameters are missing.\r\n\r\nExample providing a ZOD schema:\r\n\r\n```js\r\n  //...\r\n  const data = response.body\r\n  const { errors, dataMismatches } = validateSchemaZod(data, schema);\r\n  expect(errors).to.be.null; // Assertion to ensure no validation errors\r\n  //...\r\n```\r\n\r\n## Usage Examples\r\n\r\n### Example: Using `validateSchemaZod` Function in Cypress Test Framework\r\n\r\n```js\r\n/// <reference types=\"cypress\" />\r\n\r\nimport { z } from \"zod\";\r\nimport { validateSchemaZod } from 'core-zod-schema-validator'\r\n\r\n// Definition for the \"Category\" object\r\nconst categorySchema = z.object({\r\n  id: z.number().int(),\r\n  name: z.number().optional(), // Optional as per schema\r\n  color: z.string()\r\n});\r\n\r\n// Definition for the \"Tag\" object\r\nconst tagSchema = z.object({\r\n  id: z.number().int(),\r\n  name: z.string(),\r\n  type: z.string()\r\n});\r\n\r\n// Definition for the \"Pet\" object\r\nconst petSchema = z.object({\r\n  id: z.string().optional(), // Optional as per schema\r\n  age: z.number().int(),\r\n  category: categorySchema.optional(), // Optional as per schema\r\n  name: z.number(), // Defined as integer in the schema\r\n  photoUrls: z.array(z.string()).min(2), // Minimum of 2 items\r\n  tags: z.array(tagSchema).min(1).optional(), // Optional as per schema, min 1 item.\r\n  status: z.enum([\"available\", \"sold\"]) // Specified as enum\r\n});\r\n\r\nconst schema = z.array(petSchema);\r\n\r\n\r\ndescribe('API Schema Validation Function', () => {\r\n\r\n  const customIssuesStyles = { iconPropertyError: '⛔', iconPropertyMissing: '❓' }\r\n\r\n  it('Test Zod Schema - Sample 2', () => {\r\n      const findByStatusReq = {\r\n          url: 'https://petstore.swagger.io/v2/pet/findByStatus?status=pending',\r\n          headers: { 'Content-Type': 'application/json' }\r\n      }\r\n\r\n      cy.request(findByStatusReq).then((response) => {\r\n          const result = validateSchemaZod(response.body, schema, customIssuesStyles)\r\n          expect(result.errors).to.be.null\r\n      });\r\n  })\r\n});\r\n```\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## Changelog\r\n\r\n### [1.0.0]\r\n- Initial release.\r\n\r\n### [1.0.1]\r\n- Update wrong URLs in package.json.\r\n\r\n\r\n## Support\r\n\r\nIf you'd like to support my work, consider buying me a coffee or contributing to a training session, so I can keep learning and sharing cool stuff with all of you. Thank you for your support!\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","readmeFilename":"README.md"}