@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108
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/README.md +4 -4
- package/__tests__/utils.ts +5 -5
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +7 -4
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +3 -3
- package/lib/config/builtIn.d.ts +2 -2
- package/lib/config/builtIn.js +2 -2
- package/lib/config/config-resolvers.d.ts +5 -5
- package/lib/config/config-resolvers.js +70 -49
- package/lib/config/config.d.ts +8 -10
- package/lib/config/config.js +10 -7
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +18 -10
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +5 -4
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +5 -4
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +23 -19
- package/lib/config/utils.d.ts +5 -5
- package/lib/config/utils.js +48 -31
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.js +29 -27
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +4 -3
- package/lib/redocly/registry-api.js +9 -4
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/info-license-url.d.ts +1 -1
- package/lib/rules/common/info-license-url.js +5 -10
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- 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-operationId.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +3 -3
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +5 -5
- package/lib/rules/oas3/index.js +6 -6
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/remove-unused-components.js +5 -5
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +20 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -8
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +22 -5
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -2
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
- package/src/__tests__/bundle.test.ts +68 -34
- package/src/__tests__/codeframes.test.ts +13 -14
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +74 -6
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/ref-utils.test.ts +13 -13
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +14 -11
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +48 -56
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
- package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/benchmark/benchmark.js +9 -5
- package/src/benchmark/utils.ts +5 -5
- package/src/bundle.ts +24 -20
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +111 -76
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
- package/src/config/__tests__/load.test.ts +79 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +5 -6
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +161 -96
- package/src/config/config.ts +15 -13
- package/src/config/load.ts +34 -11
- package/src/config/minimal.ts +7 -6
- package/src/config/recommended.ts +7 -6
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +78 -57
- package/src/decorators/__tests__/filter-out.test.ts +8 -4
- package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
- package/src/decorators/common/filters/filter-helper.ts +1 -1
- package/src/decorators/common/info-description-override.ts +1 -1
- package/src/decorators/common/operation-description-override.ts +1 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/decorators/common/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +18 -12
- package/src/format/format.ts +37 -42
- package/src/index.ts +8 -7
- package/src/js-yaml/index.ts +4 -8
- package/src/lint.ts +22 -18
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +1 -6
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +12 -7
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +22 -12
- package/src/ref-utils.ts +4 -3
- package/src/resolve.ts +11 -8
- package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.ts +7 -8
- package/src/rules/common/__tests__/info-description.test.ts +3 -3
- package/src/rules/common/__tests__/info-license.test.ts +2 -2
- package/src/rules/common/__tests__/license-url.test.ts +2 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
- package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
- package/src/rules/common/__tests__/spec.test.ts +2 -2
- package/src/rules/common/__tests__/tag-description.test.ts +2 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
- package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +7 -7
- package/src/rules/common/info-license-url.ts +4 -9
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-enum-type-mismatch.ts +12 -9
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-parameters-unique.ts +2 -2
- package/src/rules/common/operation-security-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/path-params-defined.ts +1 -1
- package/src/rules/common/paths-kebab-case.ts +4 -1
- package/src/rules/common/scalar-property-missing-example.ts +1 -1
- package/src/rules/common/spec.ts +12 -9
- package/src/rules/no-unresolved-refs.ts +1 -1
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
- package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas2/index.ts +3 -3
- package/src/rules/oas2/remove-unused-components.ts +14 -9
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
- package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
- package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
- package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas3/index.ts +5 -5
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +21 -10
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +20 -4
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -8
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +26 -3
- package/src/visitors.ts +9 -9
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/license-url.ts +0 -10
package/lib/config/load.js
CHANGED
|
@@ -9,28 +9,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
|
|
12
|
+
exports.createConfig = exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const path = require("path");
|
|
15
15
|
const redocly_1 = require("../redocly");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
|
+
const js_yaml_1 = require("../js-yaml");
|
|
17
18
|
const config_1 = require("./config");
|
|
18
19
|
const utils_2 = require("./utils");
|
|
19
20
|
const config_resolvers_1 = require("./config-resolvers");
|
|
20
|
-
function addConfigMetadata({ rawConfig, customExtends, configPath, }) {
|
|
21
|
+
function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
|
|
21
22
|
var _a;
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
if (customExtends !== undefined) {
|
|
24
|
-
rawConfig.
|
|
25
|
-
rawConfig.
|
|
25
|
+
rawConfig.styleguide = rawConfig.styleguide || {};
|
|
26
|
+
rawConfig.styleguide.extends = customExtends;
|
|
26
27
|
}
|
|
27
28
|
else if (utils_1.isEmptyObject(rawConfig)) {
|
|
28
29
|
// TODO: check if we can add recommended here. add message here?
|
|
29
|
-
// rawConfig.
|
|
30
|
+
// rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
const tokens = yield redoclyClient.getTokens();
|
|
33
|
-
if (tokens.length) {
|
|
32
|
+
if (tokens === null || tokens === void 0 ? void 0 : tokens.length) {
|
|
34
33
|
if (!rawConfig.resolve)
|
|
35
34
|
rawConfig.resolve = {};
|
|
36
35
|
if (!rawConfig.resolve.http)
|
|
@@ -66,10 +65,13 @@ function loadConfig(configPath = findConfig(), customExtends, processRawConfig)
|
|
|
66
65
|
if (typeof processRawConfig === 'function') {
|
|
67
66
|
yield processRawConfig(rawConfig);
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
const redoclyClient = new redocly_1.RedoclyClient();
|
|
69
|
+
const tokens = yield redoclyClient.getTokens();
|
|
70
|
+
return addConfigMetadata({
|
|
70
71
|
rawConfig,
|
|
71
72
|
customExtends,
|
|
72
73
|
configPath,
|
|
74
|
+
tokens,
|
|
73
75
|
});
|
|
74
76
|
});
|
|
75
77
|
}
|
|
@@ -94,7 +96,7 @@ function getConfig(configPath = findConfig()) {
|
|
|
94
96
|
if (!configPath || !utils_1.doesYamlFileExist(configPath))
|
|
95
97
|
return {};
|
|
96
98
|
try {
|
|
97
|
-
const rawConfig = (
|
|
99
|
+
const rawConfig = (yield utils_1.loadYaml(configPath)) || {};
|
|
98
100
|
return utils_2.transformConfig(rawConfig);
|
|
99
101
|
}
|
|
100
102
|
catch (e) {
|
|
@@ -103,3 +105,9 @@ function getConfig(configPath = findConfig()) {
|
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
exports.getConfig = getConfig;
|
|
108
|
+
function createConfig(config, options) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return addConfigMetadata(Object.assign({ rawConfig: utils_2.transformConfig(typeof config === 'string' ? js_yaml_1.parseYaml(config) : config) }, options));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.createConfig = createConfig;
|
package/lib/config/minimal.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const _default:
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
2
|
+
declare const _default: PluginStyleguideConfig;
|
|
3
3
|
export default _default;
|
package/lib/config/minimal.js
CHANGED
|
@@ -18,7 +18,7 @@ exports.default = {
|
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
20
|
'operation-4xx-response': 'off',
|
|
21
|
-
|
|
21
|
+
assertions: 'warn',
|
|
22
22
|
'operation-operationId': 'warn',
|
|
23
23
|
'operation-summary': 'warn',
|
|
24
24
|
'operation-operationId-unique': 'warn',
|
|
@@ -36,7 +36,7 @@ exports.default = {
|
|
|
36
36
|
oas3_0Rules: {
|
|
37
37
|
'no-invalid-media-type-examples': {
|
|
38
38
|
severity: 'warn',
|
|
39
|
-
|
|
39
|
+
allowAdditionalProperties: false,
|
|
40
40
|
},
|
|
41
41
|
'no-server-example.com': 'warn',
|
|
42
42
|
'no-server-trailing-slash': 'error',
|
|
@@ -44,15 +44,16 @@ exports.default = {
|
|
|
44
44
|
'no-example-value-and-externalValue': 'warn',
|
|
45
45
|
'no-unused-components': 'warn',
|
|
46
46
|
'no-undefined-server-variable': 'warn',
|
|
47
|
-
'no-
|
|
47
|
+
'no-server-variables-empty-enum': 'error',
|
|
48
48
|
},
|
|
49
49
|
oas3_1Rules: {
|
|
50
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
51
|
'no-server-example.com': 'warn',
|
|
51
52
|
'no-server-trailing-slash': 'error',
|
|
52
53
|
'no-empty-servers': 'warn',
|
|
53
54
|
'no-example-value-and-externalValue': 'warn',
|
|
54
55
|
'no-unused-components': 'warn',
|
|
55
56
|
'no-undefined-server-variable': 'warn',
|
|
56
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
57
58
|
},
|
|
58
59
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const _default:
|
|
1
|
+
import type { PluginStyleguideConfig } from './types';
|
|
2
|
+
declare const _default: PluginStyleguideConfig;
|
|
3
3
|
export default _default;
|
|
@@ -17,7 +17,7 @@ exports.default = {
|
|
|
17
17
|
'path-parameters-defined': 'error',
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
|
-
|
|
20
|
+
assertions: 'warn',
|
|
21
21
|
'operation-4xx-response': 'warn',
|
|
22
22
|
'operation-operationId': 'warn',
|
|
23
23
|
'operation-summary': 'error',
|
|
@@ -36,7 +36,7 @@ exports.default = {
|
|
|
36
36
|
oas3_0Rules: {
|
|
37
37
|
'no-invalid-media-type-examples': {
|
|
38
38
|
severity: 'warn',
|
|
39
|
-
|
|
39
|
+
allowAdditionalProperties: false,
|
|
40
40
|
},
|
|
41
41
|
'no-server-example.com': 'warn',
|
|
42
42
|
'no-server-trailing-slash': 'error',
|
|
@@ -44,15 +44,16 @@ exports.default = {
|
|
|
44
44
|
'no-example-value-and-externalValue': 'error',
|
|
45
45
|
'no-unused-components': 'warn',
|
|
46
46
|
'no-undefined-server-variable': 'error',
|
|
47
|
-
'no-
|
|
47
|
+
'no-server-variables-empty-enum': 'error',
|
|
48
48
|
},
|
|
49
49
|
oas3_1Rules: {
|
|
50
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
51
|
'no-server-example.com': 'warn',
|
|
51
52
|
'no-server-trailing-slash': 'error',
|
|
52
53
|
'no-empty-servers': 'error',
|
|
53
54
|
'no-example-value-and-externalValue': 'error',
|
|
54
55
|
'no-unused-components': 'warn',
|
|
55
56
|
'no-undefined-server-variable': 'error',
|
|
56
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
57
58
|
},
|
|
58
59
|
};
|
package/lib/config/rules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RuleSet, OasVersion } from '../oas-types';
|
|
2
|
-
import {
|
|
3
|
-
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config:
|
|
4
|
-
severity:
|
|
2
|
+
import { StyleguideConfig } from './config';
|
|
3
|
+
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
|
|
4
|
+
severity: string;
|
|
5
5
|
ruleId: string;
|
|
6
6
|
visitor: any;
|
|
7
7
|
}[];
|
package/lib/config/rules.js
CHANGED
|
@@ -28,7 +28,7 @@ function initRules(rules, config, type, oasVersion) {
|
|
|
28
28
|
visitor: visitors, // note: actually it is only one visitor object
|
|
29
29
|
};
|
|
30
30
|
}))
|
|
31
|
-
.flatMap(visitor => visitor)
|
|
31
|
+
.flatMap((visitor) => visitor)
|
|
32
32
|
.filter(utils_1.notUndefined);
|
|
33
33
|
}
|
|
34
34
|
exports.initRules = initRules;
|
package/lib/config/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare type PreprocessorConfig = PreprocessorSeverity | ({
|
|
|
10
10
|
severity?: ProblemSeverity;
|
|
11
11
|
} & Record<string, any>);
|
|
12
12
|
export declare type DecoratorConfig = PreprocessorConfig;
|
|
13
|
-
export declare type
|
|
13
|
+
export declare type StyleguideRawConfig = {
|
|
14
14
|
plugins?: (string | Plugin)[];
|
|
15
15
|
extends?: string[];
|
|
16
16
|
doNotResolveExamples?: boolean;
|
|
@@ -28,7 +28,8 @@ export declare type LintRawConfig = {
|
|
|
28
28
|
oas3_0Decorators?: Record<string, DecoratorConfig>;
|
|
29
29
|
oas3_1Decorators?: Record<string, DecoratorConfig>;
|
|
30
30
|
};
|
|
31
|
-
export declare type
|
|
31
|
+
export declare type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
|
|
32
|
+
export declare type ResolvedStyleguideConfig = PluginStyleguideConfig & {
|
|
32
33
|
plugins?: Plugin[];
|
|
33
34
|
recommendedFallback?: boolean;
|
|
34
35
|
extends?: void | never;
|
|
@@ -51,13 +52,13 @@ export declare type CustomRulesConfig = {
|
|
|
51
52
|
};
|
|
52
53
|
export declare type Plugin = {
|
|
53
54
|
id: string;
|
|
54
|
-
configs?: Record<string,
|
|
55
|
+
configs?: Record<string, PluginStyleguideConfig>;
|
|
55
56
|
rules?: CustomRulesConfig;
|
|
56
57
|
preprocessors?: PreprocessorsConfig;
|
|
57
58
|
decorators?: DecoratorsConfig;
|
|
58
59
|
typeExtension?: TypeExtensionsConfig;
|
|
59
60
|
};
|
|
60
|
-
export declare type
|
|
61
|
+
export declare type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
|
|
61
62
|
export declare type ResolveHeader = {
|
|
62
63
|
name: string;
|
|
63
64
|
envVariable?: undefined;
|
|
@@ -83,33 +84,36 @@ export declare type Region = 'us' | 'eu';
|
|
|
83
84
|
export declare type AccessTokens = {
|
|
84
85
|
[region in Region]?: string;
|
|
85
86
|
};
|
|
86
|
-
export declare type
|
|
87
|
+
export declare type DeprecatedInRawConfig = {
|
|
87
88
|
apiDefinitions?: Record<string, string>;
|
|
88
|
-
lint?:
|
|
89
|
-
resolve?: RawResolveConfig;
|
|
90
|
-
region?: Region;
|
|
89
|
+
lint?: StyleguideRawConfig;
|
|
91
90
|
referenceDocs?: Record<string, any>;
|
|
91
|
+
apis?: Record<string, Api & DeprecatedInApi>;
|
|
92
92
|
};
|
|
93
93
|
export declare type Api = {
|
|
94
94
|
root: string;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
styleguide?: ApiStyleguideRawConfig;
|
|
96
|
+
} & FeaturesConfig;
|
|
97
|
+
export declare type DeprecatedInApi = {
|
|
98
|
+
lint?: ApiStyleguideRawConfig;
|
|
98
99
|
};
|
|
99
|
-
export declare type ResolvedApi = Omit<Api, '
|
|
100
|
-
|
|
100
|
+
export declare type ResolvedApi = Omit<Api, 'styleguide'> & {
|
|
101
|
+
styleguide: ResolvedStyleguideConfig;
|
|
101
102
|
};
|
|
102
103
|
export declare type RawConfig = {
|
|
103
104
|
apis?: Record<string, Api>;
|
|
104
|
-
|
|
105
|
+
styleguide?: StyleguideRawConfig;
|
|
105
106
|
resolve?: RawResolveConfig;
|
|
106
107
|
region?: Region;
|
|
107
|
-
'features.openapi'?: Record<string, any>;
|
|
108
|
-
'features.mockServer'?: Record<string, any>;
|
|
109
108
|
organization?: string;
|
|
110
|
-
};
|
|
111
|
-
export declare type ResolvedConfig = Omit<RawConfig, '
|
|
112
|
-
lint: ResolvedLintConfig;
|
|
109
|
+
} & FeaturesConfig;
|
|
110
|
+
export declare type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
|
|
113
111
|
apis: Record<string, ResolvedApi>;
|
|
112
|
+
styleguide: ResolvedStyleguideConfig;
|
|
113
|
+
};
|
|
114
|
+
declare type FeaturesConfig = {
|
|
115
|
+
'features.openapi'?: Record<string, any>;
|
|
116
|
+
'features.mockServer'?: Record<string, any>;
|
|
114
117
|
};
|
|
115
118
|
export declare type RulesFields = 'rules' | 'oas2Rules' | 'oas3_0Rules' | 'oas3_1Rules' | 'preprocessors' | 'oas2Preprocessors' | 'oas3_0Preprocessors' | 'oas3_1Preprocessors' | 'decorators' | 'oas2Decorators' | 'oas3_0Decorators' | 'oas3_1Decorators';
|
|
119
|
+
export {};
|
package/lib/config/utils.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
|
-
import type { Api,
|
|
2
|
+
import type { Api, DeprecatedInRawConfig, Plugin, RawConfig, RawResolveConfig, ResolveConfig, ResolvedStyleguideConfig, RulesFields } from './types';
|
|
3
3
|
export declare function parsePresetName(presetName: string): {
|
|
4
4
|
pluginId: string;
|
|
5
5
|
configName: string;
|
|
6
6
|
};
|
|
7
|
-
export declare function transformApiDefinitionsToApis(apiDefinitions?:
|
|
7
|
+
export declare function transformApiDefinitionsToApis(apiDefinitions?: DeprecatedInRawConfig['apiDefinitions']): Record<string, Api> | undefined;
|
|
8
8
|
export declare function prefixRules<T extends Record<string, any>>(rules: T, prefix: string): any;
|
|
9
|
-
export declare function mergeExtends(rulesConfList:
|
|
10
|
-
export declare function getMergedConfig(config: Config,
|
|
11
|
-
export declare function transformConfig(rawConfig:
|
|
9
|
+
export declare function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]): Omit<ResolvedStyleguideConfig, RulesFields> & Required<Pick<ResolvedStyleguideConfig, RulesFields>>;
|
|
10
|
+
export declare function getMergedConfig(config: Config, apiName?: string): Config;
|
|
11
|
+
export declare function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig;
|
|
12
12
|
export declare function getResolveConfig(resolve?: RawResolveConfig): ResolveConfig;
|
|
13
13
|
export declare function getUniquePlugins(plugins: Plugin[]): Plugin[];
|
package/lib/config/utils.js
CHANGED
|
@@ -12,9 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.getUniquePlugins = exports.getResolveConfig = exports.transformConfig = exports.getMergedConfig = exports.mergeExtends = exports.prefixRules = exports.transformApiDefinitionsToApis = exports.parsePresetName = void 0;
|
|
15
|
-
const colorette_1 = require("colorette");
|
|
16
15
|
const utils_1 = require("../utils");
|
|
17
16
|
const config_1 = require("./config");
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
18
|
function parsePresetName(presetName) {
|
|
19
19
|
if (presetName.indexOf('/') > -1) {
|
|
20
20
|
const [pluginId, configName] = presetName.split('/');
|
|
@@ -25,14 +25,26 @@ function parsePresetName(presetName) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.parsePresetName = parsePresetName;
|
|
28
|
-
function transformApiDefinitionsToApis(apiDefinitions
|
|
29
|
-
|
|
28
|
+
function transformApiDefinitionsToApis(apiDefinitions) {
|
|
29
|
+
if (!apiDefinitions)
|
|
30
|
+
return undefined;
|
|
31
|
+
const apis = {};
|
|
30
32
|
for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
|
|
31
33
|
apis[apiName] = { root: apiPath };
|
|
32
34
|
}
|
|
33
35
|
return apis;
|
|
34
36
|
}
|
|
35
37
|
exports.transformApiDefinitionsToApis = transformApiDefinitionsToApis;
|
|
38
|
+
function transformApis(legacyApis) {
|
|
39
|
+
if (!legacyApis)
|
|
40
|
+
return undefined;
|
|
41
|
+
const apis = {};
|
|
42
|
+
for (let _a of Object.entries(legacyApis)) {
|
|
43
|
+
const [apiName, _b] = _a, { lint } = _b, apiContent = __rest(_b, ["lint"]);
|
|
44
|
+
apis[apiName] = Object.assign({ styleguide: lint }, apiContent);
|
|
45
|
+
}
|
|
46
|
+
return apis;
|
|
47
|
+
}
|
|
36
48
|
function prefixRules(rules, prefix) {
|
|
37
49
|
if (!prefix)
|
|
38
50
|
return rules;
|
|
@@ -61,9 +73,9 @@ function mergeExtends(rulesConfList) {
|
|
|
61
73
|
pluginPaths: [],
|
|
62
74
|
extendPaths: [],
|
|
63
75
|
};
|
|
64
|
-
for (
|
|
76
|
+
for (const rulesConf of rulesConfList) {
|
|
65
77
|
if (rulesConf.extends) {
|
|
66
|
-
throw new Error(
|
|
78
|
+
throw new Error(`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
|
|
67
79
|
}
|
|
68
80
|
Object.assign(result.rules, rulesConf.rules);
|
|
69
81
|
Object.assign(result.oas2Rules, rulesConf.oas2Rules);
|
|
@@ -93,44 +105,49 @@ function mergeExtends(rulesConfList) {
|
|
|
93
105
|
return result;
|
|
94
106
|
}
|
|
95
107
|
exports.mergeExtends = mergeExtends;
|
|
96
|
-
function getMergedConfig(config,
|
|
108
|
+
function getMergedConfig(config, apiName) {
|
|
97
109
|
var _a, _b, _c, _d, _e, _f;
|
|
98
110
|
const extendPaths = [
|
|
99
|
-
...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.
|
|
100
|
-
(_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.
|
|
111
|
+
...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.styleguide) === null || _a === void 0 ? void 0 : _a.extendPaths; }),
|
|
112
|
+
(_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.extendPaths,
|
|
101
113
|
]
|
|
102
114
|
.flat()
|
|
103
|
-
.filter(
|
|
115
|
+
.filter(utils_1.isTruthy);
|
|
104
116
|
const pluginPaths = [
|
|
105
|
-
...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.
|
|
106
|
-
(_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.
|
|
117
|
+
...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.styleguide) === null || _a === void 0 ? void 0 : _a.pluginPaths; }),
|
|
118
|
+
(_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.styleguide) === null || _d === void 0 ? void 0 : _d.pluginPaths,
|
|
107
119
|
]
|
|
108
120
|
.flat()
|
|
109
|
-
.filter(
|
|
110
|
-
return
|
|
111
|
-
? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), {
|
|
112
|
-
? config.apis[
|
|
113
|
-
: config.rawConfig.
|
|
114
|
-
pluginPaths }), 'features.openapi': Object.assign(Object.assign({}, config['features.openapi']), (_e = config.apis[
|
|
121
|
+
.filter(utils_1.isTruthy);
|
|
122
|
+
return apiName
|
|
123
|
+
? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { styleguide: Object.assign(Object.assign({}, (config.apis[apiName]
|
|
124
|
+
? config.apis[apiName].styleguide
|
|
125
|
+
: config.rawConfig.styleguide)), { extendPaths,
|
|
126
|
+
pluginPaths }), 'features.openapi': Object.assign(Object.assign({}, config['features.openapi']), (_e = config.apis[apiName]) === null || _e === void 0 ? void 0 : _e['features.openapi']), 'features.mockServer': Object.assign(Object.assign({}, config['features.mockServer']), (_f = config.apis[apiName]) === null || _f === void 0 ? void 0 : _f['features.mockServer']) }), config.configFile)
|
|
115
127
|
: config;
|
|
116
128
|
}
|
|
117
129
|
exports.getMergedConfig = getMergedConfig;
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
function checkForDeprecatedFields(deprecatedField, updatedField, rawConfig) {
|
|
131
|
+
const isDeprecatedFieldInApis = rawConfig.apis &&
|
|
132
|
+
Object.values(rawConfig.apis).some((api) => api[deprecatedField]);
|
|
133
|
+
if (rawConfig[deprecatedField] && rawConfig[updatedField]) {
|
|
134
|
+
utils_1.showErrorForDeprecatedField(deprecatedField, updatedField);
|
|
121
135
|
}
|
|
122
|
-
if (rawConfig[
|
|
123
|
-
|
|
124
|
-
throw new Error("Do not use 'referenceDocs' field. Use 'features.openapi' instead.\n");
|
|
136
|
+
if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
|
|
137
|
+
utils_1.showWarningForDeprecatedField(deprecatedField, updatedField);
|
|
125
138
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
}
|
|
140
|
+
function transformConfig(rawConfig) {
|
|
141
|
+
const migratedFields = [
|
|
142
|
+
['apiDefinitions', 'apis'],
|
|
143
|
+
['referenceDocs', 'features.openapi'],
|
|
144
|
+
['lint', 'styleguide'], // TODO: update docs
|
|
145
|
+
];
|
|
146
|
+
for (const [deprecatedField, updatedField] of migratedFields) {
|
|
147
|
+
checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
|
|
132
148
|
}
|
|
133
|
-
|
|
149
|
+
const { apis, apiDefinitions, referenceDocs, lint } = rawConfig, rest = __rest(rawConfig, ["apis", "apiDefinitions", "referenceDocs", "lint"]);
|
|
150
|
+
return Object.assign({ 'features.openapi': referenceDocs, apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions), styleguide: lint }, rest);
|
|
134
151
|
}
|
|
135
152
|
exports.transformConfig = transformConfig;
|
|
136
153
|
function getResolveConfig(resolve) {
|
|
@@ -152,7 +169,7 @@ function getUniquePlugins(plugins) {
|
|
|
152
169
|
seen.add(p.id);
|
|
153
170
|
}
|
|
154
171
|
else if (p.id) {
|
|
155
|
-
|
|
172
|
+
logger_1.logger.warn(`Duplicate plugin id "${logger_1.colorize.red(p.id)}".\n`);
|
|
156
173
|
}
|
|
157
174
|
}
|
|
158
175
|
return results;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RegistryDependencies = void 0;
|
|
4
4
|
const redocly_1 = require("../../redocly");
|
|
5
5
|
const RegistryDependencies = () => {
|
|
6
|
-
|
|
6
|
+
const registryDependencies = new Set();
|
|
7
7
|
return {
|
|
8
8
|
DefinitionRoot: {
|
|
9
9
|
leave(_, ctx) {
|
package/lib/env.d.ts
ADDED
package/lib/env.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.env = exports.isBrowser = void 0;
|
|
4
|
+
exports.isBrowser =
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
|
|
8
|
+
exports.env = exports.isBrowser ? {} : process.env || {};
|
package/lib/format/codeframes.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAstNodeByPointer = exports.getLineColLocation = exports.getCodeframe = void 0;
|
|
4
|
-
const colorette_1 = require("colorette");
|
|
5
4
|
const yamlAst = require("yaml-ast-parser");
|
|
6
5
|
const ref_utils_1 = require("../ref-utils");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
7
|
const MAX_LINE_LENGTH = 150;
|
|
8
8
|
const MAX_CODEFRAME_LINES = 3;
|
|
9
9
|
// TODO: temporary
|
|
@@ -11,7 +11,7 @@ function parsePointer(pointer) {
|
|
|
11
11
|
return pointer.substr(2).split('/').map(ref_utils_1.unescapePointer);
|
|
12
12
|
}
|
|
13
13
|
function getCodeframe(location, color) {
|
|
14
|
-
|
|
14
|
+
logger_1.colorOptions.enabled = color;
|
|
15
15
|
const { start, end = { line: start.line, col: start.col + 1 }, source } = location;
|
|
16
16
|
const lines = source.getLines();
|
|
17
17
|
const startLineNum = start.line;
|
|
@@ -28,16 +28,22 @@ function getCodeframe(location, color) {
|
|
|
28
28
|
const line = lines[i - 1] || '';
|
|
29
29
|
if (line !== '')
|
|
30
30
|
currentPad = padSize(line);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx,
|
|
31
|
+
const startIdx = i === startLineNum ? start.col - 1 : currentPad;
|
|
32
|
+
const endIdx = i === endLineNum ? end.col - 1 : line.length;
|
|
33
|
+
prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, logger_1.colorize.red)]);
|
|
34
34
|
if (!color)
|
|
35
35
|
prefixedLines.push(['', underlineLine(line, startIdx, endIdx)]);
|
|
36
36
|
}
|
|
37
37
|
if (skipLines > 0) {
|
|
38
|
-
prefixedLines.push([
|
|
38
|
+
prefixedLines.push([
|
|
39
|
+
`…`,
|
|
40
|
+
`${whitespace(currentPad)}${logger_1.colorize.gray(`< ${skipLines} more lines >`)}`,
|
|
41
|
+
]);
|
|
39
42
|
// print last line
|
|
40
|
-
prefixedLines.push([
|
|
43
|
+
prefixedLines.push([
|
|
44
|
+
`${endLineNum}`,
|
|
45
|
+
markLine(lines[endLineNum - 1], -1, end.col - 1, logger_1.colorize.red),
|
|
46
|
+
]);
|
|
41
47
|
if (!color)
|
|
42
48
|
prefixedLines.push(['', underlineLine(lines[endLineNum - 1], -1, end.col - 1)]);
|
|
43
49
|
}
|
|
@@ -48,7 +54,7 @@ function getCodeframe(location, color) {
|
|
|
48
54
|
[`${endLineNum + 1}`, markLine(lines[endLineNum - 1 + 1])],
|
|
49
55
|
[`${endLineNum + 2}`, markLine(lines[endLineNum - 1 + 2])],
|
|
50
56
|
]);
|
|
51
|
-
function markLine(line, startIdx = -1, endIdx = +Infinity, variant =
|
|
57
|
+
function markLine(line, startIdx = -1, endIdx = +Infinity, variant = logger_1.colorize.gray) {
|
|
52
58
|
if (!color)
|
|
53
59
|
return line;
|
|
54
60
|
if (!line)
|
|
@@ -66,14 +72,14 @@ function printPrefixedLines(lines) {
|
|
|
66
72
|
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
|
|
67
73
|
const dedentLen = Math.min(...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))));
|
|
68
74
|
return existingLines
|
|
69
|
-
.map(([prefix, line]) =>
|
|
75
|
+
.map(([prefix, line]) => logger_1.colorize.gray(leftPad(padLen, prefix) + ' |') +
|
|
70
76
|
(line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''))
|
|
71
77
|
.join('\n');
|
|
72
78
|
}
|
|
73
79
|
function limitLineLength(line, maxLen = MAX_LINE_LENGTH) {
|
|
74
80
|
const overflowLen = line.length - maxLen;
|
|
75
81
|
if (overflowLen > 0) {
|
|
76
|
-
const charsMoreText =
|
|
82
|
+
const charsMoreText = logger_1.colorize.gray(`...<${overflowLen} chars>`);
|
|
77
83
|
return line.substring(0, maxLen - charsMoreText.length) + charsMoreText;
|
|
78
84
|
}
|
|
79
85
|
else {
|