{"id":24856606,"url":"https://github.com/sirraminyavari/ajv-ts-schema","last_synced_at":"2025-06-24T20:09:46.804Z","repository":{"id":263730380,"uuid":"891275101","full_name":"sirraminyavari/ajv-ts-schema","owner":"sirraminyavari","description":"Simplify AJV Schema Validation with TypeScript","archived":false,"fork":false,"pushed_at":"2025-02-13T01:04:29.000Z","size":247,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-08T20:59:16.210Z","etag":null,"topics":["ajv","json-schema","json-schema-validation","json-schema-validator","schema-validator","ts-schema-validation","typescript-ajv","typescript-schema-validation","validation","validator"],"latest_commit_sha":null,"homepage":"https://www.raminy.dev/article/18712bd0-e06d-80b2-8e76-f86720b48d01/Simplifying%20AJV%20Schema%20Validation%20with%20TypeScript","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sirraminyavari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-20T03:22:42.000Z","updated_at":"2025-02-13T01:04:32.000Z","dependencies_parsed_at":"2024-11-20T06:26:24.676Z","dependency_job_id":"bf0fd150-bc9a-4261-99aa-710e5fc8bdd3","html_url":"https://github.com/sirraminyavari/ajv-ts-schema","commit_stats":null,"previous_names":["sirraminyavari/ajv-ts-schema"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sirraminyavari/ajv-ts-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirraminyavari%2Fajv-ts-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirraminyavari%2Fajv-ts-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirraminyavari%2Fajv-ts-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirraminyavari%2Fajv-ts-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sirraminyavari","download_url":"https://codeload.github.com/sirraminyavari/ajv-ts-schema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirraminyavari%2Fajv-ts-schema/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261749217,"owners_count":23203990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajv","json-schema","json-schema-validation","json-schema-validator","schema-validator","ts-schema-validation","typescript-ajv","typescript-schema-validation","validation","validator"],"created_at":"2025-01-31T16:21:17.087Z","updated_at":"2025-06-24T20:09:46.795Z","avatar_url":"https://github.com/sirraminyavari.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A TypeScript-first approach to defining JSON Schemas for use with `AJV`.\n\n## Overview\n\n`AJV` is a powerful JSON Schema validator, but creating schemas directly in JavaScript or TypeScript can be verbose and error-prone. This package, `@raminyavari/ajv-ts-schema`, bridges the gap by allowing you to define schemas using TypeScript decorators, making your schemas type-safe and reusable.\n\n## Features\n\n- **Type-Safe Validation**: Leverages TypeScript for safer, cleaner schema definitions.\n- **Decorator-Based**: Simplifies schema creation with class and property decorators.\n- **AJV Integration**: Easily compile and validate schemas using `AJV`.\n- **Schema Reusability**: Use defined schemas for validation, request processing, and more.\n\n## Installation\n\n```bash\nnpm install @raminyavari/ajv-ts-schema\n```\n\nOr if you use yarn:\n\n```bash\nyarn add @raminyavari/ajv-ts-schema\n```\n\nEnable decorators in your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n```\n\n_If you are a contributor and wnat to clone and run on your local_\n\nMake sure `Husky` will run properly by running these commands from the root of the project:\n\n```bash\nchmod +x .husky/pre-commit\nchmod +x .husky/_/husky.sh\n```\n\nThen run:\n\n```bash\nyarn\nyarn test # or 'yarn test:ui'\n```\n\n## Quick Start\n\nDefine your schema using decorators:\n\n```tsx\nimport { AjvObject, AjvProperty, AjvSchema } from \"@raminyavari/ajv-ts-schema\";\n\n@AjvObject()\nclass MySchema extends AjvSchema {\n  @AjvProperty({ type: \"number\", required: true })\n  foo!: number;\n\n  @AjvProperty({ type: \"string\", nullable: true })\n  bar?: string | null;\n}\n\nconst schema = MySchema.getSchema();\n```\n\nValidate with `AJV`:\n\n```tsx\nimport Ajv from \"ajv/dist/2020\";\nimport addFormats from \"ajv-formats\";\nimport { AjvSchema, type AjvJsonSchema } from \"@raminyavari/ajv-ts-schema\";\n\nconst ajv = new Ajv({ useDefaults: true });\naddFormats(ajv);\nconst validate = ajv.compile(schema); // 'schema' comes from 'MySchema.getSchema()'\n\nconst myFunction = (input: any) =\u003e {\n  if (!validate(input)) {\n    console.error(validate.errors);\n  }\n\n  // 'fromJson' returns and instance of 'MySchema'\n  const typedSchema = AjvSchema.fromJson\u003cMySchema\u003e(MySchema, input);\n};\n\n// or you can do this instead\n\nconst isMySchema = (input: any): input is AjvJsonSchema\u003cMySchema\u003e =\u003e {\n  return validate(input);\n};\n\nconst myFunction = (input: any) =\u003e {\n  if (!isMySchema(input)) {\n    console.error(validate.errors);\n  }\n\n  // for the rest of the code 'input' is of type 'AjvJsonSchema\u003cMySchema\u003e'\n  // which is a JSON object\n};\n```\n\n## Key Advantages\n\n- **Code Completion**: Enhanced development experience with IDE suggestions.\n- **Error Prevention**: Catch issues at compile-time rather than runtime.\n- **Reusability**: Convert validated JSON objects into typed instances using `fromJson`.\n\n## Documentation\n\n- Full documentation and examples: [Documentation](https://www.raminy.dev/article/18712bd0-e06d-80b2-8e76-f86720b48d01/Simplifying%20AJV%20Schema%20Validation%20with%20TypeScript)\n- NPM Package: [@raminyavari/ajv-ts-schema](https://www.npmjs.com/package/@raminyavari/ajv-ts-schema)\n- JSON Schema Reference: [AJV Docs](https://github.com/ajv-validator/ajv/blob/master/docs/json-schema.md)\n\n## Contributing\n\nContributions are welcome! Please submit issues or pull requests on the [GitHub Repository](https://github.com/sirraminyavari/ajv-ts-schema).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirraminyavari%2Fajv-ts-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirraminyavari%2Fajv-ts-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirraminyavari%2Fajv-ts-schema/lists"}