@redocly/openapi-core 1.0.0-beta.100 → 1.0.0-beta.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/config.d.ts +3 -3
- package/lib/config/load.d.ts +1 -1
- package/lib/config/load.js +15 -2
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/types.d.ts +4 -2
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +67 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/oas2/index.d.ts +2 -0
- package/lib/decorators/oas2/index.js +5 -1
- package/lib/decorators/oas3/index.d.ts +2 -0
- package/lib/decorators/oas3/index.js +5 -1
- package/lib/index.d.ts +1 -1
- package/lib/lint.d.ts +2 -0
- package/lib/lint.js +2 -2
- package/lib/redocly/registry-api-types.d.ts +2 -0
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +3 -1
- package/lib/rules/common/assertions/asserts.d.ts +6 -1
- package/lib/rules/common/assertions/asserts.js +82 -49
- package/lib/rules/common/assertions/utils.d.ts +2 -1
- package/lib/rules/common/assertions/utils.js +27 -8
- package/lib/types/oas3.js +0 -3
- package/lib/types/oas3_1.js +1 -4
- package/lib/types/redocly-yaml.js +318 -27
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +5 -1
- package/lib/walk.d.ts +2 -0
- package/lib/walk.js +16 -7
- package/package.json +1 -1
- package/src/__tests__/lint.test.ts +17 -4
- package/src/config/__tests__/load.test.ts +6 -0
- package/src/config/load.ts +28 -5
- package/src/config/types.ts +6 -5
- package/src/decorators/__tests__/filter-in.test.ts +310 -0
- package/src/decorators/__tests__/filter-out.test.ts +227 -0
- package/src/decorators/common/filters/filter-helper.ts +72 -0
- package/src/decorators/common/filters/filter-in.ts +18 -0
- package/src/decorators/common/filters/filter-out.ts +18 -0
- package/src/decorators/oas2/index.ts +5 -1
- package/src/decorators/oas3/index.ts +5 -1
- package/src/index.ts +1 -0
- package/src/lint.ts +4 -3
- package/src/redocly/registry-api-types.ts +2 -0
- package/src/redocly/registry-api.ts +4 -0
- package/src/rules/common/assertions/__tests__/asserts.test.ts +154 -140
- package/src/rules/common/assertions/asserts.ts +98 -50
- package/src/rules/common/assertions/utils.ts +41 -16
- package/src/types/oas3.ts +0 -2
- package/src/types/oas3_1.ts +1 -3
- package/src/types/redocly-yaml.ts +323 -34
- package/src/utils.ts +10 -7
- package/src/walk.ts +39 -19
- package/tsconfig.tsbuildinfo +1 -1
package/lib/config/config.d.ts
CHANGED
|
@@ -31,13 +31,13 @@ export declare class LintConfig {
|
|
|
31
31
|
addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
|
|
32
32
|
extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
|
|
33
33
|
getRuleSettings(ruleId: string, oasVersion: OasVersion): {
|
|
34
|
-
severity: import("
|
|
34
|
+
severity: import("./types").RuleSeverity;
|
|
35
35
|
};
|
|
36
36
|
getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
37
|
-
severity: import("
|
|
37
|
+
severity: import("./types").RuleSeverity;
|
|
38
38
|
};
|
|
39
39
|
getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
40
|
-
severity: import("
|
|
40
|
+
severity: import("./types").RuleSeverity;
|
|
41
41
|
};
|
|
42
42
|
getUnusedRules(): {
|
|
43
43
|
rules: string[];
|
package/lib/config/load.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import type { RawConfig } from './types';
|
|
3
|
-
export declare function loadConfig(configPath?: string | undefined, customExtends?: string[]): Promise<Config>;
|
|
3
|
+
export declare function loadConfig(configPath?: string | undefined, customExtends?: string[], processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>): Promise<Config>;
|
|
4
4
|
export declare const CONFIG_FILE_NAMES: string[];
|
|
5
5
|
export declare function findConfig(dir?: string): string | undefined;
|
|
6
6
|
export declare function getConfig(configPath?: string | undefined): Promise<RawConfig>;
|
package/lib/config/load.js
CHANGED
|
@@ -17,10 +17,9 @@ const utils_1 = require("../utils");
|
|
|
17
17
|
const config_1 = require("./config");
|
|
18
18
|
const utils_2 = require("./utils");
|
|
19
19
|
const config_resolvers_1 = require("./config-resolvers");
|
|
20
|
-
function
|
|
20
|
+
function addConfigMetadata({ rawConfig, customExtends, configPath }) {
|
|
21
21
|
var _a;
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const rawConfig = yield getConfig(configPath);
|
|
24
23
|
if (customExtends !== undefined) {
|
|
25
24
|
rawConfig.lint = rawConfig.lint || {};
|
|
26
25
|
rawConfig.lint.extends = customExtends;
|
|
@@ -61,7 +60,21 @@ function loadConfig(configPath = findConfig(), customExtends) {
|
|
|
61
60
|
return config_resolvers_1.resolveConfig(rawConfig, configPath);
|
|
62
61
|
});
|
|
63
62
|
}
|
|
63
|
+
function loadConfig(configPath = findConfig(), customExtends, processRawConfig) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const rawConfig = yield getConfig(configPath);
|
|
66
|
+
if (typeof processRawConfig === 'function') {
|
|
67
|
+
yield processRawConfig(rawConfig);
|
|
68
|
+
}
|
|
69
|
+
return yield addConfigMetadata({
|
|
70
|
+
rawConfig,
|
|
71
|
+
customExtends,
|
|
72
|
+
configPath,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
64
76
|
exports.loadConfig = loadConfig;
|
|
77
|
+
;
|
|
65
78
|
exports.CONFIG_FILE_NAMES = ['redocly.yaml', 'redocly.yml', '.redocly.yaml', '.redocly.yml'];
|
|
66
79
|
function findConfig(dir) {
|
|
67
80
|
if (!fs.hasOwnProperty('existsSync'))
|
package/lib/config/rules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RuleSet, OasVersion } from '../oas-types';
|
|
2
2
|
import { LintConfig } from './config';
|
|
3
3
|
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: LintConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
|
|
4
|
-
severity: import("
|
|
4
|
+
severity: import("./types").RuleSeverity;
|
|
5
5
|
ruleId: string;
|
|
6
6
|
visitor: any;
|
|
7
7
|
}[];
|
package/lib/config/types.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ProblemSeverity } from '../walk';
|
|
2
2
|
import type { Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet, OasVersion } from '../oas-types';
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type RuleSeverity = ProblemSeverity | 'off';
|
|
5
|
+
export declare type PreprocessorSeverity = RuleSeverity | 'on';
|
|
6
|
+
export declare type RuleConfig = RuleSeverity | ({
|
|
5
7
|
severity?: ProblemSeverity;
|
|
6
8
|
} & Record<string, any>);
|
|
7
|
-
export declare type PreprocessorConfig =
|
|
9
|
+
export declare type PreprocessorConfig = PreprocessorSeverity | ({
|
|
8
10
|
severity?: ProblemSeverity;
|
|
9
11
|
} & Record<string, any>);
|
|
10
12
|
export declare type DecoratorConfig = PreprocessorConfig;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIfMatchByStrategy = exports.filter = void 0;
|
|
4
|
+
const ref_utils_1 = require("../../../ref-utils");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
function filter(node, ctx, criteria) {
|
|
7
|
+
const { parent, key } = ctx;
|
|
8
|
+
let didDelete = false;
|
|
9
|
+
if (Array.isArray(node)) {
|
|
10
|
+
for (let i = 0; i < node.length; i++) {
|
|
11
|
+
if (ref_utils_1.isRef(node[i])) {
|
|
12
|
+
const resolved = ctx.resolve(node[i]);
|
|
13
|
+
if (criteria(resolved.node)) {
|
|
14
|
+
node.splice(i, 1);
|
|
15
|
+
didDelete = true;
|
|
16
|
+
i--;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (criteria(node[i])) {
|
|
20
|
+
node.splice(i, 1);
|
|
21
|
+
didDelete = true;
|
|
22
|
+
i--;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (utils_1.isPlainObject(node)) {
|
|
27
|
+
for (const key of Object.keys(node)) {
|
|
28
|
+
node = node;
|
|
29
|
+
if (ref_utils_1.isRef(node[key])) {
|
|
30
|
+
const resolved = ctx.resolve(node[key]);
|
|
31
|
+
if (criteria(resolved.node)) {
|
|
32
|
+
delete node[key];
|
|
33
|
+
didDelete = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (criteria(node[key])) {
|
|
37
|
+
delete node[key];
|
|
38
|
+
didDelete = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (didDelete && (utils_1.isEmptyObject(node) || utils_1.isEmptyArray(node))) {
|
|
43
|
+
delete parent[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.filter = filter;
|
|
47
|
+
function checkIfMatchByStrategy(nodeValue, decoratorValue, strategy) {
|
|
48
|
+
if (!nodeValue || !decoratorValue) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(decoratorValue) && !Array.isArray(nodeValue)) {
|
|
52
|
+
return nodeValue === decoratorValue;
|
|
53
|
+
}
|
|
54
|
+
decoratorValue = toArrayIfNeeded(decoratorValue);
|
|
55
|
+
nodeValue = toArrayIfNeeded(nodeValue);
|
|
56
|
+
if (strategy === 'any') {
|
|
57
|
+
return decoratorValue.some((item) => nodeValue.includes(item));
|
|
58
|
+
}
|
|
59
|
+
if (strategy === 'all') {
|
|
60
|
+
return decoratorValue.every((item) => nodeValue.includes(item));
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
exports.checkIfMatchByStrategy = checkIfMatchByStrategy;
|
|
65
|
+
function toArrayIfNeeded(value) {
|
|
66
|
+
return Array.isArray(value) ? value : [value];
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterIn = void 0;
|
|
4
|
+
const filter_helper_1 = require("./filter-helper");
|
|
5
|
+
const DEFAULT_STRATEGY = 'any';
|
|
6
|
+
const FilterIn = ({ property, value, matchStrategy }) => {
|
|
7
|
+
const strategy = matchStrategy || DEFAULT_STRATEGY;
|
|
8
|
+
const filterInCriteria = (item) => (item === null || item === void 0 ? void 0 : item[property]) && !filter_helper_1.checkIfMatchByStrategy(item === null || item === void 0 ? void 0 : item[property], value, strategy);
|
|
9
|
+
return {
|
|
10
|
+
any: {
|
|
11
|
+
enter: (node, ctx) => {
|
|
12
|
+
filter_helper_1.filter(node, ctx, filterInCriteria);
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.FilterIn = FilterIn;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterOut = void 0;
|
|
4
|
+
const filter_helper_1 = require("./filter-helper");
|
|
5
|
+
const DEFAULT_STRATEGY = 'any';
|
|
6
|
+
const FilterOut = ({ property, value, matchStrategy }) => {
|
|
7
|
+
const strategy = matchStrategy || DEFAULT_STRATEGY;
|
|
8
|
+
const filterOutCriteria = (item) => filter_helper_1.checkIfMatchByStrategy(item === null || item === void 0 ? void 0 : item[property], value, strategy);
|
|
9
|
+
return {
|
|
10
|
+
any: {
|
|
11
|
+
enter: (node, ctx) => {
|
|
12
|
+
filter_helper_1.filter(node, ctx, filterOutCriteria);
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.FilterOut = FilterOut;
|
|
@@ -6,10 +6,14 @@ const operation_description_override_1 = require("../common/operation-descriptio
|
|
|
6
6
|
const tag_description_override_1 = require("../common/tag-description-override");
|
|
7
7
|
const info_description_override_1 = require("../common/info-description-override");
|
|
8
8
|
const remove_x_internal_1 = require("../common/remove-x-internal");
|
|
9
|
+
const filter_in_1 = require("../common/filters/filter-in");
|
|
10
|
+
const filter_out_1 = require("../common/filters/filter-out");
|
|
9
11
|
exports.decorators = {
|
|
10
12
|
'registry-dependencies': registry_dependencies_1.RegistryDependencies,
|
|
11
13
|
'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
|
|
12
14
|
'tag-description-override': tag_description_override_1.TagDescriptionOverride,
|
|
13
15
|
'info-description-override': info_description_override_1.InfoDescriptionOverride,
|
|
14
|
-
'remove-x-internal': remove_x_internal_1.RemoveXInternal
|
|
16
|
+
'remove-x-internal': remove_x_internal_1.RemoveXInternal,
|
|
17
|
+
'filter-in': filter_in_1.FilterIn,
|
|
18
|
+
'filter-out': filter_out_1.FilterOut,
|
|
15
19
|
};
|
|
@@ -6,10 +6,14 @@ const operation_description_override_1 = require("../common/operation-descriptio
|
|
|
6
6
|
const tag_description_override_1 = require("../common/tag-description-override");
|
|
7
7
|
const info_description_override_1 = require("../common/info-description-override");
|
|
8
8
|
const remove_x_internal_1 = require("../common/remove-x-internal");
|
|
9
|
+
const filter_in_1 = require("../common/filters/filter-in");
|
|
10
|
+
const filter_out_1 = require("../common/filters/filter-out");
|
|
9
11
|
exports.decorators = {
|
|
10
12
|
'registry-dependencies': registry_dependencies_1.RegistryDependencies,
|
|
11
13
|
'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
|
|
12
14
|
'tag-description-override': tag_description_override_1.TagDescriptionOverride,
|
|
13
15
|
'info-description-override': info_description_override_1.InfoDescriptionOverride,
|
|
14
|
-
'remove-x-internal': remove_x_internal_1.RemoveXInternal
|
|
16
|
+
'remove-x-internal': remove_x_internal_1.RemoveXInternal,
|
|
17
|
+
'filter-in': filter_in_1.FilterIn,
|
|
18
|
+
'filter-out': filter_out_1.FilterOut,
|
|
15
19
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { Oas2Definition } from './typings/swagger';
|
|
|
8
8
|
export { StatsAccumulator, StatsName } from './typings/common';
|
|
9
9
|
export { normalizeTypes } from './types';
|
|
10
10
|
export { Stats } from './rules/other/stats';
|
|
11
|
-
export { Config, LintConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, } from './config';
|
|
11
|
+
export { Config, LintConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity } from './config';
|
|
12
12
|
export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
|
|
13
13
|
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
14
14
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
package/lib/lint.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseResolver, Document } from './resolve';
|
|
2
2
|
import { NodeType } from './types';
|
|
3
|
+
import { ProblemSeverity } from './walk';
|
|
3
4
|
import { LintConfig, Config } from './config';
|
|
4
5
|
export declare function lint(opts: {
|
|
5
6
|
ref: string;
|
|
@@ -20,4 +21,5 @@ export declare function lintDocument(opts: {
|
|
|
20
21
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
|
21
22
|
export declare function lintConfig(opts: {
|
|
22
23
|
document: Document;
|
|
24
|
+
severity?: ProblemSeverity;
|
|
23
25
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
package/lib/lint.js
CHANGED
|
@@ -72,7 +72,7 @@ function lintDocument(opts) {
|
|
|
72
72
|
exports.lintDocument = lintDocument;
|
|
73
73
|
function lintConfig(opts) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
const { document } = opts;
|
|
75
|
+
const { document, severity } = opts;
|
|
76
76
|
const ctx = {
|
|
77
77
|
problems: [],
|
|
78
78
|
oasVersion: oas_types_1.OasVersion.Version3_0,
|
|
@@ -84,7 +84,7 @@ function lintConfig(opts) {
|
|
|
84
84
|
rules: { spec: 'error' },
|
|
85
85
|
});
|
|
86
86
|
const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
|
|
87
|
-
const rules = [{ severity: 'error', ruleId: 'spec', visitor: spec_1.OasSpec({ severity: 'error' }) }];
|
|
87
|
+
const rules = [{ severity: severity || 'error', ruleId: 'configuration spec', visitor: spec_1.OasSpec({ severity: 'error' }) }];
|
|
88
88
|
const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
|
|
89
89
|
walk_1.walkDocument({
|
|
90
90
|
document,
|
|
@@ -13,5 +13,5 @@ export declare class RegistryApi {
|
|
|
13
13
|
organizations: string[];
|
|
14
14
|
}>;
|
|
15
15
|
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>;
|
|
16
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }: RegistryApiTypes.PushApiParams): Promise<void>;
|
|
16
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }: RegistryApiTypes.PushApiParams): Promise<void>;
|
|
17
17
|
}
|
|
@@ -80,7 +80,7 @@ class RegistryApi {
|
|
|
80
80
|
throw new Error('Could not prepare file upload');
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }) {
|
|
83
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
85
|
const response = yield this.request(`/${organizationId}/${name}/${version}`, {
|
|
86
86
|
method: 'PUT',
|
|
@@ -94,6 +94,8 @@ class RegistryApi {
|
|
|
94
94
|
branch,
|
|
95
95
|
isUpsert,
|
|
96
96
|
isPublic,
|
|
97
|
+
batchId,
|
|
98
|
+
batchSize
|
|
97
99
|
}),
|
|
98
100
|
}, this.region);
|
|
99
101
|
if (response.ok) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { Location } from '../../../ref-utils';
|
|
2
|
+
declare type AssertResult = {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
location?: Location;
|
|
5
|
+
};
|
|
6
|
+
declare type Asserts = Record<string, (value: any, condition: any, baseLocation: Location, rawValue?: any) => AssertResult>;
|
|
2
7
|
export declare const runOnKeysSet: Set<string>;
|
|
3
8
|
export declare const runOnValuesSet: Set<string>;
|
|
4
9
|
export declare const asserts: Asserts;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.asserts = exports.runOnValuesSet = exports.runOnKeysSet = void 0;
|
|
4
|
-
const utils_1 = require("
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
5
6
|
exports.runOnKeysSet = new Set([
|
|
6
7
|
'mutuallyExclusive',
|
|
7
8
|
'mutuallyRequired',
|
|
@@ -13,6 +14,8 @@ exports.runOnKeysSet = new Set([
|
|
|
13
14
|
'sortOrder',
|
|
14
15
|
'disallowed',
|
|
15
16
|
'required',
|
|
17
|
+
'requireAny',
|
|
18
|
+
'ref',
|
|
16
19
|
]);
|
|
17
20
|
exports.runOnValuesSet = new Set([
|
|
18
21
|
'pattern',
|
|
@@ -24,78 +27,83 @@ exports.runOnValuesSet = new Set([
|
|
|
24
27
|
'maxLength',
|
|
25
28
|
'casing',
|
|
26
29
|
'sortOrder',
|
|
30
|
+
'ref',
|
|
27
31
|
]);
|
|
28
32
|
exports.asserts = {
|
|
29
|
-
pattern: (value, condition) => {
|
|
33
|
+
pattern: (value, condition, baseLocation) => {
|
|
30
34
|
if (typeof value === 'undefined')
|
|
31
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
32
|
-
const values =
|
|
33
|
-
const
|
|
34
|
-
condition = condition.slice(1).replace(regexOptions[0], '');
|
|
35
|
-
const regx = new RegExp(condition, regexOptions[0].slice(1));
|
|
35
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
36
|
+
const values = utils_1.isString(value) ? [value] : value;
|
|
37
|
+
const regx = utils_2.regexFromString(condition);
|
|
36
38
|
for (let _val of values) {
|
|
37
|
-
if (!
|
|
38
|
-
return false;
|
|
39
|
+
if (!(regx === null || regx === void 0 ? void 0 : regx.test(_val))) {
|
|
40
|
+
return { isValid: false, location: utils_1.isString(value) ? baseLocation : baseLocation.key() };
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
return true;
|
|
43
|
+
return { isValid: true };
|
|
42
44
|
},
|
|
43
|
-
enum: (value, condition) => {
|
|
45
|
+
enum: (value, condition, baseLocation) => {
|
|
44
46
|
if (typeof value === 'undefined')
|
|
45
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
46
|
-
const values =
|
|
47
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
48
|
+
const values = utils_1.isString(value) ? [value] : value;
|
|
47
49
|
for (let _val of values) {
|
|
48
50
|
if (!condition.includes(_val)) {
|
|
49
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
isValid: false,
|
|
53
|
+
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
54
|
+
};
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
return true;
|
|
57
|
+
return { isValid: true };
|
|
53
58
|
},
|
|
54
|
-
defined: (value, condition = true) => {
|
|
59
|
+
defined: (value, condition = true, baseLocation) => {
|
|
55
60
|
const isDefined = typeof value !== 'undefined';
|
|
56
|
-
return condition ? isDefined : !isDefined;
|
|
61
|
+
return { isValid: condition ? isDefined : !isDefined, location: baseLocation };
|
|
57
62
|
},
|
|
58
|
-
required: (value, keys) => {
|
|
63
|
+
required: (value, keys, baseLocation) => {
|
|
59
64
|
for (const requiredKey of keys) {
|
|
60
65
|
if (!value.includes(requiredKey)) {
|
|
61
|
-
return false;
|
|
66
|
+
return { isValid: false, location: baseLocation.key() };
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
|
-
return true;
|
|
69
|
+
return { isValid: true };
|
|
65
70
|
},
|
|
66
|
-
disallowed: (value, condition) => {
|
|
71
|
+
disallowed: (value, condition, baseLocation) => {
|
|
67
72
|
if (typeof value === 'undefined')
|
|
68
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
69
|
-
const values =
|
|
73
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
74
|
+
const values = utils_1.isString(value) ? [value] : value;
|
|
70
75
|
for (let _val of values) {
|
|
71
76
|
if (condition.includes(_val)) {
|
|
72
|
-
return
|
|
77
|
+
return {
|
|
78
|
+
isValid: false,
|
|
79
|
+
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
80
|
+
};
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
|
-
return true;
|
|
83
|
+
return { isValid: true };
|
|
76
84
|
},
|
|
77
|
-
undefined: (value, condition = true) => {
|
|
85
|
+
undefined: (value, condition = true, baseLocation) => {
|
|
78
86
|
const isUndefined = typeof value === 'undefined';
|
|
79
|
-
return condition ? isUndefined : !isUndefined;
|
|
87
|
+
return { isValid: condition ? isUndefined : !isUndefined, location: baseLocation };
|
|
80
88
|
},
|
|
81
|
-
nonEmpty: (value, condition = true) => {
|
|
89
|
+
nonEmpty: (value, condition = true, baseLocation) => {
|
|
82
90
|
const isEmpty = typeof value === 'undefined' || value === null || value === '';
|
|
83
|
-
return condition ? !isEmpty : isEmpty;
|
|
91
|
+
return { isValid: condition ? !isEmpty : isEmpty, location: baseLocation };
|
|
84
92
|
},
|
|
85
|
-
minLength: (value, condition) => {
|
|
93
|
+
minLength: (value, condition, baseLocation) => {
|
|
86
94
|
if (typeof value === 'undefined')
|
|
87
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
88
|
-
return value.length >= condition;
|
|
95
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
96
|
+
return { isValid: value.length >= condition, location: baseLocation };
|
|
89
97
|
},
|
|
90
|
-
maxLength: (value, condition) => {
|
|
98
|
+
maxLength: (value, condition, baseLocation) => {
|
|
91
99
|
if (typeof value === 'undefined')
|
|
92
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
93
|
-
return value.length <= condition;
|
|
100
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
101
|
+
return { isValid: value.length <= condition, location: baseLocation };
|
|
94
102
|
},
|
|
95
|
-
casing: (value, condition) => {
|
|
103
|
+
casing: (value, condition, baseLocation) => {
|
|
96
104
|
if (typeof value === 'undefined')
|
|
97
|
-
return true; // property doesn't exist, no need to lint it with this assert
|
|
98
|
-
const values =
|
|
105
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
106
|
+
const values = utils_1.isString(value) ? [value] : value;
|
|
99
107
|
for (let _val of values) {
|
|
100
108
|
let matchCase = false;
|
|
101
109
|
switch (condition) {
|
|
@@ -122,22 +130,47 @@ exports.asserts = {
|
|
|
122
130
|
break;
|
|
123
131
|
}
|
|
124
132
|
if (!matchCase) {
|
|
125
|
-
return
|
|
133
|
+
return {
|
|
134
|
+
isValid: false,
|
|
135
|
+
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
136
|
+
};
|
|
126
137
|
}
|
|
127
138
|
}
|
|
128
|
-
return true;
|
|
139
|
+
return { isValid: true };
|
|
129
140
|
},
|
|
130
|
-
sortOrder: (value, condition) => {
|
|
141
|
+
sortOrder: (value, condition, baseLocation) => {
|
|
131
142
|
if (typeof value === 'undefined')
|
|
132
|
-
return true;
|
|
133
|
-
return
|
|
143
|
+
return { isValid: true };
|
|
144
|
+
return { isValid: utils_2.isOrdered(value, condition), location: baseLocation };
|
|
134
145
|
},
|
|
135
|
-
mutuallyExclusive: (value, condition) => {
|
|
136
|
-
return
|
|
146
|
+
mutuallyExclusive: (value, condition, baseLocation) => {
|
|
147
|
+
return { isValid: utils_2.getIntersectionLength(value, condition) < 2, location: baseLocation.key() };
|
|
137
148
|
},
|
|
138
|
-
mutuallyRequired: (value, condition) => {
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
mutuallyRequired: (value, condition, baseLocation) => {
|
|
150
|
+
return {
|
|
151
|
+
isValid: utils_2.getIntersectionLength(value, condition) > 0
|
|
152
|
+
? utils_2.getIntersectionLength(value, condition) === condition.length
|
|
153
|
+
: true,
|
|
154
|
+
location: baseLocation.key(),
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
requireAny: (value, condition, baseLocation) => {
|
|
158
|
+
return { isValid: utils_2.getIntersectionLength(value, condition) >= 1, location: baseLocation.key() };
|
|
159
|
+
},
|
|
160
|
+
ref: (_value, condition, baseLocation, rawValue) => {
|
|
161
|
+
if (typeof rawValue === 'undefined')
|
|
162
|
+
return { isValid: true }; // property doesn't exist, no need to lint it with this assert
|
|
163
|
+
const hasRef = rawValue.hasOwnProperty('$ref');
|
|
164
|
+
if (typeof condition === 'boolean') {
|
|
165
|
+
return {
|
|
166
|
+
isValid: condition ? hasRef : !hasRef,
|
|
167
|
+
location: hasRef ? baseLocation : baseLocation.key(),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const regex = utils_2.regexFromString(condition);
|
|
171
|
+
return {
|
|
172
|
+
isValid: hasRef && (regex === null || regex === void 0 ? void 0 : regex.test(rawValue['$ref'])),
|
|
173
|
+
location: hasRef ? baseLocation : baseLocation.key(),
|
|
174
|
+
};
|
|
142
175
|
},
|
|
143
176
|
};
|
|
@@ -15,6 +15,7 @@ export declare type AssertToApply = {
|
|
|
15
15
|
runsOnValues: boolean;
|
|
16
16
|
};
|
|
17
17
|
export declare function buildVisitorObject(subject: string, context: Record<string, any>[], subjectVisitor: any): Record<string, any>;
|
|
18
|
-
export declare function buildSubjectVisitor(properties: string | string[], asserts: AssertToApply[], context?: Record<string, any>[]): (node: any, { report, location, key, type, resolve }: UserContext) => void;
|
|
18
|
+
export declare function buildSubjectVisitor(properties: string | string[], asserts: AssertToApply[], context?: Record<string, any>[]): (node: any, { report, location, rawLocation, key, type, resolve, rawNode }: UserContext) => void;
|
|
19
19
|
export declare function getIntersectionLength(keys: string[], properties: string[]): number;
|
|
20
20
|
export declare function isOrdered(value: any[], options: OrderOptions | OrderDirection): boolean;
|
|
21
|
+
export declare function regexFromString(input: string): RegExp | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOrdered = exports.getIntersectionLength = exports.buildSubjectVisitor = exports.buildVisitorObject = void 0;
|
|
3
|
+
exports.regexFromString = exports.isOrdered = exports.getIntersectionLength = exports.buildSubjectVisitor = exports.buildVisitorObject = void 0;
|
|
4
4
|
const ref_utils_1 = require("../../../ref-utils");
|
|
5
5
|
const asserts_1 = require("./asserts");
|
|
6
6
|
function buildVisitorObject(subject, context, subjectVisitor) {
|
|
@@ -45,7 +45,7 @@ function buildVisitorObject(subject, context, subjectVisitor) {
|
|
|
45
45
|
}
|
|
46
46
|
exports.buildVisitorObject = buildVisitorObject;
|
|
47
47
|
function buildSubjectVisitor(properties, asserts, context) {
|
|
48
|
-
return
|
|
48
|
+
return (node, { report, location, rawLocation, key, type, resolve, rawNode }) => {
|
|
49
49
|
var _a;
|
|
50
50
|
// We need to check context's last node if it has the same type as subject node;
|
|
51
51
|
// if yes - that means we didn't create context's last node visitor,
|
|
@@ -67,15 +67,29 @@ function buildSubjectVisitor(properties, asserts, context) {
|
|
|
67
67
|
properties = Array.isArray(properties) ? properties : [properties];
|
|
68
68
|
}
|
|
69
69
|
for (const assert of asserts) {
|
|
70
|
+
const currentLocation = assert.name === 'ref' ? rawLocation : location;
|
|
70
71
|
if (properties) {
|
|
71
72
|
for (const property of properties) {
|
|
72
73
|
// we can have resolvable scalar so need to resolve value here.
|
|
73
74
|
const value = ref_utils_1.isRef(node[property]) ? (_a = resolve(node[property])) === null || _a === void 0 ? void 0 : _a.node : node[property];
|
|
74
|
-
runAssertion(
|
|
75
|
+
runAssertion({
|
|
76
|
+
values: value,
|
|
77
|
+
rawValues: rawNode[property],
|
|
78
|
+
assert,
|
|
79
|
+
location: currentLocation.child(property),
|
|
80
|
+
report,
|
|
81
|
+
});
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
else {
|
|
78
|
-
|
|
85
|
+
const value = assert.name === 'ref' ? rawNode : Object.keys(node);
|
|
86
|
+
runAssertion({
|
|
87
|
+
values: Object.keys(node),
|
|
88
|
+
rawValues: value,
|
|
89
|
+
assert,
|
|
90
|
+
location: currentLocation,
|
|
91
|
+
report,
|
|
92
|
+
});
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
};
|
|
@@ -113,15 +127,20 @@ function isOrdered(value, options) {
|
|
|
113
127
|
return true;
|
|
114
128
|
}
|
|
115
129
|
exports.isOrdered = isOrdered;
|
|
116
|
-
function runAssertion(values, assert, location, report) {
|
|
117
|
-
const lintResult = asserts_1.asserts[assert.name](values, assert.conditions);
|
|
118
|
-
if (!lintResult) {
|
|
130
|
+
function runAssertion({ values, rawValues, assert, location, report }) {
|
|
131
|
+
const lintResult = asserts_1.asserts[assert.name](values, assert.conditions, location, rawValues);
|
|
132
|
+
if (!lintResult.isValid) {
|
|
119
133
|
report({
|
|
120
134
|
message: assert.message || `The ${assert.assertId} doesn't meet required conditions`,
|
|
121
|
-
location,
|
|
135
|
+
location: lintResult.location || location,
|
|
122
136
|
forceSeverity: assert.severity,
|
|
123
137
|
suggest: assert.suggest,
|
|
124
138
|
ruleId: assert.assertId,
|
|
125
139
|
});
|
|
126
140
|
}
|
|
127
141
|
}
|
|
142
|
+
function regexFromString(input) {
|
|
143
|
+
const matches = input.match(/^\/(.*)\/(.*)|(.*)/);
|
|
144
|
+
return matches && new RegExp(matches[1] || matches[3], matches[2]);
|
|
145
|
+
}
|
|
146
|
+
exports.regexFromString = regexFromString;
|