@redocly/openapi-core 1.18.0 → 1.19.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 +20 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +2 -2
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +2 -2
- package/lib/benchmark/benches/recommended-oas3.bench.js +2 -2
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +2 -2
- package/lib/benchmark/utils.js +7 -4
- package/lib/bundle.d.ts +3 -3
- package/lib/bundle.js +128 -122
- package/lib/config/all.js +9 -0
- package/lib/config/builtIn.js +7 -1
- package/lib/config/config-resolvers.js +179 -138
- package/lib/config/config.d.ts +2 -2
- package/lib/config/config.js +53 -34
- package/lib/config/load.d.ts +1 -2
- package/lib/config/load.js +105 -117
- package/lib/config/minimal.js +9 -0
- package/lib/config/recommended-strict.js +9 -0
- package/lib/config/recommended.js +9 -0
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -2
- package/lib/config/types.d.ts +9 -3
- package/lib/config/utils.js +70 -49
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.js +2 -3
- package/lib/decorators/common/filters/filter-in.js +1 -1
- package/lib/decorators/common/filters/filter-out.js +1 -1
- package/lib/decorators/common/info-override.js +1 -12
- package/lib/decorators/common/media-type-examples-override.js +8 -2
- package/lib/decorators/common/remove-x-internal.js +4 -5
- package/lib/decorators/oas2/remove-unused-components.js +1 -2
- package/lib/decorators/oas3/remove-unused-components.js +1 -2
- package/lib/env.d.ts +0 -1
- package/lib/env.js +1 -1
- package/lib/format/codeframes.js +10 -8
- package/lib/format/format.js +23 -15
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -4
- package/lib/js-yaml/index.js +1 -1
- package/lib/lint.d.ts +2 -0
- package/lib/lint.js +92 -99
- package/lib/oas-types.d.ts +9 -5
- package/lib/oas-types.js +22 -12
- package/lib/redocly/domains.js +6 -6
- package/lib/redocly/index.js +60 -73
- package/lib/redocly/registry-api.js +64 -82
- package/lib/ref-utils.js +13 -13
- package/lib/resolve.js +186 -205
- package/lib/rules/ajv.js +10 -8
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +22 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.js +5 -5
- package/lib/rules/common/assertions/index.d.ts +5 -4
- package/lib/rules/common/assertions/utils.js +43 -28
- package/lib/rules/common/no-invalid-parameter-examples.js +1 -2
- package/lib/rules/common/no-invalid-schema-examples.js +1 -2
- package/lib/rules/common/no-required-schema-properties-undefined.js +1 -2
- package/lib/rules/common/operation-tag-defined.js +1 -2
- package/lib/rules/common/path-http-verbs-order.js +1 -1
- package/lib/rules/common/path-segment-plural.js +2 -1
- package/lib/rules/common/required-string-property-missing-min-length.js +2 -2
- package/lib/rules/common/response-contains-header.js +2 -2
- package/lib/rules/common/security-defined.js +3 -7
- package/lib/rules/common/spec.d.ts +2 -2
- package/lib/rules/common/spec.js +6 -7
- package/lib/rules/no-unresolved-refs.js +3 -4
- package/lib/rules/oas2/response-contains-property.js +1 -2
- package/lib/rules/oas3/array-parameter-serialization.js +1 -2
- package/lib/rules/oas3/component-name-unique.js +2 -4
- package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -2
- package/lib/rules/oas3/no-undefined-server-variable.js +2 -3
- package/lib/rules/oas3/no-unused-components.js +1 -2
- package/lib/rules/oas3/response-contains-property.js +1 -2
- package/lib/rules/utils.js +14 -12
- package/lib/types/arazzo.d.ts +1299 -73
- package/lib/types/arazzo.js +41 -36
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/{asyncapi.js → asyncapi2.js} +71 -93
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.js +19 -10
- package/lib/types/json-schema-adapter.js +4 -18
- package/lib/types/oas2.js +6 -6
- package/lib/types/oas3.js +10 -10
- package/lib/types/oas3_1.js +15 -9
- package/lib/types/redocly-yaml.d.ts +3 -1
- package/lib/types/redocly-yaml.js +131 -35
- package/lib/typings/arazzo.d.ts +28 -1
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/utils.d.ts +12 -7
- package/lib/utils.js +91 -77
- package/lib/visitors.d.ts +11 -0
- package/lib/visitors.js +21 -8
- package/lib/walk.js +30 -23
- package/package.json +3 -3
- package/src/__tests__/bundle.test.ts +142 -0
- package/src/__tests__/lint.test.ts +0 -50
- package/src/bundle.ts +19 -6
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +22 -0
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
- package/src/config/__tests__/config.test.ts +11 -0
- package/src/config/all.ts +9 -0
- package/src/config/builtIn.ts +6 -0
- package/src/config/config-resolvers.ts +15 -2
- package/src/config/config.ts +24 -5
- package/src/config/load.ts +1 -2
- package/src/config/minimal.ts +9 -0
- package/src/config/recommended-strict.ts +9 -0
- package/src/config/recommended.ts +9 -0
- package/src/config/rules.ts +12 -4
- package/src/config/types.ts +15 -2
- package/src/config/utils.ts +15 -0
- package/src/decorators/async3/index.ts +1 -0
- package/src/decorators/common/remove-x-internal.ts +2 -2
- package/src/index.ts +2 -1
- package/src/lint.ts +26 -3
- package/src/oas-types.ts +31 -13
- package/src/rules/arazzo/index.ts +1 -1
- package/src/rules/async2/index.ts +5 -5
- package/src/rules/async3/__tests__/channels-kebab-case.test.ts +141 -0
- package/src/rules/async3/__tests__/no-channel-trailing-slash.test.ts +96 -0
- package/src/rules/async3/channels-kebab-case.ts +19 -0
- package/src/rules/async3/index.ts +23 -0
- package/src/rules/async3/no-channel-trailing-slash.ts +16 -0
- package/src/rules/common/__tests__/spec.test.ts +47 -0
- package/src/rules/common/assertions/index.ts +13 -4
- package/src/rules/common/no-invalid-schema-examples.ts +3 -2
- package/src/rules/common/path-segment-plural.ts +3 -2
- package/src/rules/common/spec.ts +2 -2
- package/src/rules/oas2/index.ts +4 -4
- package/src/rules/oas3/index.ts +39 -37
- package/src/types/arazzo.ts +28 -23
- package/src/types/{asyncapi.ts → asyncapi2.ts} +58 -76
- package/src/types/asyncapi3.ts +381 -0
- package/src/types/oas3_1.ts +3 -2
- package/src/types/redocly-yaml.ts +14 -0
- package/src/typings/arazzo.ts +41 -1
- package/src/typings/asyncapi3.ts +61 -0
- package/src/utils.ts +46 -11
- package/src/visitors.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/types/asyncapi.d.ts +0 -2
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
3
|
+
exports.resolveConfigFileAndRefs = resolveConfigFileAndRefs;
|
|
4
|
+
exports.resolveConfig = resolveConfig;
|
|
5
|
+
exports.resolvePlugins = resolvePlugins;
|
|
6
|
+
exports.resolveApis = resolveApis;
|
|
7
|
+
exports.resolveStyleguideConfig = resolveStyleguideConfig;
|
|
8
|
+
exports.resolvePreset = resolvePreset;
|
|
24
9
|
const path = require("path");
|
|
25
10
|
const ref_utils_1 = require("../ref-utils");
|
|
26
11
|
const utils_1 = require("../utils");
|
|
@@ -34,47 +19,43 @@ const logger_1 = require("../logger");
|
|
|
34
19
|
const asserts_1 = require("../rules/common/assertions/asserts");
|
|
35
20
|
const types_1 = require("../types");
|
|
36
21
|
const redocly_yaml_1 = require("../types/redocly-yaml");
|
|
37
|
-
function resolveConfigFileAndRefs({ configPath, externalRefResolver = new resolve_1.BaseResolver(), base = null, }) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
externalRefResolver,
|
|
51
|
-
});
|
|
52
|
-
return { document, resolvedRefMap };
|
|
22
|
+
async function resolveConfigFileAndRefs({ configPath, externalRefResolver = new resolve_1.BaseResolver(), base = null, }) {
|
|
23
|
+
if (!configPath) {
|
|
24
|
+
throw new Error('Reference to a config is required.\n');
|
|
25
|
+
}
|
|
26
|
+
const document = await externalRefResolver.resolveDocument(base, configPath, true);
|
|
27
|
+
if (document instanceof Error) {
|
|
28
|
+
throw document;
|
|
29
|
+
}
|
|
30
|
+
const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes);
|
|
31
|
+
const resolvedRefMap = await (0, resolve_1.resolveDocument)({
|
|
32
|
+
rootDocument: document,
|
|
33
|
+
rootType: types.ConfigRoot,
|
|
34
|
+
externalRefResolver,
|
|
53
35
|
});
|
|
36
|
+
return { document, resolvedRefMap };
|
|
54
37
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
styleguideConfig: rawConfig.styleguide,
|
|
70
|
-
configPath,
|
|
71
|
-
resolver,
|
|
72
|
-
});
|
|
73
|
-
return new config_1.Config(Object.assign(Object.assign({}, rawConfig), { apis,
|
|
74
|
-
styleguide }), configPath);
|
|
38
|
+
async function resolveConfig({ rawConfig, configPath, externalRefResolver, }) {
|
|
39
|
+
if (rawConfig.styleguide?.extends?.some(utils_3.isNotString)) {
|
|
40
|
+
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
41
|
+
}
|
|
42
|
+
const resolver = externalRefResolver ?? new resolve_1.BaseResolver((0, utils_2.getResolveConfig)(rawConfig.resolve));
|
|
43
|
+
const apis = await resolveApis({
|
|
44
|
+
rawConfig,
|
|
45
|
+
configPath,
|
|
46
|
+
resolver,
|
|
47
|
+
});
|
|
48
|
+
const styleguide = await resolveStyleguideConfig({
|
|
49
|
+
styleguideConfig: rawConfig.styleguide,
|
|
50
|
+
configPath,
|
|
51
|
+
resolver,
|
|
75
52
|
});
|
|
53
|
+
return new config_1.Config({
|
|
54
|
+
...rawConfig,
|
|
55
|
+
apis,
|
|
56
|
+
styleguide,
|
|
57
|
+
}, configPath);
|
|
76
58
|
}
|
|
77
|
-
exports.resolveConfig = resolveConfig;
|
|
78
59
|
function resolvePlugins(plugins, configPath = '') {
|
|
79
60
|
if (!plugins)
|
|
80
61
|
return [];
|
|
@@ -124,10 +105,14 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
124
105
|
throw new Error(logger_1.colorize.red(`Plugin "id" must be unique. Plugin ${logger_1.colorize.blue(p.toString())} uses id "${logger_1.colorize.blue(id)}" already seen in ${logger_1.colorize.blue(pluginPath)}`));
|
|
125
106
|
}
|
|
126
107
|
seenPluginIds.set(id, p.toString());
|
|
127
|
-
const plugin =
|
|
108
|
+
const plugin = {
|
|
109
|
+
id,
|
|
110
|
+
...(pluginModule.configs ? { configs: pluginModule.configs } : {}),
|
|
111
|
+
...(pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}),
|
|
112
|
+
};
|
|
128
113
|
if (pluginModule.rules) {
|
|
129
114
|
if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2 && !pluginModule.rules.async2) {
|
|
130
|
-
throw new Error(`Plugin rules must have \`oas3\`, \`oas2\`, \`async2\`, or \`arazzo\` rules "${p}.`);
|
|
115
|
+
throw new Error(`Plugin rules must have \`oas3\`, \`oas2\`, \`async2\`, \`async3\` or \`arazzo\` rules "${p}.`);
|
|
131
116
|
}
|
|
132
117
|
plugin.rules = {};
|
|
133
118
|
if (pluginModule.rules.oas3) {
|
|
@@ -139,6 +124,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
139
124
|
if (pluginModule.rules.async2) {
|
|
140
125
|
plugin.rules.async2 = (0, utils_2.prefixRules)(pluginModule.rules.async2, id);
|
|
141
126
|
}
|
|
127
|
+
if (pluginModule.rules.async3) {
|
|
128
|
+
plugin.rules.async3 = (0, utils_2.prefixRules)(pluginModule.rules.async3, id);
|
|
129
|
+
}
|
|
142
130
|
if (pluginModule.rules.arazzo) {
|
|
143
131
|
plugin.rules.arazzo = (0, utils_2.prefixRules)(pluginModule.rules.arazzo, id);
|
|
144
132
|
}
|
|
@@ -147,6 +135,7 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
147
135
|
if (!pluginModule.preprocessors.oas3 &&
|
|
148
136
|
!pluginModule.preprocessors.oas2 &&
|
|
149
137
|
!pluginModule.preprocessors.async2 &&
|
|
138
|
+
!pluginModule.preprocessors.async3 &&
|
|
150
139
|
!pluginModule.preprocessors.arazzo) {
|
|
151
140
|
throw new Error(`Plugin \`preprocessors\` must have \`oas3\`, \`oas2\` or \`async2\` preprocessors "${p}.`);
|
|
152
141
|
}
|
|
@@ -160,6 +149,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
160
149
|
if (pluginModule.preprocessors.async2) {
|
|
161
150
|
plugin.preprocessors.async2 = (0, utils_2.prefixRules)(pluginModule.preprocessors.async2, id);
|
|
162
151
|
}
|
|
152
|
+
if (pluginModule.preprocessors.async3) {
|
|
153
|
+
plugin.preprocessors.async3 = (0, utils_2.prefixRules)(pluginModule.preprocessors.async3, id);
|
|
154
|
+
}
|
|
163
155
|
if (pluginModule.preprocessors.arazzo) {
|
|
164
156
|
plugin.preprocessors.arazzo = (0, utils_2.prefixRules)(pluginModule.preprocessors.arazzo, id);
|
|
165
157
|
}
|
|
@@ -168,8 +160,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
168
160
|
if (!pluginModule.decorators.oas3 &&
|
|
169
161
|
!pluginModule.decorators.oas2 &&
|
|
170
162
|
!pluginModule.decorators.async2 &&
|
|
163
|
+
!pluginModule.decorators.async3 &&
|
|
171
164
|
!pluginModule.decorators.arazzo) {
|
|
172
|
-
throw new Error(`Plugin \`decorators\` must have \`oas3\`, \`oas2\` or \`
|
|
165
|
+
throw new Error(`Plugin \`decorators\` must have \`oas3\`, \`oas2\`, \`async2\` or \`async3\` decorators "${p}.`);
|
|
173
166
|
}
|
|
174
167
|
plugin.decorators = {};
|
|
175
168
|
if (pluginModule.decorators.oas3) {
|
|
@@ -181,6 +174,9 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
181
174
|
if (pluginModule.decorators.async2) {
|
|
182
175
|
plugin.decorators.async2 = (0, utils_2.prefixRules)(pluginModule.decorators.async2, id);
|
|
183
176
|
}
|
|
177
|
+
if (pluginModule.decorators.async3) {
|
|
178
|
+
plugin.decorators.async3 = (0, utils_2.prefixRules)(pluginModule.decorators.async3, id);
|
|
179
|
+
}
|
|
184
180
|
if (pluginModule.decorators.arazzo) {
|
|
185
181
|
plugin.decorators.arazzo = (0, utils_2.prefixRules)(pluginModule.decorators.arazzo, id);
|
|
186
182
|
}
|
|
@@ -192,77 +188,82 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
192
188
|
})
|
|
193
189
|
.filter(utils_3.isDefined);
|
|
194
190
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
for (const [apiName, apiContent] of Object.entries(apis || {})) {
|
|
202
|
-
if ((_b = (_a = apiContent.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_3.isNotString)) {
|
|
203
|
-
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
204
|
-
}
|
|
205
|
-
const rawStyleguideConfig = getMergedRawStyleguideConfig(styleguideConfig, apiContent.styleguide);
|
|
206
|
-
const resolvedApiConfig = yield resolveStyleguideConfig({
|
|
207
|
-
styleguideConfig: rawStyleguideConfig,
|
|
208
|
-
configPath,
|
|
209
|
-
resolver,
|
|
210
|
-
});
|
|
211
|
-
resolvedApis[apiName] = Object.assign(Object.assign({}, apiContent), { styleguide: resolvedApiConfig });
|
|
191
|
+
async function resolveApis({ rawConfig, configPath = '', resolver, }) {
|
|
192
|
+
const { apis = {}, styleguide: styleguideConfig = {} } = rawConfig;
|
|
193
|
+
const resolvedApis = {};
|
|
194
|
+
for (const [apiName, apiContent] of Object.entries(apis || {})) {
|
|
195
|
+
if (apiContent.styleguide?.extends?.some(utils_3.isNotString)) {
|
|
196
|
+
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
212
197
|
}
|
|
213
|
-
|
|
214
|
-
|
|
198
|
+
const rawStyleguideConfig = getMergedRawStyleguideConfig(styleguideConfig, apiContent.styleguide);
|
|
199
|
+
const resolvedApiConfig = await resolveStyleguideConfig({
|
|
200
|
+
styleguideConfig: rawStyleguideConfig,
|
|
201
|
+
configPath,
|
|
202
|
+
resolver,
|
|
203
|
+
});
|
|
204
|
+
resolvedApis[apiName] = { ...apiContent, styleguide: resolvedApiConfig };
|
|
205
|
+
}
|
|
206
|
+
return resolvedApis;
|
|
215
207
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
async function resolveAndMergeNestedStyleguideConfig({ styleguideConfig, configPath = '', resolver = new resolve_1.BaseResolver(), }, parentConfigPaths = [], extendPaths = []) {
|
|
209
|
+
if (parentConfigPaths.includes(configPath)) {
|
|
210
|
+
throw new Error(`Circular dependency in config file: "${configPath}"`);
|
|
211
|
+
}
|
|
212
|
+
const plugins = (0, utils_2.getUniquePlugins)(resolvePlugins([...(styleguideConfig?.plugins || []), builtIn_1.defaultPlugin], configPath));
|
|
213
|
+
const pluginPaths = styleguideConfig?.plugins
|
|
214
|
+
?.filter(utils_3.isString)
|
|
215
|
+
.map((p) => path.resolve(path.dirname(configPath), p));
|
|
216
|
+
const resolvedConfigPath = (0, ref_utils_1.isAbsoluteUrl)(configPath)
|
|
217
|
+
? configPath
|
|
218
|
+
: configPath && path.resolve(configPath);
|
|
219
|
+
const extendConfigs = await Promise.all(styleguideConfig?.extends?.map(async (presetItem) => {
|
|
220
|
+
if (!(0, ref_utils_1.isAbsoluteUrl)(presetItem) && !path.extname(presetItem)) {
|
|
221
|
+
return resolvePreset(presetItem, plugins);
|
|
222
222
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
223
|
+
const pathItem = (0, ref_utils_1.isAbsoluteUrl)(presetItem)
|
|
224
|
+
? presetItem
|
|
225
|
+
: (0, ref_utils_1.isAbsoluteUrl)(configPath)
|
|
226
|
+
? new URL(presetItem, configPath).href
|
|
227
|
+
: path.resolve(path.dirname(configPath), presetItem);
|
|
228
|
+
const extendedStyleguideConfig = await loadExtendStyleguideConfig(pathItem, resolver);
|
|
229
|
+
return await resolveAndMergeNestedStyleguideConfig({
|
|
230
|
+
styleguideConfig: extendedStyleguideConfig,
|
|
231
|
+
configPath: pathItem,
|
|
232
|
+
resolver: resolver,
|
|
233
|
+
}, [...parentConfigPaths, resolvedConfigPath], extendPaths);
|
|
234
|
+
}) || []);
|
|
235
|
+
const { plugins: mergedPlugins = [], ...styleguide } = (0, utils_2.mergeExtends)([
|
|
236
|
+
...extendConfigs,
|
|
237
|
+
{
|
|
238
|
+
...styleguideConfig,
|
|
239
|
+
plugins,
|
|
240
|
+
extends: undefined,
|
|
241
|
+
extendPaths: [...parentConfigPaths, resolvedConfigPath],
|
|
242
|
+
pluginPaths,
|
|
243
|
+
},
|
|
244
|
+
]);
|
|
245
|
+
return {
|
|
246
|
+
...styleguide,
|
|
247
|
+
extendPaths: styleguide.extendPaths?.filter((path) => path && !(0, ref_utils_1.isAbsoluteUrl)(path)),
|
|
248
|
+
plugins: (0, utils_2.getUniquePlugins)(mergedPlugins),
|
|
249
|
+
recommendedFallback: styleguideConfig?.recommendedFallback,
|
|
250
|
+
doNotResolveExamples: styleguideConfig?.doNotResolveExamples,
|
|
251
|
+
};
|
|
250
252
|
}
|
|
251
|
-
function resolveStyleguideConfig(opts, parentConfigPaths = [], extendPaths = []) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
async function resolveStyleguideConfig(opts, parentConfigPaths = [], extendPaths = []) {
|
|
254
|
+
const resolvedStyleguideConfig = await resolveAndMergeNestedStyleguideConfig(opts, parentConfigPaths, extendPaths);
|
|
255
|
+
return {
|
|
256
|
+
...resolvedStyleguideConfig,
|
|
257
|
+
rules: resolvedStyleguideConfig.rules && groupStyleguideAssertionRules(resolvedStyleguideConfig),
|
|
258
|
+
};
|
|
256
259
|
}
|
|
257
|
-
exports.resolveStyleguideConfig = resolveStyleguideConfig;
|
|
258
260
|
function resolvePreset(presetName, plugins) {
|
|
259
|
-
var _a;
|
|
260
261
|
const { pluginId, configName } = (0, utils_2.parsePresetName)(presetName);
|
|
261
262
|
const plugin = plugins.find((p) => p.id === pluginId);
|
|
262
263
|
if (!plugin) {
|
|
263
264
|
throw new Error(`Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} is not included.`);
|
|
264
265
|
}
|
|
265
|
-
const preset =
|
|
266
|
+
const preset = plugin.configs?.[configName];
|
|
266
267
|
if (!preset) {
|
|
267
268
|
throw new Error(pluginId
|
|
268
269
|
? `Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
|
|
@@ -270,26 +271,63 @@ function resolvePreset(presetName, plugins) {
|
|
|
270
271
|
}
|
|
271
272
|
return preset;
|
|
272
273
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (!rawConfig.styleguide) {
|
|
280
|
-
throw new Error(`Styleguide configuration format not detected: "${filePath}"`);
|
|
281
|
-
}
|
|
282
|
-
return rawConfig.styleguide;
|
|
274
|
+
async function loadExtendStyleguideConfig(filePath, resolver) {
|
|
275
|
+
try {
|
|
276
|
+
const { parsed } = (await resolver.resolveDocument(null, filePath));
|
|
277
|
+
const rawConfig = (0, utils_2.transformConfig)(parsed);
|
|
278
|
+
if (!rawConfig.styleguide) {
|
|
279
|
+
throw new Error(`Styleguide configuration format not detected: "${filePath}"`);
|
|
283
280
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
281
|
+
return rawConfig.styleguide;
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
throw new Error(`Failed to load "${filePath}": ${error.message}`);
|
|
285
|
+
}
|
|
288
286
|
}
|
|
289
287
|
function getMergedRawStyleguideConfig(rootStyleguideConfig, apiStyleguideConfig) {
|
|
290
|
-
const resultLint =
|
|
288
|
+
const resultLint = {
|
|
289
|
+
...rootStyleguideConfig,
|
|
290
|
+
...(0, utils_1.pickDefined)(apiStyleguideConfig),
|
|
291
|
+
rules: { ...rootStyleguideConfig?.rules, ...apiStyleguideConfig?.rules },
|
|
292
|
+
oas2Rules: { ...rootStyleguideConfig?.oas2Rules, ...apiStyleguideConfig?.oas2Rules },
|
|
293
|
+
oas3_0Rules: { ...rootStyleguideConfig?.oas3_0Rules, ...apiStyleguideConfig?.oas3_0Rules },
|
|
294
|
+
oas3_1Rules: { ...rootStyleguideConfig?.oas3_1Rules, ...apiStyleguideConfig?.oas3_1Rules },
|
|
295
|
+
async2Rules: { ...rootStyleguideConfig?.async2Rules, ...apiStyleguideConfig?.async2Rules },
|
|
296
|
+
async3Rules: { ...rootStyleguideConfig?.async3Rules, ...apiStyleguideConfig?.async3Rules },
|
|
297
|
+
arazzoRules: { ...rootStyleguideConfig?.arazzoRules, ...apiStyleguideConfig?.arazzoRules },
|
|
298
|
+
preprocessors: {
|
|
299
|
+
...rootStyleguideConfig?.preprocessors,
|
|
300
|
+
...apiStyleguideConfig?.preprocessors,
|
|
301
|
+
},
|
|
302
|
+
oas2Preprocessors: {
|
|
303
|
+
...rootStyleguideConfig?.oas2Preprocessors,
|
|
304
|
+
...apiStyleguideConfig?.oas2Preprocessors,
|
|
305
|
+
},
|
|
306
|
+
oas3_0Preprocessors: {
|
|
307
|
+
...rootStyleguideConfig?.oas3_0Preprocessors,
|
|
308
|
+
...apiStyleguideConfig?.oas3_0Preprocessors,
|
|
309
|
+
},
|
|
310
|
+
oas3_1Preprocessors: {
|
|
311
|
+
...rootStyleguideConfig?.oas3_1Preprocessors,
|
|
312
|
+
...apiStyleguideConfig?.oas3_1Preprocessors,
|
|
313
|
+
},
|
|
314
|
+
decorators: { ...rootStyleguideConfig?.decorators, ...apiStyleguideConfig?.decorators },
|
|
315
|
+
oas2Decorators: {
|
|
316
|
+
...rootStyleguideConfig?.oas2Decorators,
|
|
317
|
+
...apiStyleguideConfig?.oas2Decorators,
|
|
318
|
+
},
|
|
319
|
+
oas3_0Decorators: {
|
|
320
|
+
...rootStyleguideConfig?.oas3_0Decorators,
|
|
321
|
+
...apiStyleguideConfig?.oas3_0Decorators,
|
|
322
|
+
},
|
|
323
|
+
oas3_1Decorators: {
|
|
324
|
+
...rootStyleguideConfig?.oas3_1Decorators,
|
|
325
|
+
...apiStyleguideConfig?.oas3_1Decorators,
|
|
326
|
+
},
|
|
327
|
+
recommendedFallback: apiStyleguideConfig?.extends
|
|
291
328
|
? false
|
|
292
|
-
: rootStyleguideConfig.recommendedFallback
|
|
329
|
+
: rootStyleguideConfig.recommendedFallback,
|
|
330
|
+
};
|
|
293
331
|
return resultLint;
|
|
294
332
|
}
|
|
295
333
|
function groupStyleguideAssertionRules({ rules, plugins, }) {
|
|
@@ -313,7 +351,10 @@ function groupStyleguideAssertionRules({ rules, plugins, }) {
|
|
|
313
351
|
registerCustomAssertions(plugins, context);
|
|
314
352
|
}
|
|
315
353
|
}
|
|
316
|
-
assertions.push(
|
|
354
|
+
assertions.push({
|
|
355
|
+
...assertion,
|
|
356
|
+
assertionId: ruleKey,
|
|
357
|
+
});
|
|
317
358
|
}
|
|
318
359
|
else {
|
|
319
360
|
// If it's not an assertion, keep it as is
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NormalizedProblem } from '../walk';
|
|
2
|
-
import { SpecVersion, SpecMajorVersion, Oas2RuleSet, Oas3RuleSet,
|
|
2
|
+
import { SpecVersion, SpecMajorVersion, Oas2RuleSet, Oas3RuleSet, Async3RuleSet, ArazzoRuleSet } from '../oas-types';
|
|
3
3
|
import type { NodeType } from '../types';
|
|
4
4
|
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig, RuleSettings, Telemetry, ThemeRawConfig } from './types';
|
|
5
5
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
@@ -31,7 +31,7 @@ export declare class StyleguideConfig {
|
|
|
31
31
|
preprocessors: string[];
|
|
32
32
|
decorators: string[];
|
|
33
33
|
};
|
|
34
|
-
getRulesForOasVersion(version: SpecMajorVersion): Oas3RuleSet[] | Oas2RuleSet[] |
|
|
34
|
+
getRulesForOasVersion(version: SpecMajorVersion): Oas3RuleSet[] | Oas2RuleSet[] | Async3RuleSet[] | ArazzoRuleSet[];
|
|
35
35
|
skipRules(rules?: string[]): void;
|
|
36
36
|
skipPreprocessors(preprocessors?: string[]): void;
|
|
37
37
|
skipDecorators(decorators?: string[]): void;
|
package/lib/config/config.js
CHANGED
|
@@ -33,25 +33,28 @@ class StyleguideConfig {
|
|
|
33
33
|
this.doNotResolveExamples = !!rawConfig.doNotResolveExamples;
|
|
34
34
|
this.recommendedFallback = rawConfig.recommendedFallback || false;
|
|
35
35
|
this.rules = {
|
|
36
|
-
[oas_types_1.SpecVersion.OAS2]:
|
|
37
|
-
[oas_types_1.SpecVersion.OAS3_0]:
|
|
38
|
-
[oas_types_1.SpecVersion.OAS3_1]:
|
|
39
|
-
[oas_types_1.SpecVersion.Async2]:
|
|
40
|
-
[oas_types_1.SpecVersion.
|
|
36
|
+
[oas_types_1.SpecVersion.OAS2]: { ...rawConfig.rules, ...rawConfig.oas2Rules },
|
|
37
|
+
[oas_types_1.SpecVersion.OAS3_0]: { ...rawConfig.rules, ...rawConfig.oas3_0Rules },
|
|
38
|
+
[oas_types_1.SpecVersion.OAS3_1]: { ...rawConfig.rules, ...rawConfig.oas3_1Rules },
|
|
39
|
+
[oas_types_1.SpecVersion.Async2]: { ...rawConfig.rules, ...rawConfig.async2Rules },
|
|
40
|
+
[oas_types_1.SpecVersion.Async3]: { ...rawConfig.rules, ...rawConfig.async3Rules },
|
|
41
|
+
[oas_types_1.SpecVersion.Arazzo]: { ...rawConfig.arazzoRules },
|
|
41
42
|
};
|
|
42
43
|
this.preprocessors = {
|
|
43
|
-
[oas_types_1.SpecVersion.OAS2]:
|
|
44
|
-
[oas_types_1.SpecVersion.OAS3_0]:
|
|
45
|
-
[oas_types_1.SpecVersion.OAS3_1]:
|
|
46
|
-
[oas_types_1.SpecVersion.Async2]:
|
|
47
|
-
[oas_types_1.SpecVersion.
|
|
44
|
+
[oas_types_1.SpecVersion.OAS2]: { ...rawConfig.preprocessors, ...rawConfig.oas2Preprocessors },
|
|
45
|
+
[oas_types_1.SpecVersion.OAS3_0]: { ...rawConfig.preprocessors, ...rawConfig.oas3_0Preprocessors },
|
|
46
|
+
[oas_types_1.SpecVersion.OAS3_1]: { ...rawConfig.preprocessors, ...rawConfig.oas3_1Preprocessors },
|
|
47
|
+
[oas_types_1.SpecVersion.Async2]: { ...rawConfig.preprocessors, ...rawConfig.async2Preprocessors },
|
|
48
|
+
[oas_types_1.SpecVersion.Async3]: { ...rawConfig.preprocessors, ...rawConfig.async3Preprocessors },
|
|
49
|
+
[oas_types_1.SpecVersion.Arazzo]: { ...rawConfig.arazzoPreprocessors },
|
|
48
50
|
};
|
|
49
51
|
this.decorators = {
|
|
50
|
-
[oas_types_1.SpecVersion.OAS2]:
|
|
51
|
-
[oas_types_1.SpecVersion.OAS3_0]:
|
|
52
|
-
[oas_types_1.SpecVersion.OAS3_1]:
|
|
53
|
-
[oas_types_1.SpecVersion.Async2]:
|
|
54
|
-
[oas_types_1.SpecVersion.
|
|
52
|
+
[oas_types_1.SpecVersion.OAS2]: { ...rawConfig.decorators, ...rawConfig.oas2Decorators },
|
|
53
|
+
[oas_types_1.SpecVersion.OAS3_0]: { ...rawConfig.decorators, ...rawConfig.oas3_0Decorators },
|
|
54
|
+
[oas_types_1.SpecVersion.OAS3_1]: { ...rawConfig.decorators, ...rawConfig.oas3_1Decorators },
|
|
55
|
+
[oas_types_1.SpecVersion.Async2]: { ...rawConfig.decorators, ...rawConfig.async2Decorators },
|
|
56
|
+
[oas_types_1.SpecVersion.Async3]: { ...rawConfig.decorators, ...rawConfig.async3Decorators },
|
|
57
|
+
[oas_types_1.SpecVersion.Arazzo]: { ...rawConfig.arazzoDecorators },
|
|
55
58
|
};
|
|
56
59
|
this.extendPaths = rawConfig.extendPaths || [];
|
|
57
60
|
this.pluginPaths = rawConfig.pluginPaths || [];
|
|
@@ -105,7 +108,11 @@ class StyleguideConfig {
|
|
|
105
108
|
const ruleIgnore = fileIgnore[problem.ruleId];
|
|
106
109
|
const ignored = ruleIgnore && ruleIgnore.has(loc.pointer);
|
|
107
110
|
return ignored
|
|
108
|
-
?
|
|
111
|
+
? {
|
|
112
|
+
...problem,
|
|
113
|
+
ignored,
|
|
114
|
+
}
|
|
115
|
+
: problem;
|
|
109
116
|
}
|
|
110
117
|
extendTypes(types, version) {
|
|
111
118
|
let extendedTypes = types;
|
|
@@ -128,6 +135,11 @@ class StyleguideConfig {
|
|
|
128
135
|
continue;
|
|
129
136
|
extendedTypes = plugin.typeExtension.async2(extendedTypes, version);
|
|
130
137
|
break;
|
|
138
|
+
case oas_types_1.SpecVersion.Async3:
|
|
139
|
+
if (!plugin.typeExtension.async3)
|
|
140
|
+
continue;
|
|
141
|
+
extendedTypes = plugin.typeExtension.async3(extendedTypes, version);
|
|
142
|
+
break;
|
|
131
143
|
case oas_types_1.SpecVersion.Arazzo:
|
|
132
144
|
if (!plugin.typeExtension.arazzo)
|
|
133
145
|
continue;
|
|
@@ -150,7 +162,7 @@ class StyleguideConfig {
|
|
|
150
162
|
};
|
|
151
163
|
}
|
|
152
164
|
else {
|
|
153
|
-
return
|
|
165
|
+
return { severity: 'error', ...settings };
|
|
154
166
|
}
|
|
155
167
|
}
|
|
156
168
|
getPreprocessorSettings(ruleId, oasVersion) {
|
|
@@ -163,7 +175,7 @@ class StyleguideConfig {
|
|
|
163
175
|
};
|
|
164
176
|
}
|
|
165
177
|
else {
|
|
166
|
-
return
|
|
178
|
+
return { severity: 'error', ...settings };
|
|
167
179
|
}
|
|
168
180
|
}
|
|
169
181
|
getDecoratorSettings(ruleId, oasVersion) {
|
|
@@ -176,7 +188,7 @@ class StyleguideConfig {
|
|
|
176
188
|
};
|
|
177
189
|
}
|
|
178
190
|
else {
|
|
179
|
-
return
|
|
191
|
+
return { severity: 'error', ...settings };
|
|
180
192
|
}
|
|
181
193
|
}
|
|
182
194
|
getUnusedRules() {
|
|
@@ -199,30 +211,37 @@ class StyleguideConfig {
|
|
|
199
211
|
case oas_types_1.SpecMajorVersion.OAS3:
|
|
200
212
|
// eslint-disable-next-line no-case-declarations
|
|
201
213
|
const oas3Rules = []; // default ruleset
|
|
202
|
-
this.plugins.forEach((p) =>
|
|
203
|
-
this.plugins.forEach((p) =>
|
|
204
|
-
this.plugins.forEach((p) =>
|
|
214
|
+
this.plugins.forEach((p) => p.preprocessors?.oas3 && oas3Rules.push(p.preprocessors.oas3));
|
|
215
|
+
this.plugins.forEach((p) => p.rules?.oas3 && oas3Rules.push(p.rules.oas3));
|
|
216
|
+
this.plugins.forEach((p) => p.decorators?.oas3 && oas3Rules.push(p.decorators.oas3));
|
|
205
217
|
return oas3Rules;
|
|
206
218
|
case oas_types_1.SpecMajorVersion.OAS2:
|
|
207
219
|
// eslint-disable-next-line no-case-declarations
|
|
208
220
|
const oas2Rules = []; // default ruleset
|
|
209
|
-
this.plugins.forEach((p) =>
|
|
210
|
-
this.plugins.forEach((p) =>
|
|
211
|
-
this.plugins.forEach((p) =>
|
|
221
|
+
this.plugins.forEach((p) => p.preprocessors?.oas2 && oas2Rules.push(p.preprocessors.oas2));
|
|
222
|
+
this.plugins.forEach((p) => p.rules?.oas2 && oas2Rules.push(p.rules.oas2));
|
|
223
|
+
this.plugins.forEach((p) => p.decorators?.oas2 && oas2Rules.push(p.decorators.oas2));
|
|
212
224
|
return oas2Rules;
|
|
213
225
|
case oas_types_1.SpecMajorVersion.Async2:
|
|
214
226
|
// eslint-disable-next-line no-case-declarations
|
|
215
|
-
const
|
|
216
|
-
this.plugins.forEach((p) =>
|
|
217
|
-
this.plugins.forEach((p) =>
|
|
218
|
-
this.plugins.forEach((p) =>
|
|
219
|
-
return
|
|
227
|
+
const asyncApi2Rules = []; // default ruleset
|
|
228
|
+
this.plugins.forEach((p) => p.preprocessors?.async2 && asyncApi2Rules.push(p.preprocessors.async2));
|
|
229
|
+
this.plugins.forEach((p) => p.rules?.async2 && asyncApi2Rules.push(p.rules.async2));
|
|
230
|
+
this.plugins.forEach((p) => p.decorators?.async2 && asyncApi2Rules.push(p.decorators.async2));
|
|
231
|
+
return asyncApi2Rules;
|
|
232
|
+
case oas_types_1.SpecMajorVersion.Async3:
|
|
233
|
+
// eslint-disable-next-line no-case-declarations
|
|
234
|
+
const asyncApi3Rules = []; // default ruleset
|
|
235
|
+
this.plugins.forEach((p) => p.preprocessors?.async3 && asyncApi3Rules.push(p.preprocessors.async3));
|
|
236
|
+
this.plugins.forEach((p) => p.rules?.async3 && asyncApi3Rules.push(p.rules.async3));
|
|
237
|
+
this.plugins.forEach((p) => p.decorators?.async3 && asyncApi3Rules.push(p.decorators.async3));
|
|
238
|
+
return asyncApi3Rules;
|
|
220
239
|
case oas_types_1.SpecMajorVersion.Arazzo:
|
|
221
240
|
// eslint-disable-next-line no-case-declarations
|
|
222
241
|
const arazzoRules = []; // default ruleset
|
|
223
|
-
this.plugins.forEach((p) =>
|
|
224
|
-
this.plugins.forEach((p) =>
|
|
225
|
-
this.plugins.forEach((p) =>
|
|
242
|
+
this.plugins.forEach((p) => p.preprocessors?.arazzo && arazzoRules.push(p.preprocessors.arazzo));
|
|
243
|
+
this.plugins.forEach((p) => p.rules?.arazzo && arazzoRules.push(p.rules.arazzo));
|
|
244
|
+
this.plugins.forEach((p) => p.decorators?.arazzo && arazzoRules.push(p.decorators.arazzo));
|
|
226
245
|
return arazzoRules;
|
|
227
246
|
}
|
|
228
247
|
}
|
|
@@ -262,7 +281,7 @@ class Config {
|
|
|
262
281
|
this.apis = rawConfig.apis || {};
|
|
263
282
|
this.styleguide = new StyleguideConfig(rawConfig.styleguide || {}, configFile);
|
|
264
283
|
this.theme = rawConfig.theme || {};
|
|
265
|
-
this.resolve = (0, utils_2.getResolveConfig)(rawConfig
|
|
284
|
+
this.resolve = (0, utils_2.getResolveConfig)(rawConfig?.resolve);
|
|
266
285
|
this.region = rawConfig.region;
|
|
267
286
|
this.organization = rawConfig.organization;
|
|
268
287
|
this.files = rawConfig.files || [];
|
package/lib/config/load.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import { BaseResolver } from '../resolve';
|
|
3
|
-
import type { Document } from '../resolve';
|
|
3
|
+
import type { Document, ResolvedRefMap } from '../resolve';
|
|
4
4
|
import type { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
|
|
5
5
|
import type { RawConfig, RawUniversalConfig, Region } from './types';
|
|
6
|
-
import type { ResolvedRefMap } from '../resolve';
|
|
7
6
|
export type RawConfigProcessor = (params: {
|
|
8
7
|
document: Document;
|
|
9
8
|
resolvedRefMap: ResolvedRefMap;
|