{"library":"oas-validator","title":"OpenAPI Validator","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install oas-validator"],"cli":null},"imports":["import validator from 'oas-validator';\n// Then use validator.validate(openapi, options);","const validator = require('oas-validator');\n// Then use validator.validate(openapi, options);","import type { Options as ValidationOptions } from 'oas-validator';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import validator from 'oas-validator';\n\nconst openapiDefinition = {\n  openapi: '3.0.0',\n  info: {\n    title: 'Sample API',\n    version: '1.0.0',\n  },\n  paths: {\n    '/hello': {\n      get: {\n        summary: 'Says hello',\n        responses: {\n          '200': {\n            description: 'A greeting',\n            content: {\n              'text/plain': {\n                schema: { type: 'string' }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n};\n\nconst options = {}; // No linting, stops on first error\n\nvalidator.validate(openapiDefinition, options)\n  .then(function(result){\n    if (result.valid) {\n      console.log('OpenAPI definition is valid.');\n    } else {\n      // This branch is rarely hit for critical errors due to assertion-based validation\n      console.warn('OpenAPI definition has warnings or soft errors:', result.warnings);\n    }\n  })\n  .catch(function(err){\n    console.error('Validation error caught:', err.message);\n    if (err.context) console.error('Location:', err.context.pop());\n  });","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}