@redocly/openapi-core 1.3.0 → 1.4.0
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/CHANGELOG.md +6 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +4 -4
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +4 -4
- package/lib/benchmark/benches/recommended-oas3.bench.js +4 -4
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +3 -3
- package/lib/benchmark/utils.js +3 -3
- package/lib/bundle.d.ts +4 -4
- package/lib/bundle.js +23 -23
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +44 -8
- package/lib/config/builtIn.js +2 -0
- package/lib/config/config-resolvers.js +25 -25
- package/lib/config/config.js +9 -9
- package/lib/config/index.js +5 -1
- package/lib/config/load.d.ts +1 -1
- package/lib/config/load.js +6 -6
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +34 -3
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +92 -0
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +34 -3
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/types.d.ts +47 -46
- package/lib/config/types.js +2 -2
- package/lib/config/utils.js +26 -14
- package/lib/decorators/common/filters/filter-helper.js +4 -4
- package/lib/decorators/common/filters/filter-in.js +2 -2
- package/lib/decorators/common/filters/filter-out.js +2 -2
- package/lib/decorators/common/info-description-override.js +1 -1
- package/lib/decorators/common/media-type-examples-override.js +3 -3
- package/lib/decorators/common/operation-description-override.js +1 -1
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +4 -4
- package/lib/decorators/common/tag-description-override.js +1 -1
- package/lib/format/codeframes.d.ts +6 -6
- package/lib/format/format.d.ts +2 -2
- package/lib/format/format.js +12 -12
- package/lib/js-yaml/index.d.ts +2 -2
- package/lib/js-yaml/index.js +2 -2
- package/lib/lint.js +18 -18
- package/lib/oas-types.d.ts +12 -10
- package/lib/oas-types.js +2 -2
- package/lib/redocly/index.js +10 -10
- package/lib/redocly/registry-api.js +2 -2
- package/lib/resolve.d.ts +4 -4
- package/lib/resolve.js +18 -18
- package/lib/rules/ajv.js +1 -1
- package/lib/rules/async2/index.d.ts +2 -11
- package/lib/rules/common/assertions/asserts.d.ts +3 -3
- package/lib/rules/common/assertions/asserts.js +21 -21
- package/lib/rules/common/assertions/index.d.ts +4 -4
- package/lib/rules/common/assertions/index.js +3 -3
- package/lib/rules/common/assertions/utils.d.ts +4 -4
- package/lib/rules/common/assertions/utils.js +3 -3
- package/lib/rules/common/info-contact.js +1 -1
- package/lib/rules/common/info-license-url.js +1 -1
- package/lib/rules/common/info-license.js +1 -1
- package/lib/rules/common/no-enum-type-mismatch.js +3 -3
- package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- package/lib/rules/common/operation-2xx-response.js +2 -2
- package/lib/rules/common/operation-4xx-response.js +2 -2
- package/lib/rules/common/operation-description.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-summary.js +1 -1
- package/lib/rules/common/path-segment-plural.js +1 -1
- package/lib/rules/common/response-contains-header.js +2 -2
- package/lib/rules/common/spec-strict-refs.js +1 -1
- package/lib/rules/common/spec.js +11 -11
- package/lib/rules/common/tag-description.js +1 -1
- package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
- package/lib/rules/oas2/index.d.ts +2 -46
- package/lib/rules/oas2/remove-unused-components.js +1 -1
- package/lib/rules/oas2/request-mime-type.js +2 -2
- package/lib/rules/oas2/response-contains-property.js +2 -2
- package/lib/rules/oas2/response-mime-type.js +2 -2
- package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
- package/lib/rules/oas3/index.d.ts +1 -1
- package/lib/rules/oas3/index.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
- package/lib/rules/oas3/remove-unused-components.js +2 -2
- package/lib/rules/oas3/request-mime-type.js +3 -3
- package/lib/rules/oas3/response-contains-property.js +2 -2
- package/lib/rules/oas3/response-mime-type.js +3 -3
- package/lib/rules/utils.js +3 -3
- package/lib/types/asyncapi.js +21 -21
- package/lib/types/index.d.ts +8 -8
- package/lib/types/oas2.js +14 -14
- package/lib/types/oas3.js +27 -27
- package/lib/types/oas3_1.js +6 -6
- package/lib/types/redocly-yaml.d.ts +11 -0
- package/lib/types/redocly-yaml.js +71 -53
- package/lib/types/theme-config.js +1 -1
- package/lib/typings/common.d.ts +2 -2
- package/lib/typings/openapi.d.ts +6 -6
- package/lib/typings/swagger.d.ts +3 -3
- package/lib/utils.d.ts +5 -5
- package/lib/utils.js +3 -3
- package/lib/visitors.d.ts +40 -40
- package/lib/walk.d.ts +14 -15
- package/lib/walk.js +11 -11
- package/package.json +2 -2
- package/src/__tests__/lint.test.ts +40 -40
- package/src/__tests__/normalizeVisitors.test.ts +23 -5
- package/src/__tests__/ref-utils.test.ts +7 -7
- package/src/__tests__/resolve-http.test.ts +10 -10
- package/src/__tests__/resolve.test.ts +39 -39
- package/src/__tests__/walk.test.ts +48 -48
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
- package/src/config/__tests__/config-resolvers.test.ts +30 -1
- package/src/config/__tests__/config.test.ts +88 -88
- package/src/config/__tests__/load.test.ts +12 -8
- package/src/config/__tests__/utils.test.ts +18 -18
- package/src/config/all.ts +46 -9
- package/src/config/builtIn.ts +2 -0
- package/src/config/minimal.ts +36 -4
- package/src/config/recommended-strict.ts +93 -0
- package/src/config/recommended.ts +36 -4
- package/src/config/types.ts +22 -8
- package/src/config/utils.ts +15 -0
- package/src/decorators/common/media-type-examples-override.ts +2 -2
- package/src/lint.ts +3 -3
- package/src/oas-types.ts +26 -3
- package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
- package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
- package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
- package/src/rules/async2/index.ts +2 -1
- package/src/rules/common/__tests__/info-license.test.ts +6 -6
- package/src/rules/common/__tests__/license-url.test.ts +6 -6
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
- package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
- package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
- package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
- package/src/rules/common/__tests__/security-defined.test.ts +21 -21
- package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
- package/src/rules/common/__tests__/spec.test.ts +102 -102
- package/src/rules/common/__tests__/tag-description.test.ts +6 -6
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
- package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
- package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
- package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
- package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
- package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
- package/src/rules/oas2/index.ts +3 -1
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
- package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
- package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
- package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
- package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
- package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
- package/src/rules/oas3/index.ts +3 -3
- package/src/types/redocly-yaml.ts +75 -40
- package/src/visitors.ts +3 -3
- package/src/walk.ts +23 -10
- package/tsconfig.tsbuildinfo +1 -1
package/lib/lint.js
CHANGED
|
@@ -30,48 +30,48 @@ exports.lint = lint;
|
|
|
30
30
|
function lintFromString(opts) {
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
33
|
-
const document = resolve_1.makeDocumentFromString(source, absoluteRef || '/');
|
|
33
|
+
const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
|
|
34
34
|
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
exports.lintFromString = lintFromString;
|
|
38
38
|
function lintDocument(opts) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
ajv_1.releaseAjvInstance(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
|
|
40
|
+
(0, ajv_1.releaseAjvInstance)(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
|
|
41
41
|
const { document, customTypes, externalRefResolver, config } = opts;
|
|
42
|
-
const specVersion = oas_types_1.detectSpec(document.parsed);
|
|
43
|
-
const specMajorVersion = oas_types_1.getMajorSpecVersion(specVersion);
|
|
42
|
+
const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
|
|
43
|
+
const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
|
|
44
44
|
const rules = config.getRulesForOasVersion(specMajorVersion);
|
|
45
|
-
const types = types_1.normalizeTypes(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : oas_types_1.getTypes(specVersion), specVersion), config);
|
|
45
|
+
const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : (0, oas_types_1.getTypes)(specVersion), specVersion), config);
|
|
46
46
|
const ctx = {
|
|
47
47
|
problems: [],
|
|
48
48
|
oasVersion: specVersion,
|
|
49
49
|
visitorsData: {},
|
|
50
50
|
};
|
|
51
|
-
const preprocessors = config_1.initRules(rules, config, 'preprocessors', specVersion);
|
|
52
|
-
const regularRules = config_1.initRules(rules, config, 'rules', specVersion);
|
|
53
|
-
let resolvedRefMap = yield resolve_1.resolveDocument({
|
|
51
|
+
const preprocessors = (0, config_1.initRules)(rules, config, 'preprocessors', specVersion);
|
|
52
|
+
const regularRules = (0, config_1.initRules)(rules, config, 'rules', specVersion);
|
|
53
|
+
let resolvedRefMap = yield (0, resolve_1.resolveDocument)({
|
|
54
54
|
rootDocument: document,
|
|
55
55
|
rootType: types.Root,
|
|
56
56
|
externalRefResolver,
|
|
57
57
|
});
|
|
58
58
|
if (preprocessors.length > 0) {
|
|
59
59
|
// Make additional pass to resolve refs defined in preprocessors.
|
|
60
|
-
walk_1.walkDocument({
|
|
60
|
+
(0, walk_1.walkDocument)({
|
|
61
61
|
document,
|
|
62
62
|
rootType: types.Root,
|
|
63
|
-
normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
|
|
63
|
+
normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
|
|
64
64
|
resolvedRefMap,
|
|
65
65
|
ctx,
|
|
66
66
|
});
|
|
67
|
-
resolvedRefMap = yield resolve_1.resolveDocument({
|
|
67
|
+
resolvedRefMap = yield (0, resolve_1.resolveDocument)({
|
|
68
68
|
rootDocument: document,
|
|
69
69
|
rootType: types.Root,
|
|
70
70
|
externalRefResolver,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
|
|
74
|
-
walk_1.walkDocument({
|
|
73
|
+
const normalizedVisitors = (0, visitors_1.normalizeVisitors)(regularRules, types);
|
|
74
|
+
(0, walk_1.walkDocument)({
|
|
75
75
|
document,
|
|
76
76
|
rootType: types.Root,
|
|
77
77
|
normalizedVisitors,
|
|
@@ -90,22 +90,22 @@ function lintConfig(opts) {
|
|
|
90
90
|
oasVersion: oas_types_1.SpecVersion.OAS3_0,
|
|
91
91
|
visitorsData: {},
|
|
92
92
|
};
|
|
93
|
-
const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
|
|
93
|
+
const plugins = (0, config_1.resolvePlugins)([config_1.defaultPlugin]);
|
|
94
94
|
const config = new config_1.StyleguideConfig({
|
|
95
95
|
plugins,
|
|
96
96
|
rules: { spec: 'error' },
|
|
97
97
|
});
|
|
98
|
-
const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
|
|
98
|
+
const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes, config);
|
|
99
99
|
const rules = [
|
|
100
100
|
{
|
|
101
101
|
severity: severity || 'error',
|
|
102
102
|
ruleId: 'configuration spec',
|
|
103
|
-
visitor: spec_1.Spec({ severity: 'error' }),
|
|
103
|
+
visitor: (0, spec_1.Spec)({ severity: 'error' }),
|
|
104
104
|
},
|
|
105
105
|
];
|
|
106
106
|
// TODO: check why any is needed
|
|
107
|
-
const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
|
|
108
|
-
walk_1.walkDocument({
|
|
107
|
+
const normalizedVisitors = (0, visitors_1.normalizeVisitors)(rules, types);
|
|
108
|
+
(0, walk_1.walkDocument)({
|
|
109
109
|
document,
|
|
110
110
|
rootType: types.ConfigRoot,
|
|
111
111
|
normalizedVisitors,
|
package/lib/oas-types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule } from './visitors';
|
|
2
|
-
|
|
2
|
+
import { BuiltInAsync2RuleId, BuiltInCommonOASRuleId, BuiltInCommonRuleId, BuiltInOAS2RuleId, BuiltInOAS3RuleId } from './types/redocly-yaml';
|
|
3
|
+
export type RuleSet<T> = Record<string, T>;
|
|
3
4
|
export declare enum SpecVersion {
|
|
4
5
|
OAS2 = "oas2",
|
|
5
6
|
OAS3_0 = "oas3_0",
|
|
@@ -11,15 +12,16 @@ export declare enum SpecMajorVersion {
|
|
|
11
12
|
OAS3 = "oas3",
|
|
12
13
|
Async2 = "async2"
|
|
13
14
|
}
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
15
|
+
export type RuleMap<Key extends string, RuleConfig, T> = Record<T extends 'built-in' ? Key : string, RuleConfig>;
|
|
16
|
+
export type Oas3RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions', Oas3Rule, T>;
|
|
17
|
+
export type Oas2RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions', Oas2Rule, T>;
|
|
18
|
+
export type Async2RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInAsync2RuleId | 'assertions', Async2Rule, T>;
|
|
19
|
+
export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
|
|
20
|
+
export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
|
|
21
|
+
export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
|
|
22
|
+
export type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
|
|
23
|
+
export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
|
|
24
|
+
export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
|
|
23
25
|
export declare function detectSpec(root: any): SpecVersion;
|
|
24
26
|
export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
|
|
25
27
|
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType>;
|
package/lib/oas-types.js
CHANGED
|
@@ -11,13 +11,13 @@ var SpecVersion;
|
|
|
11
11
|
SpecVersion["OAS3_0"] = "oas3_0";
|
|
12
12
|
SpecVersion["OAS3_1"] = "oas3_1";
|
|
13
13
|
SpecVersion["Async2"] = "async2";
|
|
14
|
-
})(SpecVersion
|
|
14
|
+
})(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
|
|
15
15
|
var SpecMajorVersion;
|
|
16
16
|
(function (SpecMajorVersion) {
|
|
17
17
|
SpecMajorVersion["OAS2"] = "oas2";
|
|
18
18
|
SpecMajorVersion["OAS3"] = "oas3";
|
|
19
19
|
SpecMajorVersion["Async2"] = "async2";
|
|
20
|
-
})(SpecMajorVersion
|
|
20
|
+
})(SpecMajorVersion || (exports.SpecMajorVersion = SpecMajorVersion = {}));
|
|
21
21
|
const typesMap = {
|
|
22
22
|
[SpecVersion.OAS2]: oas2_1.Oas2Types,
|
|
23
23
|
[SpecVersion.OAS3_0]: oas3_1.Oas3Types,
|
package/lib/redocly/index.js
CHANGED
|
@@ -41,7 +41,7 @@ class RedoclyClient {
|
|
|
41
41
|
return this.region;
|
|
42
42
|
}
|
|
43
43
|
hasTokens() {
|
|
44
|
-
return utils_1.isNotEmptyObject(this.accessTokens);
|
|
44
|
+
return (0, utils_1.isNotEmptyObject)(this.accessTokens);
|
|
45
45
|
}
|
|
46
46
|
// <backward compatibility: old versions of portal>
|
|
47
47
|
hasToken() {
|
|
@@ -57,9 +57,9 @@ class RedoclyClient {
|
|
|
57
57
|
this.accessTokens = accessTokens;
|
|
58
58
|
}
|
|
59
59
|
loadTokens() {
|
|
60
|
-
const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
|
|
60
|
+
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
|
|
61
61
|
const credentials = this.readCredentialsFile(credentialsPath);
|
|
62
|
-
if (utils_1.isNotEmptyObject(credentials)) {
|
|
62
|
+
if ((0, utils_1.isNotEmptyObject)(credentials)) {
|
|
63
63
|
this.setAccessTokens(Object.assign(Object.assign({}, credentials), (credentials.token &&
|
|
64
64
|
!credentials[this.region] && {
|
|
65
65
|
[this.region]: credentials.token,
|
|
@@ -108,11 +108,11 @@ class RedoclyClient {
|
|
|
108
108
|
}
|
|
109
109
|
isAuthorizedWithRedocly() {
|
|
110
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
return this.hasTokens() && utils_1.isNotEmptyObject(yield this.getValidTokens());
|
|
111
|
+
return this.hasTokens() && (0, utils_1.isNotEmptyObject)(yield this.getValidTokens());
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
readCredentialsFile(credentialsPath) {
|
|
115
|
-
return fs_1.existsSync(credentialsPath) ? JSON.parse(fs_1.readFileSync(credentialsPath, 'utf-8')) : {};
|
|
115
|
+
return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
|
|
116
116
|
}
|
|
117
117
|
verifyToken(accessToken, region, verbose = false) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -121,7 +121,7 @@ class RedoclyClient {
|
|
|
121
121
|
}
|
|
122
122
|
login(accessToken, verbose = false) {
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
|
|
124
|
+
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
|
|
125
125
|
try {
|
|
126
126
|
yield this.verifyToken(accessToken, this.region, verbose);
|
|
127
127
|
}
|
|
@@ -131,13 +131,13 @@ class RedoclyClient {
|
|
|
131
131
|
const credentials = Object.assign(Object.assign({}, this.readCredentialsFile(credentialsPath)), { [this.region]: accessToken, token: accessToken });
|
|
132
132
|
this.accessTokens = credentials;
|
|
133
133
|
this.registryApi.setAccessTokens(credentials);
|
|
134
|
-
fs_1.writeFileSync(credentialsPath, JSON.stringify(credentials, null, 2));
|
|
134
|
+
(0, fs_1.writeFileSync)(credentialsPath, JSON.stringify(credentials, null, 2));
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
logout() {
|
|
138
|
-
const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
|
|
139
|
-
if (fs_1.existsSync(credentialsPath)) {
|
|
140
|
-
fs_1.unlinkSync(credentialsPath);
|
|
138
|
+
const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
|
|
139
|
+
if ((0, fs_1.existsSync)(credentialsPath)) {
|
|
140
|
+
(0, fs_1.unlinkSync)(credentialsPath);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -20,7 +20,7 @@ class RegistryApi {
|
|
|
20
20
|
this.region = region;
|
|
21
21
|
}
|
|
22
22
|
get accessToken() {
|
|
23
|
-
return utils_1.isNotEmptyObject(this.accessTokens) && this.accessTokens[this.region];
|
|
23
|
+
return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
|
|
24
24
|
}
|
|
25
25
|
getBaseUrl(region = config_1.DEFAULT_REGION) {
|
|
26
26
|
return `https://api.${config_1.DOMAINS[region]}/registry`;
|
|
@@ -41,7 +41,7 @@ class RegistryApi {
|
|
|
41
41
|
if (!headers.hasOwnProperty('authorization')) {
|
|
42
42
|
throw new Error('Unauthorized');
|
|
43
43
|
}
|
|
44
|
-
const response = yield node_fetch_1.default(`${this.getBaseUrl(region)}${path}`, Object.assign({}, options, { headers }));
|
|
44
|
+
const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl(region)}${path}`, Object.assign({}, options, { headers }));
|
|
45
45
|
if (response.status === 401) {
|
|
46
46
|
throw new Error('Unauthorized');
|
|
47
47
|
}
|
package/lib/resolve.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { YAMLNode, LoadOptions } from 'yaml-ast-parser';
|
|
2
2
|
import { NormalizedNodeType } from './types';
|
|
3
3
|
import { ResolveConfig } from './config/types';
|
|
4
|
-
export
|
|
4
|
+
export type CollectedRefs = Map<string, Document>;
|
|
5
5
|
export declare class Source {
|
|
6
6
|
absoluteRef: string;
|
|
7
7
|
body: string;
|
|
@@ -23,7 +23,7 @@ export declare class YamlParseError extends Error {
|
|
|
23
23
|
line: number;
|
|
24
24
|
constructor(originalError: Error, source: Source);
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type Document = {
|
|
27
27
|
source: Source;
|
|
28
28
|
parsed: any;
|
|
29
29
|
};
|
|
@@ -42,7 +42,7 @@ export declare class BaseResolver {
|
|
|
42
42
|
parseDocument(source: Source, isRoot?: boolean): Document;
|
|
43
43
|
resolveDocument(base: string | null, ref: string, isRoot?: boolean): Promise<Document | ResolveError | YamlParseError>;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type ResolvedRef = {
|
|
46
46
|
resolved: false;
|
|
47
47
|
isRemote: boolean;
|
|
48
48
|
nodePointer?: string;
|
|
@@ -58,7 +58,7 @@ export declare type ResolvedRef = {
|
|
|
58
58
|
isRemote: boolean;
|
|
59
59
|
error?: undefined;
|
|
60
60
|
};
|
|
61
|
-
export
|
|
61
|
+
export type ResolvedRefMap = Map<string, ResolvedRef>;
|
|
62
62
|
export declare function resolveDocument(opts: {
|
|
63
63
|
rootDocument: Document;
|
|
64
64
|
externalRefResolver: BaseResolver;
|
package/lib/resolve.js
CHANGED
|
@@ -77,7 +77,7 @@ function makeDocumentFromString(sourceString, absoluteRef) {
|
|
|
77
77
|
try {
|
|
78
78
|
return {
|
|
79
79
|
source,
|
|
80
|
-
parsed: utils_1.parseYaml(sourceString, { filename: absoluteRef }),
|
|
80
|
+
parsed: (0, utils_1.parseYaml)(sourceString, { filename: absoluteRef }),
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
catch (e) {
|
|
@@ -94,10 +94,10 @@ class BaseResolver {
|
|
|
94
94
|
return new Set(Array.from(this.cache.keys()));
|
|
95
95
|
}
|
|
96
96
|
resolveExternalRef(base, ref) {
|
|
97
|
-
if (ref_utils_1.isAbsoluteUrl(ref)) {
|
|
97
|
+
if ((0, ref_utils_1.isAbsoluteUrl)(ref)) {
|
|
98
98
|
return ref;
|
|
99
99
|
}
|
|
100
|
-
if (base && ref_utils_1.isAbsoluteUrl(base)) {
|
|
100
|
+
if (base && (0, ref_utils_1.isAbsoluteUrl)(base)) {
|
|
101
101
|
return new URL(ref, base).href;
|
|
102
102
|
}
|
|
103
103
|
return path.resolve(base ? path.dirname(base) : process.cwd(), ref);
|
|
@@ -105,8 +105,8 @@ class BaseResolver {
|
|
|
105
105
|
loadExternalRef(absoluteRef) {
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
try {
|
|
108
|
-
if (ref_utils_1.isAbsoluteUrl(absoluteRef)) {
|
|
109
|
-
const { body, mimeType } = yield utils_1.readFileFromUrl(absoluteRef, this.config.http);
|
|
108
|
+
if ((0, ref_utils_1.isAbsoluteUrl)(absoluteRef)) {
|
|
109
|
+
const { body, mimeType } = yield (0, utils_1.readFileFromUrl)(absoluteRef, this.config.http);
|
|
110
110
|
return new Source(absoluteRef, body, mimeType);
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
@@ -136,7 +136,7 @@ class BaseResolver {
|
|
|
136
136
|
try {
|
|
137
137
|
return {
|
|
138
138
|
source,
|
|
139
|
-
parsed: utils_1.parseYaml(source.body, { filename: source.absoluteRef }),
|
|
139
|
+
parsed: (0, utils_1.parseYaml)(source.body, { filename: source.absoluteRef }),
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
catch (e) {
|
|
@@ -212,7 +212,7 @@ function resolveDocument(opts) {
|
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
214
|
for (let i = 0; i < node.length; i++) {
|
|
215
|
-
walk(node[i], itemsType || unknownType, ref_utils_1.joinPointer(nodeAbsoluteRef, i));
|
|
215
|
+
walk(node[i], itemsType || unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
|
|
216
216
|
}
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
@@ -230,19 +230,19 @@ function resolveDocument(opts) {
|
|
|
230
230
|
propType === unknownType) {
|
|
231
231
|
propType = types_1.SpecExtension;
|
|
232
232
|
}
|
|
233
|
-
if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
|
|
233
|
+
if (!(0, types_1.isNamedType)(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
|
|
234
234
|
propType = propType.directResolveAs;
|
|
235
235
|
propValue = { $ref: propValue };
|
|
236
236
|
}
|
|
237
237
|
if (propType && propType.name === undefined && propType.resolvable !== false) {
|
|
238
238
|
propType = resolvableScalarType;
|
|
239
239
|
}
|
|
240
|
-
if (!types_1.isNamedType(propType) || typeof propValue !== 'object') {
|
|
240
|
+
if (!(0, types_1.isNamedType)(propType) || typeof propValue !== 'object') {
|
|
241
241
|
continue;
|
|
242
242
|
}
|
|
243
|
-
walk(propValue, propType, ref_utils_1.joinPointer(nodeAbsoluteRef, ref_utils_1.escapePointer(propName)));
|
|
243
|
+
walk(propValue, propType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, (0, ref_utils_1.escapePointer)(propName)));
|
|
244
244
|
}
|
|
245
|
-
if (ref_utils_1.isRef(node)) {
|
|
245
|
+
if ((0, ref_utils_1.isRef)(node)) {
|
|
246
246
|
const promise = followRef(rootNodeDocument, node, {
|
|
247
247
|
prev: null,
|
|
248
248
|
node,
|
|
@@ -259,9 +259,9 @@ function resolveDocument(opts) {
|
|
|
259
259
|
if (hasRef(refStack.prev, ref)) {
|
|
260
260
|
throw new Error('Self-referencing circular pointer');
|
|
261
261
|
}
|
|
262
|
-
if (ref_utils_1.isAnchor(ref.$ref)) {
|
|
262
|
+
if ((0, ref_utils_1.isAnchor)(ref.$ref)) {
|
|
263
263
|
// Wait for all anchors in the document to be collected firstly.
|
|
264
|
-
yield utils_1.nextTick();
|
|
264
|
+
yield (0, utils_1.nextTick)();
|
|
265
265
|
const resolvedRef = {
|
|
266
266
|
resolved: true,
|
|
267
267
|
isRemote: false,
|
|
@@ -273,7 +273,7 @@ function resolveDocument(opts) {
|
|
|
273
273
|
resolvedRefMap.set(refId, resolvedRef);
|
|
274
274
|
return resolvedRef;
|
|
275
275
|
}
|
|
276
|
-
const { uri, pointer } = ref_utils_1.parseRef(ref.$ref);
|
|
276
|
+
const { uri, pointer } = (0, ref_utils_1.parseRef)(ref.$ref);
|
|
277
277
|
const isRemote = uri !== null;
|
|
278
278
|
let targetDoc;
|
|
279
279
|
try {
|
|
@@ -308,9 +308,9 @@ function resolveDocument(opts) {
|
|
|
308
308
|
}
|
|
309
309
|
else if (target[segment] !== undefined) {
|
|
310
310
|
target = target[segment];
|
|
311
|
-
resolvedRef.nodePointer = ref_utils_1.joinPointer(resolvedRef.nodePointer, ref_utils_1.escapePointer(segment));
|
|
311
|
+
resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
|
|
312
312
|
}
|
|
313
|
-
else if (ref_utils_1.isRef(target)) {
|
|
313
|
+
else if ((0, ref_utils_1.isRef)(target)) {
|
|
314
314
|
resolvedRef = yield followRef(targetDoc, target, pushRef(refStack, target));
|
|
315
315
|
targetDoc = resolvedRef.document || targetDoc;
|
|
316
316
|
if (typeof resolvedRef.node !== 'object') {
|
|
@@ -318,7 +318,7 @@ function resolveDocument(opts) {
|
|
|
318
318
|
break;
|
|
319
319
|
}
|
|
320
320
|
target = resolvedRef.node[segment];
|
|
321
|
-
resolvedRef.nodePointer = ref_utils_1.joinPointer(resolvedRef.nodePointer, ref_utils_1.escapePointer(segment));
|
|
321
|
+
resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
|
|
322
322
|
}
|
|
323
323
|
else {
|
|
324
324
|
target = undefined;
|
|
@@ -328,7 +328,7 @@ function resolveDocument(opts) {
|
|
|
328
328
|
resolvedRef.node = target;
|
|
329
329
|
resolvedRef.document = targetDoc;
|
|
330
330
|
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
331
|
-
if (resolvedRef.document && ref_utils_1.isRef(target)) {
|
|
331
|
+
if (resolvedRef.document && (0, ref_utils_1.isRef)(target)) {
|
|
332
332
|
resolvedRef = yield followRef(resolvedRef.document, target, pushRef(refStack, target));
|
|
333
333
|
}
|
|
334
334
|
resolvedRefMap.set(refId, resolvedRef);
|
package/lib/rules/ajv.js
CHANGED
|
@@ -71,7 +71,7 @@ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allo
|
|
|
71
71
|
if (error.keyword === 'additionalProperties' || error.keyword === 'unevaluatedProperties') {
|
|
72
72
|
const property = error.params.additionalProperty || error.params.unevaluatedProperty;
|
|
73
73
|
message = `${message} \`${property}\``;
|
|
74
|
-
error.instancePath += '/' + ref_utils_1.escapePointer(property);
|
|
74
|
+
error.instancePath += '/' + (0, ref_utils_1.escapePointer)(property);
|
|
75
75
|
}
|
|
76
76
|
return Object.assign(Object.assign({}, error), { message,
|
|
77
77
|
suggest });
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const rules:
|
|
3
|
-
spec: Async2Rule;
|
|
4
|
-
assertions: (opts: Record<string, import("../common/assertions").Assertion>) => (import("../../visitors").Oas3Visitor | import("../../visitors").Oas2Visitor)[];
|
|
5
|
-
'info-contact': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
|
|
6
|
-
'operation-operationId': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
|
|
7
|
-
'channels-kebab-case': Async2Rule;
|
|
8
|
-
'no-channel-trailing-slash': Async2Rule;
|
|
9
|
-
'tag-description': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
|
|
10
|
-
'tags-alphabetical': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
|
|
11
|
-
};
|
|
1
|
+
import type { Async2RuleSet } from '../../oas-types';
|
|
2
|
+
export declare const rules: Async2RuleSet<'built-in'>;
|
|
12
3
|
export declare const preprocessors: {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AssertionContext, AssertResult, CustomFunction } from 'core/src/config/types';
|
|
2
2
|
import { Location } from '../../../ref-utils';
|
|
3
|
-
export
|
|
3
|
+
export type AssertionFnContext = AssertionContext & {
|
|
4
4
|
baseLocation: Location;
|
|
5
5
|
rawValue?: any;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export
|
|
7
|
+
export type AssertionFn = (value: any, condition: any, ctx: AssertionFnContext) => AssertResult[];
|
|
8
|
+
export type Asserts = {
|
|
9
9
|
pattern: AssertionFn;
|
|
10
10
|
notPattern: AssertionFn;
|
|
11
11
|
enum: AssertionFn;
|
|
@@ -36,45 +36,45 @@ exports.runOnValuesSet = new Set([
|
|
|
36
36
|
]);
|
|
37
37
|
exports.asserts = {
|
|
38
38
|
pattern: (value, condition, { baseLocation, rawValue }) => {
|
|
39
|
-
if (typeof value === 'undefined' || utils_1.isPlainObject(value))
|
|
39
|
+
if (typeof value === 'undefined' || (0, utils_1.isPlainObject)(value))
|
|
40
40
|
return []; // property doesn't exist or is an object, no need to lint it with this assert
|
|
41
41
|
const values = Array.isArray(value) ? value : [value];
|
|
42
|
-
const regex = utils_2.regexFromString(condition);
|
|
42
|
+
const regex = (0, utils_2.regexFromString)(condition);
|
|
43
43
|
return values
|
|
44
44
|
.map((_val) => !(regex === null || regex === void 0 ? void 0 : regex.test(_val)) && {
|
|
45
45
|
message: `"${_val}" should match a regex ${condition}`,
|
|
46
|
-
location: utils_1.isString(value)
|
|
46
|
+
location: (0, utils_1.isString)(value)
|
|
47
47
|
? baseLocation
|
|
48
|
-
: utils_1.isPlainObject(rawValue)
|
|
48
|
+
: (0, utils_1.isPlainObject)(rawValue)
|
|
49
49
|
? baseLocation.child(_val).key()
|
|
50
50
|
: baseLocation.key(),
|
|
51
51
|
})
|
|
52
52
|
.filter(utils_1.isTruthy);
|
|
53
53
|
},
|
|
54
54
|
notPattern: (value, condition, { baseLocation, rawValue }) => {
|
|
55
|
-
if (typeof value === 'undefined' || utils_1.isPlainObject(value))
|
|
55
|
+
if (typeof value === 'undefined' || (0, utils_1.isPlainObject)(value))
|
|
56
56
|
return []; // property doesn't exist or is an object, no need to lint it with this assert
|
|
57
57
|
const values = Array.isArray(value) ? value : [value];
|
|
58
|
-
const regex = utils_2.regexFromString(condition);
|
|
58
|
+
const regex = (0, utils_2.regexFromString)(condition);
|
|
59
59
|
return values
|
|
60
60
|
.map((_val) => (regex === null || regex === void 0 ? void 0 : regex.test(_val)) && {
|
|
61
61
|
message: `"${_val}" should not match a regex ${condition}`,
|
|
62
|
-
location: utils_1.isString(value)
|
|
62
|
+
location: (0, utils_1.isString)(value)
|
|
63
63
|
? baseLocation
|
|
64
|
-
: utils_1.isPlainObject(rawValue)
|
|
64
|
+
: (0, utils_1.isPlainObject)(rawValue)
|
|
65
65
|
? baseLocation.child(_val).key()
|
|
66
66
|
: baseLocation.key(),
|
|
67
67
|
})
|
|
68
68
|
.filter(utils_1.isTruthy);
|
|
69
69
|
},
|
|
70
70
|
enum: (value, condition, { baseLocation }) => {
|
|
71
|
-
if (typeof value === 'undefined' || utils_1.isPlainObject(value))
|
|
71
|
+
if (typeof value === 'undefined' || (0, utils_1.isPlainObject)(value))
|
|
72
72
|
return []; // property doesn't exist or is an object, no need to lint it with this assert
|
|
73
73
|
const values = Array.isArray(value) ? value : [value];
|
|
74
74
|
return values
|
|
75
75
|
.map((_val) => !condition.includes(_val) && {
|
|
76
76
|
message: `"${_val}" should be one of the predefined values`,
|
|
77
|
-
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
77
|
+
location: (0, utils_1.isString)(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
78
78
|
})
|
|
79
79
|
.filter(utils_1.isTruthy);
|
|
80
80
|
},
|
|
@@ -99,13 +99,13 @@ exports.asserts = {
|
|
|
99
99
|
.filter(utils_1.isTruthy);
|
|
100
100
|
},
|
|
101
101
|
disallowed: (value, condition, { baseLocation }) => {
|
|
102
|
-
if (typeof value === 'undefined' || utils_1.isPlainObject(value))
|
|
102
|
+
if (typeof value === 'undefined' || (0, utils_1.isPlainObject)(value))
|
|
103
103
|
return []; // property doesn't exist or is an object, no need to lint it with this assert
|
|
104
104
|
const values = Array.isArray(value) ? value : [value];
|
|
105
105
|
return values
|
|
106
106
|
.map((_val) => condition.includes(_val) && {
|
|
107
107
|
message: `"${_val}" is disallowed`,
|
|
108
|
-
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
108
|
+
location: (0, utils_1.isString)(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
109
109
|
})
|
|
110
110
|
.filter(utils_1.isTruthy);
|
|
111
111
|
},
|
|
@@ -116,7 +116,7 @@ exports.asserts = {
|
|
|
116
116
|
return value
|
|
117
117
|
.map((_val) => condition !== _val && {
|
|
118
118
|
message: `"${_val}" should be equal ${condition} `,
|
|
119
|
-
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
119
|
+
location: (0, utils_1.isString)(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
120
120
|
})
|
|
121
121
|
.filter(utils_1.isTruthy);
|
|
122
122
|
}
|
|
@@ -176,7 +176,7 @@ exports.asserts = {
|
|
|
176
176
|
];
|
|
177
177
|
},
|
|
178
178
|
casing: (value, condition, { baseLocation }) => {
|
|
179
|
-
if (typeof value === 'undefined' || utils_1.isPlainObject(value))
|
|
179
|
+
if (typeof value === 'undefined' || (0, utils_1.isPlainObject)(value))
|
|
180
180
|
return []; // property doesn't exist or is an object, no need to lint it with this assert
|
|
181
181
|
const values = Array.isArray(value) ? value : [value];
|
|
182
182
|
const casingRegexes = {
|
|
@@ -191,7 +191,7 @@ exports.asserts = {
|
|
|
191
191
|
return values
|
|
192
192
|
.map((_val) => !_val.match(casingRegexes[condition]) && {
|
|
193
193
|
message: `"${_val}" should use ${condition}`,
|
|
194
|
-
location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
194
|
+
location: (0, utils_1.isString)(value) ? baseLocation : baseLocation.child(_val).key(),
|
|
195
195
|
})
|
|
196
196
|
.filter(utils_1.isTruthy);
|
|
197
197
|
},
|
|
@@ -206,7 +206,7 @@ exports.asserts = {
|
|
|
206
206
|
},
|
|
207
207
|
];
|
|
208
208
|
}
|
|
209
|
-
if (typeof value === 'undefined' || utils_2.isOrdered(value, condition))
|
|
209
|
+
if (typeof value === 'undefined' || (0, utils_2.isOrdered)(value, condition))
|
|
210
210
|
return [];
|
|
211
211
|
return [
|
|
212
212
|
{
|
|
@@ -216,7 +216,7 @@ exports.asserts = {
|
|
|
216
216
|
];
|
|
217
217
|
},
|
|
218
218
|
mutuallyExclusive: (value, condition, { baseLocation }) => {
|
|
219
|
-
if (utils_2.getIntersectionLength(value, condition) < 2)
|
|
219
|
+
if ((0, utils_2.getIntersectionLength)(value, condition) < 2)
|
|
220
220
|
return [];
|
|
221
221
|
return [
|
|
222
222
|
{
|
|
@@ -226,8 +226,8 @@ exports.asserts = {
|
|
|
226
226
|
];
|
|
227
227
|
},
|
|
228
228
|
mutuallyRequired: (value, condition, { baseLocation }) => {
|
|
229
|
-
const isValid = utils_2.getIntersectionLength(value, condition) > 0
|
|
230
|
-
? utils_2.getIntersectionLength(value, condition) === condition.length
|
|
229
|
+
const isValid = (0, utils_2.getIntersectionLength)(value, condition) > 0
|
|
230
|
+
? (0, utils_2.getIntersectionLength)(value, condition) === condition.length
|
|
231
231
|
: true;
|
|
232
232
|
return isValid
|
|
233
233
|
? []
|
|
@@ -239,7 +239,7 @@ exports.asserts = {
|
|
|
239
239
|
];
|
|
240
240
|
},
|
|
241
241
|
requireAny: (value, condition, { baseLocation }) => {
|
|
242
|
-
return utils_2.getIntersectionLength(value, condition) >= 1
|
|
242
|
+
return (0, utils_2.getIntersectionLength)(value, condition) >= 1
|
|
243
243
|
? []
|
|
244
244
|
: [
|
|
245
245
|
{
|
|
@@ -263,7 +263,7 @@ exports.asserts = {
|
|
|
263
263
|
},
|
|
264
264
|
];
|
|
265
265
|
}
|
|
266
|
-
const regex = utils_2.regexFromString(condition);
|
|
266
|
+
const regex = (0, utils_2.regexFromString)(condition);
|
|
267
267
|
const isValid = hasRef && (regex === null || regex === void 0 ? void 0 : regex.test(rawValue['$ref']));
|
|
268
268
|
return isValid
|
|
269
269
|
? []
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { asserts, AssertionFn } from './asserts';
|
|
2
2
|
import { Oas2Visitor, Oas3Visitor } from '../../../visitors';
|
|
3
3
|
import { RuleSeverity } from '../../../config';
|
|
4
|
-
export
|
|
4
|
+
export type AssertionLocators = {
|
|
5
5
|
filterInParentKeys?: (string | number)[];
|
|
6
6
|
filterOutParentKeys?: (string | number)[];
|
|
7
7
|
matchParentKeys?: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type AssertionDefinition = {
|
|
10
10
|
subject: {
|
|
11
11
|
type: string;
|
|
12
12
|
property?: string | string[];
|
|
@@ -15,13 +15,13 @@ export declare type AssertionDefinition = {
|
|
|
15
15
|
[name in keyof typeof asserts]?: AssertionFn;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type RawAssertion = AssertionDefinition & {
|
|
19
19
|
where?: AssertionDefinition[];
|
|
20
20
|
message?: string;
|
|
21
21
|
suggest?: string[];
|
|
22
22
|
severity?: RuleSeverity;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type Assertion = RawAssertion & {
|
|
25
25
|
assertionId: string;
|
|
26
26
|
};
|
|
27
27
|
export declare const Assertions: (opts: Record<string, Assertion>) => (Oas3Visitor | Oas2Visitor)[];
|
|
@@ -12,11 +12,11 @@ const Assertions = (opts) => {
|
|
|
12
12
|
// before - filter only object 'opts' values
|
|
13
13
|
const assertions = Object.values(opts).filter((opt) => typeof opt === 'object' && opt !== null);
|
|
14
14
|
for (const [_, assertion] of assertions.entries()) {
|
|
15
|
-
if (!utils_2.isString(assertion.subject.type)) {
|
|
15
|
+
if (!(0, utils_2.isString)(assertion.subject.type)) {
|
|
16
16
|
throw new Error(`${assertion.assertionId}: 'type' (String) is required`);
|
|
17
17
|
}
|
|
18
|
-
const subjectVisitor = utils_1.buildSubjectVisitor(assertion.assertionId, assertion);
|
|
19
|
-
const visitorObject = utils_1.buildVisitorObject(assertion, subjectVisitor);
|
|
18
|
+
const subjectVisitor = (0, utils_1.buildSubjectVisitor)(assertion.assertionId, assertion);
|
|
19
|
+
const visitorObject = (0, utils_1.buildVisitorObject)(assertion, subjectVisitor);
|
|
20
20
|
visitors.push(visitorObject);
|
|
21
21
|
}
|
|
22
22
|
return visitors;
|
|
@@ -2,18 +2,18 @@ import { Asserts } from './asserts';
|
|
|
2
2
|
import type { AssertionContext, AssertResult } from '../../../config';
|
|
3
3
|
import type { Assertion, AssertionDefinition } from '.';
|
|
4
4
|
import type { Oas2Visitor, Oas3Visitor, VisitFunction } from '../../../visitors';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type OrderDirection = 'asc' | 'desc';
|
|
6
|
+
export type OrderOptions = {
|
|
7
7
|
direction: OrderDirection;
|
|
8
8
|
property: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type AssertToApply = {
|
|
11
11
|
name: keyof Asserts;
|
|
12
12
|
conditions: any;
|
|
13
13
|
runsOnKeys: boolean;
|
|
14
14
|
runsOnValues: boolean;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
type RunAssertionParams = {
|
|
17
17
|
ctx: AssertionContext;
|
|
18
18
|
assert: AssertToApply;
|
|
19
19
|
assertionProperty?: string;
|