{"id":15674144,"url":"https://github.com/xotabu4/response-openapi-validator","last_synced_at":"2025-05-05T21:45:39.208Z","repository":{"id":44591945,"uuid":"302930810","full_name":"Xotabu4/response-openapi-validator","owner":"Xotabu4","description":"Asserts your responses against Swagger/OpenApi docs. Useful for API testing.","archived":false,"fork":false,"pushed_at":"2024-07-31T09:12:58.000Z","size":60,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-05T19:16:03.927Z","etag":null,"topics":["ajv","openapi","swagger","testing"],"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/Xotabu4.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-10T15:23:47.000Z","updated_at":"2025-02-15T09:37:55.000Z","dependencies_parsed_at":"2024-10-23T11:55:11.998Z","dependency_job_id":null,"html_url":"https://github.com/Xotabu4/response-openapi-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotabu4%2Fresponse-openapi-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotabu4%2Fresponse-openapi-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotabu4%2Fresponse-openapi-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotabu4%2Fresponse-openapi-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xotabu4","download_url":"https://codeload.github.com/Xotabu4/response-openapi-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252582332,"owners_count":21771646,"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","openapi","swagger","testing"],"created_at":"2024-10-03T15:43:40.644Z","updated_at":"2025-05-05T21:45:39.192Z","avatar_url":"https://github.com/Xotabu4.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# response-openapi-validator\n\nThis library allows to match your existing response against your swagger/openapi docs.\n\n- Does lookup in your docs, and finds schema defined for provided response\n- Uses AJV to validate response body against found schema \n- Provides nice and clean errors\n- Framework/Stack agnostic (works with everything)\n- OpenApi v3 support is not yet verified\n\n\n```typescript\nimport { ResponseValidator } from \"response-openapi-validator\";\n\nconst validator = new ResponseValidator({\n    // Also can be URL\n    openApiSpecPath: \"./.temp/open_api_docs.json\",\n});\n\nconst response = await got(\"http://someserver.com/api/something\");\n\nawait validator.assertResponse({\n    method: response.request?.options?.method,\n    requestUrl: response?.request?.requestUrl,\n    statusCode: response?.statusCode,\n    body: response.body,\n});\n```\n\n### Option: ajvOptions\n\nAJV is used to match found JSON schema against body.\nYou can define AJV options by passing param:\n\n```typescript\nconst validator = new ResponseValidator({\n    // Also can be URL\n    openApiSpecPath: \"./.temp/open_api_docs.json\",\n    // You can see all AJV options here\n    // https://github.com/ajv-validator/ajv#options\n    ajvOptions: {\n        // I recommend to keep allErrors, verbose, and jsonPointers options enabled\n        allErrors: true,\n        verbose: true,\n        jsonPointers: true,\n\n        // Define additional JSON schema formats, if needed\n        formats: {\n            double: \"[+-]?\\\\d*\\\\.?\\\\d+\",\n            int32: /^(-?\\d{1,9}|-?1\\d{9}|-?20\\d{8}|-?21[0-3]\\d{7}|-?214[0-6]\\d{6}|-?2147[0-3]\\d{5}|-?21474[0-7]\\d{4}|-?214748[012]\\d{4}|-?2147483[0-5]\\d{3}|-?21474836[0-3]\\d{2}|214748364[0-7]|-214748364[0-8])$/,\n            int64: /^\\d+$/,\n        },\n    },\n});\n```\n\n### Option: apiPathPrefix\n\nSometimes API has prefix part, which is not defined in docs.\n\nReal path:\n\n```\n/core/user/create\n```\n\nPath defined in docs:\n\n```\n/user/create\n```\n\nYou can specify such prefix in options:\n\n```typescript\nconst validator = new OpenApiValidator({\n    apiPathPrefix: '/core'\n    openApiSpecPath: \"./.temp/open_api_docs.json\",\n});\n\nawait validator.assertResponse({\n    method: response.request?.options?.method,\n    requestUrl: response?.request?.requestUrl,\n    statusCode: response?.statusCode,\n    body: response.body,\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxotabu4%2Fresponse-openapi-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxotabu4%2Fresponse-openapi-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxotabu4%2Fresponse-openapi-validator/lists"}