Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oas-validator

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oas-validator

Parser/validator for OpenAPI 3.x definitions

  • 5.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
decreased by-1.95%
Maintainers
1
Weekly downloads
 
Created

What is oas-validator?

The oas-validator npm package is used to validate OpenAPI Specification (OAS) documents. It ensures that the OAS documents adhere to the OpenAPI standards and helps in identifying any discrepancies or errors in the API definitions.

What are oas-validator's main functionalities?

Validate OpenAPI 3.0 documents

This feature allows you to validate OpenAPI 3.0 documents to ensure they conform to the OpenAPI Specification. The code sample reads an OpenAPI document from a file and validates it using the oas-validator package.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/openapi.json', 'utf8'));

validator.validate(apiSpec, {}, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Validate OpenAPI 2.0 (Swagger) documents

This feature allows you to validate OpenAPI 2.0 (Swagger) documents. The code sample reads a Swagger document from a file and validates it using the oas-validator package, specifying the version as '2.0'.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/swagger.json', 'utf8'));

validator.validate(apiSpec, { version: '2.0' }, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Custom validation options

This feature allows you to use custom validation options such as linting and schema validation. The code sample demonstrates how to pass custom options to the validator.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/openapi.json', 'utf8'));

const options = {
  lint: true,
  validateSchema: true
};

validator.validate(apiSpec, options, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Other packages similar to oas-validator

Keywords

FAQs

Package last updated on 14 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc