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 - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

6

functions/schema.js

@@ -15,6 +15,8 @@ "use strict";

const results = [];
const path = paths.target || paths.given;
if (!targetVal)
return [
{
message: `${paths.target ? paths.target.join('.') : 'property'} does not exist`,
path,
message: `${paths ? path.join('.') : 'property'} does not exist`,
},

@@ -29,3 +31,3 @@ ];

results.push({
path: paths.given.concat(e.dataPath.split('/').slice(1)),
path: path.concat(e.dataPath.split('/').slice(1)),
message: e.message ? e.message : '',

@@ -32,0 +34,0 @@ });

@@ -1,2 +0,2 @@

import { IFunction, ITruthRuleOptions } from '../types';
export declare const truthy: IFunction<ITruthRuleOptions>;
import { IFunction } from '../types';
export declare const truthy: IFunction;

@@ -7,2 +7,3 @@ "use strict";

const has = require('lodash/has');
const invert = require('lodash/invert');
exports.lintNode = (node, rule, then, apply, opts) => {

@@ -64,9 +65,12 @@ const givenPath = node.path[0] === '$' ? node.path.slice(1) : node.path;

}) || [];
const severity = rule.severity || types_1.ValidationSeverity.Warn;
const severityLabel = rule.severityLabel || types_1.ValidationSeverityLabel[invert(types_1.ValidationSeverity)[severity]];
results = results.concat(targetResults.map(result => {
return {
name: rule.name,
summary: rule.summary,
message: result.message,
severity: rule.severity || types_1.ValidationSeverity.Error,
severityLabel: rule.severityLabel || types_1.ValidationSeverityLabel.Error,
path: result.path || targetPath,
severity,
severityLabel,
};

@@ -73,0 +77,0 @@ }));

{
"name": "@stoplight/spectral",
"version": "1.0.0",
"version": "1.0.1",
"description": "A flexible object linter with out of the box support for OpenAPI v2 and v3.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,2 +0,2 @@

# Spectral
![Spectral logo](img/spectral-banner.png)

@@ -12,3 +12,3 @@ [![Test Coverage](https://api.codeclimate.com/v1/badges/1aa53502913a428f40ac/test_coverage)](https://codeclimate.com/github/stoplightio/spectral/test_coverage)

- Create custom functions for advanced use cases.
- Optional ready to use rules and functions to validate and lint OpenAPI v2 _and_ v3 documents.
- Optional ready to use rules and functions to validate and lint OpenAPI Specification (OAS) 2 _and_ 3 documents.
- Validate JSON with [Ajv](https://github.com/epoberezkin/ajv).

@@ -38,3 +38,3 @@

```javascript
const { RuleFunction, Spectral } = require("@stoplight/spectral");
const { RuleFunction, Spectral } = require('@stoplight/spectral');

@@ -45,6 +45,6 @@ const spectral = new Spectral();

snake_case: {
summary: "Checks for snake case pattern",
summary: 'Checks for snake case pattern',
// evaluate every property
given: "$..*",
given: '$..*',

@@ -54,10 +54,10 @@ then: {

functionOptions: {
match: "^[a-z]+[a-z0-9_]*[a-z0-9]+$"
}
}
}
match: '^[a-z]+[a-z0-9_]*[a-z0-9]+$',
},
},
},
});
const results = spectral.run({
name: "helloWorld"
name: 'helloWorld',
});

@@ -73,4 +73,4 @@

// "message": "must match the pattern '^[a-z]+[a-z0-9_]*[a-z0-9]+$'",
// "severity": 50,
// "severityLabel": "error",
// "severity": 40,
// "severityLabel": "warn",
// "path": [

@@ -89,3 +89,3 @@ // "name"

```javascript
const { Spectral } = require("@stoplight/spectral");
const { Spectral } = require('@stoplight/spectral');

@@ -100,4 +100,4 @@ // custom function

{
message: `Use ${suggestion} instead of ${match}!`
}
message: `Use ${suggestion} instead of ${match}!`,
},
];

@@ -110,3 +110,3 @@ }

spectral.addFunctions({
notThat: customNotThatFunction
notThat: customNotThatFunction,
});

@@ -116,22 +116,22 @@

openapi_not_swagger: {
summary: "Checks for use of Swagger, and suggests OpenAPI.",
summary: 'Checks for use of Swagger, and suggests OpenAPI.',
// check every property
given: "$..*",
given: '$..*',
then: {
// reference the function we added!
function: "notThat",
function: 'notThat',
// pass it the options it needs
functionOptions: {
match: "Swagger",
suggestion: "OpenAPI"
}
}
}
match: 'Swagger',
suggestion: 'OpenAPI',
},
},
},
});
const results = spectral.run({
description: "Swagger is pretty cool!"
description: 'Swagger is pretty cool!',
});

