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

@stoplight/spectral

Package Overview
Dependencies
Maintainers
7
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/spectral

An object linting framework

  • 0.1.2-beta.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by12.61%
Maintainers
7
Weekly downloads
 
Created
Source

spectral

Warning This is still a prototype and not ready for general use.

This is an enhanced version of the speccy project. Differences between this project and speccy include:

  • Lint rules can be applied to any JSON object, not just OAS3 specifications.

  • All dependencies on the oas-kit repository have been removed, since rules are no longer OAS-specific.

  • The rule structure has been modified slightly to use JSONPath path parameters instead of the object parameters (which were OAS-specific).

  • Rules are more clearly defined (thanks to TypeScript typings) and now require specifying a type parameter.

  • Some rule types have been enhanced to be a little more flexible. An example of this includes the ability to specify the object to be linted in the path parameter itself, instead of relying on rule-specific options to be applied.

  • Ported to TypeScript.

Things that speccy has, but spectral does not (though they would be easy to add):

  • A 'server' and CLI mode

  • The ability to add rules from file

  • The ability for rule files to specify a dependency on other rule files

Usage

import { Spectral } from '@stoplight/spectral';
import { defaultRuleset } from '@stoplight/spectral/rulesets';

// an OASv2 specification
var myOAS = {
  [...]
  responses: {
    '401asdf': {
      description: '',
      schema: {
        $ref: '#/definitions/error-response',
      },
    },
  },
  [...]
};

// create a new instance of spectral with all of the baked in rulesets
const spectral = new Spectral({ rulesets: [defaultRuleset()] });

// run!
console.log(spectral.run({ spec: 'oas2', target: myOAS }));

//  [ {
//   path: '$.responses',
//   rule:
//     { type: 'pattern',
//       name: 'all-responses-must-be-numeric',
//       path: '$..responses',
//       enabled: true,
//       description: 'reference components should all match regex ^[0-9]+',
//       pattern: { property: '*', value: '^[0-9]+$' } },
//     error:
//       Error {
//         operator: 'to be',
//         expected: true,
//         message: 'reference components should all match regex ^[0-9]+',
//         showDiff: true,
//         actual: false,
//         stackStartFunction: [Function: assert],
//         negate: false,
//         assertion:
//         Assertion {
//           obj: false,
//           anyOne: false,
//           negate: false,
//           params: [Object],
//           onlyThis: undefined,
//           light: false } } } ]

FAQs

Package last updated on 03 Dec 2018

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