oas-validator is a JavaScript library designed for parsing and validating OpenAPI 3.x definitions. The current stable version is 5.0.8. It operates as an assertion-based validator, meaning it ceases validation upon encountering the first structural error, which is crucial for preventing a cascade of spurious errors. However, it also offers a 'lint' option to report multiple warnings for non-critical issues. Key differentiators include its internal use of `reftools` for JSON Pointer and Reference resolution, a transition from older implementations like `jgeXml`. The library supports both Promise-based and callback-based asynchronous usage patterns, catering to different integration preferences. Its primary use case is ensuring the correctness and adherence to the OpenAPI specification of API definitions, often integrated into CI/CD pipelines or development tooling.
npm install oas-validatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use `oas-validator` with an OpenAPI 3.x definition, showcasing the Promise-based API and basic error handling.
To receive multiple non-critical warnings (e.g., linting issues), set the `lint` option to `true` in the validation options object (e.g., `{ lint: true }`). Critical structural errors will still halt validation immediately.Thoroughly test existing OpenAPI definitions after upgrading from versions predating the `reftools` integration to ensure no unexpected changes in validation behavior. Review `reftools` documentation if encountering specific reference resolution issues.
Consistently use either the Promise-based approach (`.then().catch()`) or the callback approach, but not both simultaneously. For modern async JavaScript, the Promise-based interface is generally recommended.
For ESM, use `import validator from 'oas-validator';` and then call `validator.validate(...)`. Ensure your project configuration (e.g., `package.json` `type` field) is set appropriately for ESM if using Node.js modules.
Change `import { validate } from 'oas-validator';` to `import validator from 'oas-validator';` and then use `validator.validate(...)`.Inspect the reported `Location` in the error context to identify and correct the specific part of your OpenAPI definition that is invalid. For a broader range of non-critical warnings, enable the `lint: true` option.
Convert `const validator = require('oas-validator');` to `import validator from 'oas-validator';`. Ensure your module is properly configured for ESM.No dependency data recorded yet.