Note This project is a fork from the openapi-library project because that project is not maintained at the moment. This project contains updates and security fixes, but ideally will be merged back into that project, as soon as it's maintained again.
Use Jest or Chai to assert that HTTP responses satisfy an OpenAPI spec.
If your server's behaviour doesn't match your API documentation, then you need to correct your server, your documentation, or both. The sooner you know the better.
These test plugins let you automatically test whether your server's behaviour and documentation match. They extend Jest and Chai to support the OpenAPI standard for documenting REST APIs. In your JavaScript tests, you can simply assert expect(responseObject).toSatisfyApiSpec()
These packages are published to the public npm registry under the scope @ehuelsmann:
@ehuelsmann/jest-openapi@ehuelsmann/chai-openapi-response-validator@ehuelsmann/openapi-validator
No authentication or token is required to install.
npm install --save-dev @ehuelsmann/jest-openapi
# or
npm install --save-dev @ehuelsmann/chai-openapi-response-validatoryarn add --dev @ehuelsmann/jest-openapi
# or
yarn add --dev @ehuelsmann/chai-openapi-response-validatorNote: These are published as scoped packages, so import using the scoped name — for example:
import jestOpenAPI from '@ehuelsmann/jest-openapi'import chaiOpenAPI from '@ehuelsmann/chai-openapi-response-validator'
Both packages ship as ESM-first (preferred) with a CommonJS fallback, supporting:
// ESM / TypeScript
import jestOpenAPI from '@ehuelsmann/jest-openapi';
import chaiOpenAPI from '@ehuelsmann/chai-openapi-response-validator';
// CommonJS
const jestOpenAPI = require('@ehuelsmann/jest-openapi').default;
const chaiOpenAPI = require('@ehuelsmann/chai-openapi-response-validator').default;Richard Waller 🚧 💻 📖 👀 |
Jonny Spruce 💻 📖 👀 |
Alex Dobeck 💻 🐛 |
Ben Guthrie 💻 🐛 |
Martijn Vegter 💻 |
Ludek 💻 🐛 |
Tommy Giardina 💻 🐛 |
Oleksandr Khotemskyi 📖 |
Amit Keinan 💻 |
DetachHead 🐛 |
Kristoffer Karlsson 📖 |