{"id":18375823,"url":"https://github.com/apideck-libraries/reva","last_synced_at":"2025-04-06T20:31:13.058Z","repository":{"id":37101137,"uuid":"434616525","full_name":"apideck-libraries/reva","owner":"apideck-libraries","description":"Server-side request validator for Node.js based on OpenAPI","archived":false,"fork":false,"pushed_at":"2023-02-04T03:40:06.000Z","size":523,"stargazers_count":13,"open_issues_count":6,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T21:33:12.893Z","etag":null,"topics":["ajv","nodejs","openapi","validation"],"latest_commit_sha":null,"homepage":"","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/apideck-libraries.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":"2021-12-03T14:02:40.000Z","updated_at":"2024-08-08T05:44:12.000Z","dependencies_parsed_at":"2023-02-18T13:30:49.760Z","dependency_job_id":null,"html_url":"https://github.com/apideck-libraries/reva","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apideck-libraries%2Freva","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apideck-libraries%2Freva/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apideck-libraries%2Freva/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apideck-libraries%2Freva/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apideck-libraries","download_url":"https://codeload.github.com/apideck-libraries/reva/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247547309,"owners_count":20956533,"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","nodejs","openapi","validation"],"created_at":"2024-11-06T00:20:34.780Z","updated_at":"2025-04-06T20:31:12.672Z","avatar_url":"https://github.com/apideck-libraries.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm (scoped)](https://img.shields.io/npm/v/@apideck/reva?color=brightgreen)](https://npmjs.com/@apideck/reva) [![npm](https://img.shields.io/npm/dm/@apideck/reva)](https://npmjs.com/@apideck/reva) [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/apideck-libraries/reva/main.yml?branch=main)](https://github.com/apideck-libraries/reva/actions/workflows/main.yml?query=branch%3Amain++)\n\n# @apideck/reva 🕵\n\n\u003e Server-side **re**quest **va**lidator for Node.js based on OpenAPI\n\n- Supports all OpenAPI parameters\n- Based on [AJV](https://github.com/ajv-validator/ajv)\n- Readable and helpful errors (by [@apideck/better-ajv-errors](https://github.com/apideck-libraries/better-ajv-errors))\n- High quality TypeScript definitions included\n- Minimal footprint: 42 kB including AJV (gzip + minified)\n\n## Install\n\n```bash\n$ yarn add @apideck/reva\n```\n\nor\n\n```bash\n$ npm i @apideck/reva\n```\n\n## Usage\n\nCreate a Reva instance and call the `validate` method with your [OpenAPI operation](https://spec.openapis.org/oas/v3.1.0#operation-object) and your request data.\n\n```ts\nimport { Reva } from '@apideck/reva';\n\nconst reva = new Reva();\n\nconst result = reva.validate({\n  operation, // OpenAPI operation\n  request: {\n    headers: { 'X-My-Header': 'value', Cookie: 'Key=Value' },\n    pathParameters: { id: 'ed55e7a3' },\n    queryParameters: { order_by: 'created' },\n    body: { name: 'Jane Doe' },\n  },\n});\n\nif (result.ok) {\n  // Valid request!\n} else {\n  // Invalid request, result.errors contains validation errors\n  console.log(result.errors);\n  // {\n  //   \"ok\": false,\n  //   \"errors\": [\n  //     {\n  //       \"path\": \"request.query\",\n  //       \"message\": \"'order_by' property must be equal to one of the allowed values\",\n  //       \"suggestion\": \"Did you mean 'created_at'?\",\n  //       \"context\": { \"errorType\": \"enum\", \"allowedValues\": [\"created_at\", \"updated_at\"] }\n  //     },\n  //     {\n  //       \"path\": \"request.header\",\n  //       \"message\": \"request.header must have required property 'x-required-header'\",\n  //       \"context\": { \"errorType\": \"required\" }\n  //     },\n  //     {\n  //       \"path\": \"request.body\",\n  //       \"message\": \"'name' property is not expected to be here\",\n  //       \"context\": { \"errorType\": \"additionalProperties\" }\n  //     }\n  //   ]\n  // }\n\n}\n```\n\n## API\n\n### Reva\n\nReva is the main **Re**quest **va**lidation class. You can optionally pass options to the constructor.\n\n#### new Reva(options?: RevaOptions)\n\n**Parameters**\n\n- `options: RevaOptions`\n  - `allowAdditionalParameters?: true | OpenApiParameterType[]` Allow additional parameters to be passed that are not defined in the OpenAPI operation. Use `true` to allow all parameter types to have additional parameters. Default value: `['header', 'cookie']`\n  - `partialBody?: boolean` Ignore required properties on the requestBody. This option is useful for update endpoints where a subset of required properties is allowed. Default value: `false`\n  - `groupedParameters?: OpenApiParameterType[]` Validate multiple OpenAPI parameter types as one schema. This is useful for APIs where parameters (`query`,`path`, etc) are combined into a single `parameters` object. Default value: `[]`\n  - `paramAjvOptions?: AjvOptions` Custom AJV options for request param validation.\n  - `bodyAjvOptions?: AjvOptions` Custom AJV options for request body validation.\n\n#### reva.validate(options: RevaValidateOptions)\n\nValidate requests based on OpenAPI. Parameter validation uses [type coercion](https://ajv.js.org/coercion.html), request body validation does not. When a Content-Type header is passed, it has to match a Content-Type defined in the OpenAPI operation. Default Content-Type is `application/json`.\n\n**Parameters**\n\n- `options: RevaValidateOptions`\n  - `operation: OpenApiOperation` Your OpenAPI operation object to validate against\n  - `request: RevaRequest` The request data to validate. All properties are optional\n    - `queryParameters?: Record\u003cstring, unknown\u003e` Query parameters to validate\n    - `headers?: Record\u003cstring, unknown\u003e` Headers to validate\n    - `pathParameters?: Record\u003cstring, unknown\u003e` Path parameters to validate\n    - `body?: unknown` Request body to validate\n  - `options?: RevaOptions` Override options set in the Reva constructor\n\n**Return Value**\n\n- `Result\u003cValidationError\u003e`\n  - `ok: boolean` Indicates if the request is valid or not\n  - `errors?: ValidationError[]` Array of formatted errors. Only populated when `Result.ok` is `false`\n    - `message: string` Formatted error message\n    - `suggestion?: string` Optional suggestion based on provided data and schema\n    - `path: string` Object path where the error occurred (example: `.foo.bar.0.quz`)\n    - `context: { errorType: DefinedError['keyword']; [additionalContext: string]: unknown }` `errorType` is `error.keyword` proxied from `ajv`. `errorType` can be used as a key for i18n if needed. There might be additional properties on context, based on the type of error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapideck-libraries%2Freva","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapideck-libraries%2Freva","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapideck-libraries%2Freva/lists"}