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

@stoplight/spectral

Package Overview
Dependencies
Maintainers
11
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 2.3.2 to 2.4.0

rulesets/message.d.ts

7

formatters/stylish.js

@@ -41,8 +41,3 @@ "use strict";

}
return [
formatRange(result.range),
messageType,
result.code !== undefined ? result.code : '',
result.summary ? result.summary.replace(/([^ ])\.$/u, '$1') : result.message,
];
return [formatRange(result.range), messageType, result.code !== undefined ? result.code : '', result.message];
});

@@ -49,0 +44,0 @@ output += `${table(pathTableData, {

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

const jsonSpecv4 = require("ajv/lib/refs/json-schema-draft-04.json");
const oasFormatValidator = require('ajv-oai/lib/format-validator');
const ajv = new AJV({

@@ -16,2 +17,24 @@ meta: false,

ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';
ajv.addFormat('int32', { type: 'number', validate: oasFormatValidator.int32 });
ajv.addFormat('int64', { type: 'number', validate: oasFormatValidator.int64 });
ajv.addFormat('float', { type: 'number', validate: oasFormatValidator.float });
ajv.addFormat('double', { type: 'number', validate: oasFormatValidator.double });
ajv.addFormat('byte', { type: 'string', validate: oasFormatValidator.byte });
const formatPath = (path) => path
.split('/')
.slice(1)
.map(json_1.decodePointerFragment);
const mergeErrors = (existingError, newError) => {
switch (newError.keyword) {
case 'additionalProperties': {
const { additionalProperty } = newError.params;
if (!new RegExp(`[:,] ${additionalProperty}`).test(existingError.message)) {
existingError.message += `, ${newError.params.additionalProperty}`;
}
return true;
}
default:
return existingError.message === newError.message;
}
};
exports.schema = (targetVal, opts, paths) => {

@@ -29,14 +52,22 @@ const results = [];

if (!ajv.validate(schemaObj, targetVal) && ajv.errors) {
ajv.errors.forEach((e) => {
if (e.params && e.params.additionalProperty) {
e.message = e.message + ': ' + e.params.additionalProperty;
const collectedErrors = [];
for (const error of ajv.errors) {
if (collectedErrors.length > 0) {
const index = collectedErrors.indexOf(error.keyword);
if (index !== -1) {
if (mergeErrors(results[index], error))
continue;
}
}
let message = error.message || '';
if (error.keyword === 'additionalProperties' &&
error.params.additionalProperty) {
message += `: ${error.params.additionalProperty}`;
}
collectedErrors.push(error.keyword);
results.push({
path: path.concat(e.dataPath
.split('/')
.slice(1)
.map(frag => json_1.decodePointerFragment(frag))),
message: e.message ? e.message : '',
path: [...path, ...formatPath(error.dataPath)],
message,
});
});
}
}

@@ -43,0 +74,0 @@ return results;

@@ -65,4 +65,16 @@ "use strict";

results = results.concat(targetResults.map(result => {
const location = parsedResult.getLocationForJsonPath(parsed, result.path || targetPath, true);
return Object.assign({ code: rule.name, summary: rule.summary, message: result.message, path: result.path || targetPath, severity, source: parsedResult.source }, (location || {
const path = result.path || targetPath;
const location = parsedResult.getLocationForJsonPath(parsed, path, true);
return Object.assign({ code: rule.name, get summary() {
return this.message;
}, message: rule.message === undefined
? rule.summary || result.message
: typeof rule.message === 'function'
? rule.message({
error: result.message,
property: path.length > 0 ? path[path.length - 1] : '',
description: rule.description,
})
: rule.message, path,
severity, source: parsedResult.source }, (location || {
range: {

@@ -69,0 +81,0 @@ start: {

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

{"version":"2.3.2","commands":{"lint":{"id":"lint","description":"lint a JSON/YAML document from a file or URL","pluginName":"@stoplight/spectral","pluginType":"core","aliases":[],"examples":["$ spectral lint .openapi.yaml\nlinting ./openapi.yaml\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"config":{"name":"config","type":"option","char":"c","description":"path to a config file"},"encoding":{"name":"encoding","type":"option","char":"e","description":"text encoding to use"},"format":{"name":"format","type":"option","char":"f","description":"formatter to use for outputting results","options":["json","stylish"]},"output":{"name":"output","type":"option","char":"o","description":"output to a file instead of stdout"},"max-results":{"name":"max-results","type":"option","description":"[default: all] maximum results to show"},"maxResults":{"name":"maxResults","type":"option","char":"m","description":"deprecated: use --max-results instead"},"ruleset":{"name":"ruleset","type":"option","char":"r","description":"path to a ruleset file (supports remote files)"},"skip-rule":{"name":"skip-rule","type":"option","char":"s","description":"ignore certain rules if they are causing trouble"},"verbose":{"name":"verbose","type":"boolean","char":"v","description":"increase verbosity","allowNo":false}},"args":[{"name":"source"}]}}}
{"version":"2.4.0","commands":{"lint":{"id":"lint","description":"lint a JSON/YAML document from a file or URL","pluginName":"@stoplight/spectral","pluginType":"core","aliases":[],"examples":["$ spectral lint .openapi.yaml\nlinting ./openapi.yaml\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"config":{"name":"config","type":"option","char":"c","description":"path to a config file"},"encoding":{"name":"encoding","type":"option","char":"e","description":"text encoding to use"},"format":{"name":"format","type":"option","char":"f","description":"formatter to use for outputting results","options":["json","stylish"]},"output":{"name":"output","type":"option","char":"o","description":"output to a file instead of stdout"},"max-results":{"name":"max-results","type":"option","description":"[default: all] maximum results to show"},"maxResults":{"name":"maxResults","type":"option","char":"m","description":"deprecated: use --max-results instead"},"ruleset":{"name":"ruleset","type":"option","char":"r","description":"path to a ruleset file (supports remote files)"},"skip-rule":{"name":"skip-rule","type":"option","char":"s","description":"ignore certain rules if they are causing trouble"},"verbose":{"name":"verbose","type":"boolean","char":"v","description":"increase verbosity","allowNo":false}},"args":[{"name":"source"}]}}}
{
"name": "@stoplight/spectral",
"version": "2.3.2",
"version": "2.4.0",
"description": "A flexible object linter with out of the box support for OpenAPI v2 and v3.",

@@ -38,2 +38,3 @@ "keywords": [

"ajv": "6.x.x",
"ajv-oai": "^1.1.1",
"chalk": "^2.4.2",

@@ -45,3 +46,3 @@ "jsonpath": "https://github.com/stoplightio/jsonpath#f1c0e9e634da2d45671b7639fa0a99afc807da17",

"text-table": "^0.2.0",
"typescript-json-schema": "^0.37.0"
"typescript-json-schema": "^0.38.0"
},

@@ -48,0 +49,0 @@ "pkg": {

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

const types_2 = require("../../types");
const message_1 = require("../message");
exports.operationPath = "$..paths.*[?( name() === 'get' || name() === 'put' || name() === 'post'" +

@@ -60,2 +61,3 @@ " || name() === 'delete' || name() === 'options' || name() === 'head'" +

summary: 'Path parameters are correct and valid.',
message: message_1.message `${'error'}`,
type: types_2.RuleType.VALIDATION,

@@ -62,0 +64,0 @@ severity: types_1.DiagnosticSeverity.Error,

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

const types_2 = require("../../types");
const message_1 = require("../message");
const oas_1 = require("../oas");

@@ -14,3 +15,3 @@ const schema = require("./schemas/main.json");

'oas2-schema': {
summary: 'Validate structure of OpenAPIv2 specification.',
message: message_1.message `${'error'}`,
type: types_2.RuleType.VALIDATION,

@@ -27,3 +28,3 @@ severity: types_1.DiagnosticSeverity.Error,

'api-host': {
summary: 'OpenAPI `host` must be present and non-empty string.',
message: 'OpenAPI `host` must be present and non-empty string.',
type: types_2.RuleType.STYLE,

@@ -38,3 +39,3 @@ given: '$',

'api-schemes': {
summary: 'OpenAPI host `schemes` must be present and non-empty array.',
message: 'OpenAPI host `schemes` must be present and non-empty array.',
type: types_2.RuleType.STYLE,

@@ -59,3 +60,3 @@ given: '$',

enabled: false,
summary: 'Server URL should not point at `example.com`.',
message: 'Server URL should not point at `example.com`.',
type: types_2.RuleType.STYLE,

@@ -72,3 +73,3 @@ given: '$',

'host-trailing-slash': {
summary: 'Server URL should not have a trailing slash.',
message: 'Server URL should not have a trailing slash.',
type: types_2.RuleType.STYLE,

@@ -86,3 +87,3 @@ given: '$',

enabled: false,
summary: 'Definition `description` must be present and non-empty string.',
message: 'Definition `description` must be present and non-empty string.',
type: types_2.RuleType.STYLE,

@@ -96,3 +97,3 @@ given: '$..definitions[*]',

'operation-security-defined': {
summary: 'Operation `security` values must match a scheme defined in the `securityDefinitions` object.',
message: 'Operation `security` values must match a scheme defined in the `securityDefinitions` object.',
type: types_2.RuleType.VALIDATION,

@@ -109,3 +110,3 @@ given: '$',

'valid-example': {
summary: 'Examples must be valid against their defined schema.',
message: message_1.message `"${'property'}" property ${'error'}`,
type: types_2.RuleType.VALIDATION,

@@ -112,0 +113,0 @@ given: '$..[?(@.example)]',

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

const types_2 = require("../../types");
const message_1 = require("../message");
const oas_1 = require("../oas");

@@ -14,3 +15,3 @@ const schema = require("./schemas/main.json");

'oas3-schema': {
summary: 'Validate structure of OpenAPIv3 specification.',
message: message_1.message `${'error'}`,
type: types_2.RuleType.VALIDATION,

@@ -27,3 +28,3 @@ severity: types_1.DiagnosticSeverity.Error,

'api-servers': {
summary: 'OpenAPI `servers` must be present and non-empty array.',
message: 'OpenAPI `servers` must be present and non-empty array.',
type: types_2.RuleType.STYLE,

@@ -48,3 +49,3 @@ given: '$',

enabled: false,
summary: 'Model `description` must be present and non-empty string.',
message: 'Model `description` must be present and non-empty string.',
type: types_2.RuleType.STYLE,

@@ -58,3 +59,3 @@ given: '$.components.schemas[*]',

'operation-security-defined': {
summary: 'Operation `security` values must match a scheme defined in the `components.securitySchemes` object.',
message: 'Operation `security` values must match a scheme defined in the `components.securitySchemes` object.',
type: types_2.RuleType.VALIDATION,

@@ -72,3 +73,3 @@ given: '$',

enabled: false,
summary: 'Server URL should not point at `example.com`.',
message: 'Server URL should not point at `example.com`.',
type: types_2.RuleType.STYLE,

@@ -85,3 +86,3 @@ given: '$.servers[*]',

'server-trailing-slash': {
summary: 'Server URL should not have a trailing slash.',
message: 'Server URL should not have a trailing slash.',
type: types_2.RuleType.STYLE,

@@ -98,3 +99,3 @@ given: '$.servers[*]',

'valid-example': {
summary: 'Examples must be valid against their defined schema.',
message: message_1.message `"${'property'}" property ${'error'}`,
type: types_2.RuleType.VALIDATION,

@@ -101,0 +102,0 @@ given: '$..[?(@.example)]',

import { DiagnosticSeverity } from '@stoplight/types';
import { MessageInterpolator } from '../rulesets/message';
import { RuleFunction, RuleType } from './enums';

@@ -7,2 +8,3 @@ export declare type Rule = IRule | TruthyRule | XorRule | LengthRule | AlphaRule | PatternRule | SchemaRule;

summary?: string;
message?: string | MessageInterpolator;
description?: string;

@@ -9,0 +11,0 @@ severity?: DiagnosticSeverity;

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