{"id":27233069,"url":"https://github.com/expresso/validator","last_synced_at":"2025-04-10T14:11:20.109Z","repository":{"id":33082946,"uuid":"151322360","full_name":"expresso/validator","owner":"expresso","description":"JSON Schema validation middleware for Expresso","archived":false,"fork":false,"pushed_at":"2024-08-27T21:36:37.000Z","size":774,"stargazers_count":6,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T11:48:12.107Z","etag":null,"topics":["json-schema","schema","validation","validator"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/expresso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-02T20:56:38.000Z","updated_at":"2024-08-27T21:36:41.000Z","dependencies_parsed_at":"2023-01-14T23:17:49.238Z","dependency_job_id":null,"html_url":"https://github.com/expresso/validator","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expresso%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expresso%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expresso%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expresso%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expresso","download_url":"https://codeload.github.com/expresso/validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232419,"owners_count":21069487,"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":["json-schema","schema","validation","validator"],"created_at":"2025-04-10T14:11:19.494Z","updated_at":"2025-04-10T14:11:20.094Z","avatar_url":"https://github.com/expresso.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Expresso Validator\n\n\u003e JSON Schema validation middleware for [Expresso](https://github.com/expresso)\n\n## Summary\n\n- [Expresso Validator](#expresso-validator)\n  - [Summary](#summary)\n  - [What is this](#what-is-this)\n  - [Basic Usage](#basic-usage)\n    - [Validating queries](#validating-queries)\n    - [validateType function](#validatetype-function)\n  - [Errors](#errors)\n\n## What is this\n\nThis middleware validates an input against a [JSON Schema](https://json-schema.org) and automatically throws a boom error for `badData` (which is HTTP code `422 - Unprocessable Entity`) if this input is not matched.\n\n## Basic Usage\n\n**Install**:\n\n```sh\n$ npm i @expresso/validator\n```\n\n**Import and use**:\n\n```ts\nimport { validate } from '@expresso/validator'\n\n// Your expresso initialization here\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    age: {\n      type: 'integer'\n    }\n  },\n  additionalProperties: false,\n  required: ['name', 'age']\n}\n\napp.post('/users', validate(schema), (req: Reques, res: Response, next: NextFunction) =\u003e { // ... // })\n```\n\n### Validating queries\n\nBy default, the validator will match the schema against the body of the request, this is why the root type is `{ type: 'object' }`. It is also possible to validate the query string params:\n\n```ts\nimport { validate } from '@expresso/validator'\n\n// Your expresso initialization here\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    age: {\n      type: 'integer'\n    }\n  },\n  required: ['name', 'age']\n}\n\napp.get('/users', validate.query(schema), (req: Reques, res: Response, next: NextFunction) =\u003e { // ... // })\n```\n\nThis will validate the whole query string against the given schema.\n\n### validateType function\n`validateType` is actually a dummy function that should be removed in runtime. It exists to give type\nsafety for using [@expresso/ts-transformer-type-validator](https://www.npmjs.com/package/@expresso/ts-transformer-type-validator)\n\n## Errors\n\nThis validator follows Expresso's directives and returns a [Boom](https://github.com/hapijs/boom) error for BadData, right now it is not possible to change this behavior\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpresso%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpresso%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpresso%2Fvalidator/lists"}