@@ -147,4 +147,4 @@

// "message": "Use OpenAPI instead of Swagger!",
// "severity": 50,
// "severityLabel": "error",
// "severity": 40,
// "severityLabel": "warn",
// "path": [

@@ -160,3 +160,3 @@ // "description"

Spectral also includes a number of ready made rules and functions for OpenAPI 2 and 3 documents. This example uses the OpenAPI 2 rules to lint an OpenAPI 2 document.
Spectral also includes a number of ready made rules and functions for OpenAPI Specification (OAS) 2 and 3 documents. This example uses the OAS 2 rules to lint a document.

@@ -166,7 +166,4 @@ You can also add to these rules to create a customized linting style guide for your OAS documents.

```javascript
const { Spectral } = require("@stoplight/spectral");
const {
oas2Functions,
oas2Rules
} = require("@stoplight/spectral/rulesets/oas2");
const { Spectral } = require('@stoplight/spectral');
const { oas2Functions, oas2Rules } = require('@stoplight/spectral/rulesets/oas2');

@@ -177,9 +174,9 @@ // an OASv2 document

responses: {
"200": {
description: "",
'200': {
description: '',
schema: {
$ref: "#/definitions/error-response"
}
}
}
$ref: '#/definitions/error-response',
},
},
},
// ... properties in your document

@@ -226,6 +223,8 @@ };

If you are interested in contributing to Spectral itself, check out our [contributing docs](CONTRIBUTING.md) to get started.
If you are interested in contributing to Spectral itself, check out our [contributing docs](CONTRIBUTING.md) [Coming soon!] to get started.
If you are using Spectral in your open source project and want to be listed in the examples section, we encourage you to open an [issue](https://github.com/stoplightio/spectral/issues).
Also, most of the interesting projects are built _with_ Spectral. Please consider using Spectral in a project or contribute to an [existing one](#example-implementations).
If you are using Spectral in your project and want to be listed in the examples section, we encourage you to open an [issue](https://github.com/stoplightio/spectral/issues).
## Helpful Links

@@ -232,0 +231,0 @@

@@ -14,3 +14,3 @@ "use strict";

ids.push({
path: ['$', 'paths', path, operation, 'operationId'],
path: ['paths', path, operation, 'operationId'],
operationId,

@@ -17,0 +17,0 @@ });

@@ -62,3 +62,3 @@ "use strict";

const nameVal = nonUnique[group][firstMatch].name;
let message = `Operations must have unique \`name\` + \`in\` parameters.\nRepeats of \`in:${inVal}\` + \`name:${nameVal}\` \n\nParameters found at:\n`;
let message = `Operations must have unique \`name\` + \`in\` parameters.\nRepeats of \`in:${inVal}\` + \`name:${nameVal}\`\n\nParameters found at:\n`;
for (const index in nonUnique[group]) {

@@ -71,3 +71,3 @@ if (!inBody[index]) {

message,
path: ['$', 'paths', path, operation],
path: ['paths', path, operation],
});

@@ -85,3 +85,3 @@ }

message,
path: ['$', 'paths', path, operation],
path: ['paths', path, operation],
});

@@ -98,3 +98,3 @@ }

message,
path: ['$', 'paths', path, operation],
path: ['paths', path, operation],
});

@@ -101,0 +101,0 @@ }

@@ -21,3 +21,3 @@ "use strict";

message: 'operation referencing undefined security scheme',
path: ['$', 'paths', path, operation, 'security', index],
path: ['paths', path, operation, 'security', index],
});

@@ -24,0 +24,0 @@ }

@@ -319,2 +319,3 @@ "use strict";

summary: 'given keys should not end with a slash.',
type: types_1.RuleType.STYLE,
given: '$..paths',

@@ -321,0 +322,0 @@ then: {

@@ -24,6 +24,3 @@ import { ValidationSeverity, ValidationSeverityLabel } from '@stoplight/types/validations';

}
export interface ITruthRuleOptions {
properties: string | string[];
}
export declare type TruthyRule = IRule<RuleFunction.TRUTHY, ITruthRuleOptions>;
export declare type TruthyRule = IRule<RuleFunction.TRUTHY>;
export interface IXorRuleOptions {

@@ -30,0 +27,0 @@ properties: string[];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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