@redocly/openapi-core 1.0.0-beta.106 → 1.0.0-beta.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +9 -6
- package/lib/config/all.js +5 -3
- package/lib/config/config-resolvers.js +32 -14
- package/lib/config/config.d.ts +3 -5
- package/lib/config/config.js +7 -4
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +14 -6
- package/lib/config/minimal.js +7 -4
- package/lib/config/recommended.js +7 -4
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +7 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +49 -11
- package/lib/decorators/common/registry-dependencies.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.d.ts +1 -1
- package/lib/format/format.js +49 -26
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -1
- package/lib/js-yaml/index.js +1 -0
- package/lib/lint.js +2 -2
- 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 +3 -3
- package/lib/redocly/registry-api.js +7 -1
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +4 -2
- 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/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- 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 +1 -1
- package/lib/rules/common/operation-4xx-response.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
- package/lib/rules/common/spec.js +14 -3
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +1 -1
- package/lib/rules/oas2/index.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/index.js +8 -4
- 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} +5 -5
- package/lib/rules/oas3/no-unused-components.js +2 -2
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/remove-unused-components.js +4 -4
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +2 -2
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +16 -4
- package/lib/types/oas2.js +5 -5
- package/lib/types/oas3.js +27 -20
- package/lib/types/oas3_1.js +3 -3
- package/lib/types/redocly-yaml.js +47 -56
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +24 -7
- package/lib/visitors.d.ts +12 -12
- package/lib/visitors.js +15 -3
- 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 +3 -3
- package/src/__tests__/fixtures/extension.js +3 -3
- package/src/__tests__/format.test.ts +76 -0
- package/src/__tests__/lint.test.ts +106 -131
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +10 -7
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
- package/src/config/__tests__/config.test.ts +35 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
- package/src/config/__tests__/load.test.ts +76 -1
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +5 -3
- package/src/config/config-resolvers.ts +45 -19
- package/src/config/config.ts +10 -8
- package/src/config/load.ts +31 -7
- package/src/config/minimal.ts +7 -4
- package/src/config/recommended.ts +7 -4
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +11 -0
- package/src/config/utils.ts +115 -25
- package/src/decorators/common/registry-dependencies.ts +2 -2
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +15 -9
- package/src/format/format.ts +59 -34
- package/src/index.ts +6 -4
- package/src/js-yaml/index.ts +1 -0
- package/src/lint.ts +2 -2
- package/src/logger.ts +34 -0
- package/src/output.ts +7 -0
- package/src/redocly/index.ts +7 -4
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +18 -7
- package/src/ref-utils.ts +2 -1
- package/src/resolve.ts +7 -5
- package/src/rules/__tests__/utils.test.ts +39 -1
- package/src/rules/ajv.ts +7 -7
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
- package/src/rules/common/__tests__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec.test.ts +79 -0
- package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +1 -1
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- 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-2xx-response.ts +1 -1
- package/src/rules/common/operation-4xx-response.ts +1 -1
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-tag-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
- package/src/rules/common/spec.ts +17 -3
- package/src/rules/common/tags-alphabetical.ts +1 -1
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +3 -3
- package/src/rules/oas2/request-mime-type.ts +1 -1
- package/src/rules/oas2/response-mime-type.ts +1 -1
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
- package/src/rules/oas3/index.ts +8 -4
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
- package/src/rules/oas3/no-unused-components.ts +2 -2
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +5 -5
- package/src/rules/oas3/request-mime-type.ts +1 -1
- package/src/rules/oas3/response-mime-type.ts +1 -1
- package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
- package/src/rules/other/stats.ts +2 -2
- package/src/rules/utils.ts +17 -3
- package/src/types/index.ts +2 -2
- package/src/types/oas2.ts +5 -5
- package/src/types/oas3.ts +27 -20
- package/src/types/oas3_1.ts +3 -3
- package/src/types/redocly-yaml.ts +53 -41
- package/src/utils.ts +31 -4
- package/src/visitors.ts +34 -18
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
|
@@ -16,7 +16,7 @@ function measureAsync() {
|
|
|
16
16
|
return resolve_1.resolveDocument({
|
|
17
17
|
rootDocument: rebillyDocument,
|
|
18
18
|
externalRefResolver,
|
|
19
|
-
rootType: types_1.normalizeTypes(oas3_1.Oas3Types).
|
|
19
|
+
rootType: types_1.normalizeTypes(oas3_1.Oas3Types).Root,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
exports.measureAsync = measureAsync;
|
package/lib/bundle.d.ts
CHANGED
|
@@ -44,4 +44,4 @@ export declare function bundleDocument(opts: {
|
|
|
44
44
|
refTypes: Map<string, NormalizedNodeType> | undefined;
|
|
45
45
|
visitorsData: Record<string, Record<string, unknown>>;
|
|
46
46
|
}>;
|
|
47
|
-
export declare function mapTypeToComponent(typeName: string, version: OasMajorVersion): "headers" | "definitions" | "parameters" | "examples" | "responses" | "schemas" | "requestBodies" | "
|
|
47
|
+
export declare function mapTypeToComponent(typeName: string, version: OasMajorVersion): "headers" | "definitions" | "parameters" | "examples" | "responses" | "schemas" | "requestBodies" | "links" | "callbacks" | "securitySchemes" | null;
|
package/lib/bundle.js
CHANGED
|
@@ -76,7 +76,7 @@ function bundleDocument(opts) {
|
|
|
76
76
|
}
|
|
77
77
|
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
78
78
|
rootDocument: document,
|
|
79
|
-
rootType: types.
|
|
79
|
+
rootType: types.Root,
|
|
80
80
|
externalRefResolver,
|
|
81
81
|
});
|
|
82
82
|
const bundleVisitor = visitors_1.normalizeVisitors([
|
|
@@ -90,7 +90,7 @@ function bundleDocument(opts) {
|
|
|
90
90
|
], types);
|
|
91
91
|
walk_1.walkDocument({
|
|
92
92
|
document,
|
|
93
|
-
rootType: types.
|
|
93
|
+
rootType: types.Root,
|
|
94
94
|
normalizedVisitors: bundleVisitor,
|
|
95
95
|
resolvedRefMap,
|
|
96
96
|
ctx,
|
|
@@ -99,7 +99,7 @@ function bundleDocument(opts) {
|
|
|
99
99
|
bundle: document,
|
|
100
100
|
problems: ctx.problems.map((problem) => config.addProblemToIgnore(problem)),
|
|
101
101
|
fileDependencies: externalRefResolver.getFiles(),
|
|
102
|
-
rootType: types.
|
|
102
|
+
rootType: types.Root,
|
|
103
103
|
refTypes: ctx.refTypes,
|
|
104
104
|
visitorsData: ctx.visitorsData,
|
|
105
105
|
};
|
|
@@ -184,7 +184,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
},
|
|
187
|
-
|
|
187
|
+
Root: {
|
|
188
188
|
enter(root) {
|
|
189
189
|
if (version === oas_types_1.OasMajorVersion.Version3) {
|
|
190
190
|
components = root.components = root.components || {};
|
|
@@ -231,9 +231,12 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
231
231
|
ctx.parent[ctx.key] = resolved.node;
|
|
232
232
|
}
|
|
233
233
|
else {
|
|
234
|
+
// TODO: why $ref isn't optional in OasRef?
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
234
236
|
// @ts-ignore
|
|
235
237
|
delete ref.$ref;
|
|
236
|
-
Object.assign(
|
|
238
|
+
const obj = Object.assign({}, resolved.node, ref);
|
|
239
|
+
Object.assign(ref, obj); // assign ref itself again so ref fields take precedence
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
function saveComponent(componentType, target, ctx) {
|
|
@@ -259,7 +262,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
|
|
|
259
262
|
const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
|
|
260
263
|
const componentsGroup = components[componentType];
|
|
261
264
|
let name = '';
|
|
262
|
-
const refParts = pointer.slice(2).split('/').filter(
|
|
265
|
+
const refParts = pointer.slice(2).split('/').filter(utils_1.isTruthy); // slice(2) removes "#/"
|
|
263
266
|
while (refParts.length > 0) {
|
|
264
267
|
name = refParts.pop() + (name ? `-${name}` : '');
|
|
265
268
|
if (!componentsGroup ||
|
package/lib/config/all.js
CHANGED
|
@@ -26,7 +26,7 @@ exports.default = {
|
|
|
26
26
|
'operation-operationId-url-safe': 'error',
|
|
27
27
|
'operation-parameters-unique': 'error',
|
|
28
28
|
'operation-tag-defined': 'error',
|
|
29
|
-
'
|
|
29
|
+
'security-defined': 'error',
|
|
30
30
|
'operation-singular-tag': 'error',
|
|
31
31
|
'no-unresolved-refs': 'error',
|
|
32
32
|
'no-enum-type-mismatch': 'error',
|
|
@@ -51,7 +51,8 @@ exports.default = {
|
|
|
51
51
|
'no-example-value-and-externalValue': 'error',
|
|
52
52
|
'no-unused-components': 'error',
|
|
53
53
|
'no-undefined-server-variable': 'error',
|
|
54
|
-
'no-
|
|
54
|
+
'no-server-variables-empty-enum': 'error',
|
|
55
|
+
'operation-4xx-problem-details-rfc7807': 'error',
|
|
55
56
|
},
|
|
56
57
|
oas3_1Rules: {
|
|
57
58
|
'no-server-example.com': 'error',
|
|
@@ -60,6 +61,7 @@ exports.default = {
|
|
|
60
61
|
'no-example-value-and-externalValue': 'error',
|
|
61
62
|
'no-unused-components': 'error',
|
|
62
63
|
'no-undefined-server-variable': 'error',
|
|
63
|
-
'no-
|
|
64
|
+
'no-server-variables-empty-enum': 'error',
|
|
65
|
+
'operation-4xx-problem-details-rfc7807': 'error',
|
|
64
66
|
},
|
|
65
67
|
};
|
|
@@ -22,13 +22,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.resolvePreset = exports.resolveStyleguideConfig = exports.resolveApis = exports.resolvePlugins = exports.resolveConfig = void 0;
|
|
24
24
|
const path = require("path");
|
|
25
|
-
const colorette_1 = require("colorette");
|
|
26
25
|
const ref_utils_1 = require("../ref-utils");
|
|
27
26
|
const resolve_1 = require("../resolve");
|
|
28
27
|
const builtIn_1 = require("./builtIn");
|
|
29
28
|
const utils_1 = require("./utils");
|
|
29
|
+
const env_1 = require("../env");
|
|
30
30
|
const utils_2 = require("../utils");
|
|
31
31
|
const config_1 = require("./config");
|
|
32
|
+
const logger_1 = require("../logger");
|
|
32
33
|
function resolveConfig(rawConfig, configPath) {
|
|
33
34
|
var _a, _b, _c, _d, _e;
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -57,25 +58,42 @@ exports.resolveConfig = resolveConfig;
|
|
|
57
58
|
function resolvePlugins(plugins, configPath = '') {
|
|
58
59
|
if (!plugins)
|
|
59
60
|
return [];
|
|
60
|
-
//
|
|
61
|
-
const requireFunc =
|
|
61
|
+
// TODO: implement or reuse Resolver approach so it will work in node and browser envs
|
|
62
|
+
const requireFunc = (plugin) => {
|
|
63
|
+
if (env_1.isBrowser && utils_2.isString(plugin)) {
|
|
64
|
+
logger_1.logger.error(`Cannot load ${plugin}. Plugins aren't supported in browser yet.`);
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (utils_2.isString(plugin)) {
|
|
68
|
+
const absoltePluginPath = path.resolve(path.dirname(configPath), plugin);
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return typeof __webpack_require__ === 'function'
|
|
72
|
+
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
__non_webpack_require__(absoltePluginPath)
|
|
75
|
+
: require(absoltePluginPath);
|
|
76
|
+
}
|
|
77
|
+
return plugin;
|
|
78
|
+
};
|
|
62
79
|
const seenPluginIds = new Map();
|
|
63
80
|
return plugins
|
|
64
81
|
.map((p) => {
|
|
65
82
|
if (utils_2.isString(p) && ref_utils_1.isAbsoluteUrl(p)) {
|
|
66
|
-
throw new Error(
|
|
83
|
+
throw new Error(logger_1.colorize.red(`We don't support remote plugins yet.`));
|
|
67
84
|
}
|
|
68
85
|
// TODO: resolve npm packages similar to eslint
|
|
69
|
-
const pluginModule =
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
const pluginModule = requireFunc(p);
|
|
87
|
+
if (!pluginModule) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
72
90
|
const id = pluginModule.id;
|
|
73
91
|
if (typeof id !== 'string') {
|
|
74
|
-
throw new Error(
|
|
92
|
+
throw new Error(logger_1.colorize.red(`Plugin must define \`id\` property in ${logger_1.colorize.blue(p.toString())}.`));
|
|
75
93
|
}
|
|
76
94
|
if (seenPluginIds.has(id)) {
|
|
77
95
|
const pluginPath = seenPluginIds.get(id);
|
|
78
|
-
throw new Error(
|
|
96
|
+
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)}`));
|
|
79
97
|
}
|
|
80
98
|
seenPluginIds.set(id, p.toString());
|
|
81
99
|
const plugin = Object.assign(Object.assign({ id }, (pluginModule.configs ? { configs: pluginModule.configs } : {})), (pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}));
|
|
@@ -117,14 +135,14 @@ function resolvePlugins(plugins, configPath = '') {
|
|
|
117
135
|
}
|
|
118
136
|
return plugin;
|
|
119
137
|
})
|
|
120
|
-
.filter(utils_2.
|
|
138
|
+
.filter(utils_2.isDefined);
|
|
121
139
|
}
|
|
122
140
|
exports.resolvePlugins = resolvePlugins;
|
|
123
141
|
function resolveApis({ rawConfig, configPath = '', resolver, }) {
|
|
124
142
|
var _a, _b;
|
|
125
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
144
|
const { apis = {}, styleguide: styleguideConfig = {} } = rawConfig;
|
|
127
|
-
|
|
145
|
+
const resolvedApis = {};
|
|
128
146
|
for (const [apiName, apiContent] of Object.entries(apis || {})) {
|
|
129
147
|
if ((_b = (_a = apiContent.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_2.isNotString)) {
|
|
130
148
|
throw new Error(`Error configuration format not detected in extends value must contain strings`);
|
|
@@ -188,13 +206,13 @@ function resolvePreset(presetName, plugins) {
|
|
|
188
206
|
const { pluginId, configName } = utils_1.parsePresetName(presetName);
|
|
189
207
|
const plugin = plugins.find((p) => p.id === pluginId);
|
|
190
208
|
if (!plugin) {
|
|
191
|
-
throw new Error(`Invalid config ${
|
|
209
|
+
throw new Error(`Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} is not included.`);
|
|
192
210
|
}
|
|
193
211
|
const preset = (_a = plugin.configs) === null || _a === void 0 ? void 0 : _a[configName];
|
|
194
212
|
if (!preset) {
|
|
195
213
|
throw new Error(pluginId
|
|
196
|
-
? `Invalid config ${
|
|
197
|
-
: `Invalid config ${
|
|
214
|
+
? `Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
|
|
215
|
+
: `Invalid config ${logger_1.colorize.red(presetName)}: there is no such built-in config.`);
|
|
198
216
|
}
|
|
199
217
|
return preset;
|
|
200
218
|
}
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { NormalizedProblem } from '../walk';
|
|
3
2
|
import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
|
|
4
3
|
import type { NodeType } from '../types';
|
|
5
4
|
import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig } from './types';
|
|
6
|
-
export declare const env: NodeJS.ProcessEnv;
|
|
7
5
|
export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
|
|
8
6
|
export declare const DEFAULT_REGION = "us";
|
|
9
7
|
export declare const DOMAINS: {
|
|
@@ -32,13 +30,13 @@ export declare class StyleguideConfig {
|
|
|
32
30
|
addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
|
|
33
31
|
extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
|
|
34
32
|
getRuleSettings(ruleId: string, oasVersion: OasVersion): {
|
|
35
|
-
severity:
|
|
33
|
+
severity: string;
|
|
36
34
|
};
|
|
37
35
|
getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
38
|
-
severity:
|
|
36
|
+
severity: string;
|
|
39
37
|
};
|
|
40
38
|
getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
|
|
41
|
-
severity:
|
|
39
|
+
severity: string;
|
|
42
40
|
};
|
|
43
41
|
getUnusedRules(): {
|
|
44
42
|
rules: string[];
|
package/lib/config/config.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE =
|
|
3
|
+
exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const js_yaml_1 = require("../js-yaml");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const oas_types_1 = require("../oas-types");
|
|
9
|
+
const env_1 = require("../env");
|
|
9
10
|
const utils_2 = require("./utils");
|
|
10
|
-
// Alias environment here so this file can work in browser environments too.
|
|
11
|
-
exports.env = typeof process !== 'undefined' ? process.env || {} : {};
|
|
12
11
|
exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
|
|
13
12
|
const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
|
|
14
13
|
`# See https://redoc.ly/docs/cli/ for more information.\n`;
|
|
@@ -19,7 +18,7 @@ function getDomains() {
|
|
|
19
18
|
eu: 'eu.redocly.com',
|
|
20
19
|
};
|
|
21
20
|
// FIXME: temporary fix for our lab environments
|
|
22
|
-
const domain =
|
|
21
|
+
const domain = env_1.env.REDOCLY_DOMAIN;
|
|
23
22
|
if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
|
|
24
23
|
domains[domain.split('.')[0]] = domain;
|
|
25
24
|
}
|
|
@@ -125,10 +124,12 @@ class StyleguideConfig {
|
|
|
125
124
|
if (!plugin.typeExtension.oas3)
|
|
126
125
|
continue;
|
|
127
126
|
extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
|
|
127
|
+
break;
|
|
128
128
|
case oas_types_1.OasVersion.Version2:
|
|
129
129
|
if (!plugin.typeExtension.oas2)
|
|
130
130
|
continue;
|
|
131
131
|
extendedTypes = plugin.typeExtension.oas2(extendedTypes, version);
|
|
132
|
+
break;
|
|
132
133
|
default:
|
|
133
134
|
throw new Error('Not implemented');
|
|
134
135
|
}
|
|
@@ -193,12 +194,14 @@ class StyleguideConfig {
|
|
|
193
194
|
getRulesForOasVersion(version) {
|
|
194
195
|
switch (version) {
|
|
195
196
|
case oas_types_1.OasMajorVersion.Version3:
|
|
197
|
+
// eslint-disable-next-line no-case-declarations
|
|
196
198
|
const oas3Rules = []; // default ruleset
|
|
197
199
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.preprocessors.oas3); });
|
|
198
200
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.rules.oas3); });
|
|
199
201
|
this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.decorators.oas3); });
|
|
200
202
|
return oas3Rules;
|
|
201
203
|
case oas_types_1.OasMajorVersion.Version2:
|
|
204
|
+
// eslint-disable-next-line no-case-declarations
|
|
202
205
|
const oas2Rules = []; // default ruleset
|
|
203
206
|
this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.preprocessors.oas2); });
|
|
204
207
|
this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.rules.oas2); });
|
package/lib/config/load.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import type { RawConfig } from './types';
|
|
3
|
+
import { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
|
|
3
4
|
export declare function loadConfig(configPath?: string | undefined, customExtends?: string[], processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>): Promise<Config>;
|
|
4
5
|
export declare const CONFIG_FILE_NAMES: string[];
|
|
5
6
|
export declare function findConfig(dir?: string): string | undefined;
|
|
6
7
|
export declare function getConfig(configPath?: string | undefined): Promise<RawConfig>;
|
|
8
|
+
declare type CreateConfigOptions = {
|
|
9
|
+
extends?: string[];
|
|
10
|
+
tokens?: RegionalTokenWithValidity[];
|
|
11
|
+
};
|
|
12
|
+
export declare function createConfig(config: string | RawConfig, options?: CreateConfigOptions): Promise<Config>;
|
|
13
|
+
export {};
|
package/lib/config/load.js
CHANGED
|
@@ -9,15 +9,16 @@ 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) {
|
|
@@ -28,9 +29,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, }) {
|
|
|
28
29
|
// TODO: check if we can add recommended here. add message here?
|
|
29
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
|
}
|
|
@@ -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.js
CHANGED
|
@@ -24,7 +24,7 @@ exports.default = {
|
|
|
24
24
|
'operation-operationId-unique': 'warn',
|
|
25
25
|
'operation-parameters-unique': 'warn',
|
|
26
26
|
'operation-tag-defined': 'off',
|
|
27
|
-
'
|
|
27
|
+
'security-defined': 'warn',
|
|
28
28
|
'operation-operationId-url-safe': 'warn',
|
|
29
29
|
'operation-singular-tag': 'off',
|
|
30
30
|
'no-unresolved-refs': '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,18 @@ 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
|
+
'spec-components-invalid-map-name': 'warn',
|
|
48
49
|
},
|
|
49
50
|
oas3_1Rules: {
|
|
51
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
52
|
'no-server-example.com': 'warn',
|
|
51
53
|
'no-server-trailing-slash': 'error',
|
|
52
54
|
'no-empty-servers': 'warn',
|
|
53
55
|
'no-example-value-and-externalValue': 'warn',
|
|
54
56
|
'no-unused-components': 'warn',
|
|
55
57
|
'no-undefined-server-variable': 'warn',
|
|
56
|
-
'no-
|
|
58
|
+
'no-server-variables-empty-enum': 'error',
|
|
59
|
+
'spec-components-invalid-map-name': 'warn',
|
|
57
60
|
},
|
|
58
61
|
};
|
|
@@ -25,7 +25,7 @@ exports.default = {
|
|
|
25
25
|
'operation-operationId-url-safe': 'error',
|
|
26
26
|
'operation-parameters-unique': 'error',
|
|
27
27
|
'operation-tag-defined': 'off',
|
|
28
|
-
'
|
|
28
|
+
'security-defined': 'error',
|
|
29
29
|
'operation-singular-tag': 'off',
|
|
30
30
|
'no-unresolved-refs': 'error',
|
|
31
31
|
'no-enum-type-mismatch': '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,18 @@ 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
|
+
'spec-components-invalid-map-name': 'error',
|
|
48
49
|
},
|
|
49
50
|
oas3_1Rules: {
|
|
51
|
+
'no-invalid-media-type-examples': 'warn',
|
|
50
52
|
'no-server-example.com': 'warn',
|
|
51
53
|
'no-server-trailing-slash': 'error',
|
|
52
54
|
'no-empty-servers': 'error',
|
|
53
55
|
'no-example-value-and-externalValue': 'error',
|
|
54
56
|
'no-unused-components': 'warn',
|
|
55
57
|
'no-undefined-server-variable': 'error',
|
|
56
|
-
'no-
|
|
58
|
+
'no-server-variables-empty-enum': 'error',
|
|
59
|
+
'spec-components-invalid-map-name': 'error',
|
|
57
60
|
},
|
|
58
61
|
};
|
package/lib/config/rules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RuleSet, OasVersion } from '../oas-types';
|
|
2
2
|
import { StyleguideConfig } from './config';
|
|
3
3
|
export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
|
|
4
|
-
severity:
|
|
4
|
+
severity: string;
|
|
5
5
|
ruleId: string;
|
|
6
6
|
visitor: any;
|
|
7
7
|
}[];
|
package/lib/config/rules.js
CHANGED
package/lib/config/types.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare type ResolveHeader = {
|
|
|
72
72
|
};
|
|
73
73
|
export declare type RawResolveConfig = {
|
|
74
74
|
http?: Partial<HttpResolveConfig>;
|
|
75
|
+
doNotResolveExamples?: boolean;
|
|
75
76
|
};
|
|
76
77
|
export declare type HttpResolveConfig = {
|
|
77
78
|
headers: ResolveHeader[];
|
|
@@ -87,6 +88,7 @@ export declare type AccessTokens = {
|
|
|
87
88
|
export declare type DeprecatedInRawConfig = {
|
|
88
89
|
apiDefinitions?: Record<string, string>;
|
|
89
90
|
lint?: StyleguideRawConfig;
|
|
91
|
+
styleguide?: StyleguideRawConfig;
|
|
90
92
|
referenceDocs?: Record<string, any>;
|
|
91
93
|
apis?: Record<string, Api & DeprecatedInApi>;
|
|
92
94
|
};
|
|
@@ -107,6 +109,11 @@ export declare type RawConfig = {
|
|
|
107
109
|
region?: Region;
|
|
108
110
|
organization?: string;
|
|
109
111
|
} & FeaturesConfig;
|
|
112
|
+
export declare type FlatApi = Omit<Api, 'styleguide'> & Omit<ApiStyleguideRawConfig, 'doNotResolveExamples'>;
|
|
113
|
+
export declare type FlatRawConfig = Omit<RawConfig, 'styleguide' | 'resolve' | 'apis'> & Omit<StyleguideRawConfig, 'doNotResolveExamples'> & {
|
|
114
|
+
resolve?: RawResolveConfig;
|
|
115
|
+
apis?: Record<string, FlatApi>;
|
|
116
|
+
};
|
|
110
117
|
export declare type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
|
|
111
118
|
apis: Record<string, ResolvedApi>;
|
|
112
119
|
styleguide: ResolvedStyleguideConfig;
|
package/lib/config/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
|
-
import type { Api, DeprecatedInRawConfig, Plugin, RawConfig, RawResolveConfig, ResolveConfig, ResolvedStyleguideConfig, RulesFields } from './types';
|
|
2
|
+
import type { Api, DeprecatedInRawConfig, FlatRawConfig, Plugin, RawConfig, RawResolveConfig, ResolveConfig, ResolvedStyleguideConfig, RulesFields } from './types';
|
|
3
3
|
export declare function parsePresetName(presetName: string): {
|
|
4
4
|
pluginId: string;
|
|
5
5
|
configName: string;
|
|
@@ -8,6 +8,6 @@ export declare function transformApiDefinitionsToApis(apiDefinitions?: Deprecate
|
|
|
8
8
|
export declare function prefixRules<T extends Record<string, any>>(rules: T, prefix: string): any;
|
|
9
9
|
export declare function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]): Omit<ResolvedStyleguideConfig, RulesFields> & Required<Pick<ResolvedStyleguideConfig, RulesFields>>;
|
|
10
10
|
export declare function getMergedConfig(config: Config, apiName?: string): Config;
|
|
11
|
-
export declare function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig;
|
|
11
|
+
export declare function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig & FlatRawConfig): 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('/');
|
|
@@ -35,13 +35,46 @@ function transformApiDefinitionsToApis(apiDefinitions) {
|
|
|
35
35
|
return apis;
|
|
36
36
|
}
|
|
37
37
|
exports.transformApiDefinitionsToApis = transformApiDefinitionsToApis;
|
|
38
|
+
function extractFlatConfig(_a) {
|
|
39
|
+
var _b;
|
|
40
|
+
var { plugins, extends: _extends, rules, oas2Rules, oas3_0Rules, oas3_1Rules, preprocessors, oas2Preprocessors, oas3_0Preprocessors, oas3_1Preprocessors, decorators, oas2Decorators, oas3_0Decorators, oas3_1Decorators } = _a, rawConfigRest = __rest(_a, ["plugins", "extends", "rules", "oas2Rules", "oas3_0Rules", "oas3_1Rules", "preprocessors", "oas2Preprocessors", "oas3_0Preprocessors", "oas3_1Preprocessors", "decorators", "oas2Decorators", "oas3_0Decorators", "oas3_1Decorators"]);
|
|
41
|
+
const styleguideConfig = {
|
|
42
|
+
plugins,
|
|
43
|
+
extends: _extends,
|
|
44
|
+
rules,
|
|
45
|
+
oas2Rules,
|
|
46
|
+
oas3_0Rules,
|
|
47
|
+
oas3_1Rules,
|
|
48
|
+
preprocessors,
|
|
49
|
+
oas2Preprocessors,
|
|
50
|
+
oas3_0Preprocessors,
|
|
51
|
+
oas3_1Preprocessors,
|
|
52
|
+
decorators,
|
|
53
|
+
oas2Decorators,
|
|
54
|
+
oas3_0Decorators,
|
|
55
|
+
oas3_1Decorators,
|
|
56
|
+
doNotResolveExamples: (_b = rawConfigRest.resolve) === null || _b === void 0 ? void 0 : _b.doNotResolveExamples,
|
|
57
|
+
};
|
|
58
|
+
if ((rawConfigRest.lint && rawConfigRest.styleguide) ||
|
|
59
|
+
(Object.values(styleguideConfig).some(utils_1.isDefined) &&
|
|
60
|
+
(rawConfigRest.lint || rawConfigRest.styleguide))) {
|
|
61
|
+
throw new Error(`Do not use 'lint', 'styleguide' and flat syntax together. \nSee more about the configuration in the docs: https://redocly.com/docs/cli/configuration/ \n`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
styleguideConfig: Object.values(styleguideConfig).some(utils_1.isDefined)
|
|
65
|
+
? styleguideConfig
|
|
66
|
+
: undefined,
|
|
67
|
+
rawConfigRest,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
38
70
|
function transformApis(legacyApis) {
|
|
39
71
|
if (!legacyApis)
|
|
40
72
|
return undefined;
|
|
41
73
|
const apis = {};
|
|
42
74
|
for (let _a of Object.entries(legacyApis)) {
|
|
43
75
|
const [apiName, _b] = _a, { lint } = _b, apiContent = __rest(_b, ["lint"]);
|
|
44
|
-
|
|
76
|
+
const { styleguideConfig, rawConfigRest } = extractFlatConfig(apiContent);
|
|
77
|
+
apis[apiName] = Object.assign({ styleguide: styleguideConfig || lint }, rawConfigRest);
|
|
45
78
|
}
|
|
46
79
|
return apis;
|
|
47
80
|
}
|
|
@@ -73,7 +106,7 @@ function mergeExtends(rulesConfList) {
|
|
|
73
106
|
pluginPaths: [],
|
|
74
107
|
extendPaths: [],
|
|
75
108
|
};
|
|
76
|
-
for (
|
|
109
|
+
for (const rulesConf of rulesConfList) {
|
|
77
110
|
if (rulesConf.extends) {
|
|
78
111
|
throw new Error(`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
|
|
79
112
|
}
|
|
@@ -112,13 +145,13 @@ function getMergedConfig(config, apiName) {
|
|
|
112
145
|
(_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.extendPaths,
|
|
113
146
|
]
|
|
114
147
|
.flat()
|
|
115
|
-
.filter(
|
|
148
|
+
.filter(utils_1.isTruthy);
|
|
116
149
|
const pluginPaths = [
|
|
117
150
|
...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
151
|
(_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.styleguide) === null || _d === void 0 ? void 0 : _d.pluginPaths,
|
|
119
152
|
]
|
|
120
153
|
.flat()
|
|
121
|
-
.filter(
|
|
154
|
+
.filter(utils_1.isTruthy);
|
|
122
155
|
return apiName
|
|
123
156
|
? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { styleguide: Object.assign(Object.assign({}, (config.apis[apiName]
|
|
124
157
|
? config.apis[apiName].styleguide
|
|
@@ -130,24 +163,29 @@ exports.getMergedConfig = getMergedConfig;
|
|
|
130
163
|
function checkForDeprecatedFields(deprecatedField, updatedField, rawConfig) {
|
|
131
164
|
const isDeprecatedFieldInApis = rawConfig.apis &&
|
|
132
165
|
Object.values(rawConfig.apis).some((api) => api[deprecatedField]);
|
|
133
|
-
if (rawConfig[deprecatedField] &&
|
|
134
|
-
|
|
166
|
+
if (rawConfig[deprecatedField] && updatedField === null) {
|
|
167
|
+
utils_1.showWarningForDeprecatedField(deprecatedField);
|
|
168
|
+
}
|
|
169
|
+
if (rawConfig[deprecatedField] && updatedField && rawConfig[updatedField]) {
|
|
170
|
+
utils_1.showErrorForDeprecatedField(deprecatedField, updatedField);
|
|
135
171
|
}
|
|
136
172
|
if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
|
|
137
|
-
|
|
173
|
+
utils_1.showWarningForDeprecatedField(deprecatedField, updatedField);
|
|
138
174
|
}
|
|
139
175
|
}
|
|
140
176
|
function transformConfig(rawConfig) {
|
|
141
177
|
const migratedFields = [
|
|
142
178
|
['apiDefinitions', 'apis'],
|
|
143
179
|
['referenceDocs', 'features.openapi'],
|
|
144
|
-
['lint',
|
|
180
|
+
['lint', undefined],
|
|
181
|
+
['styleguide', undefined],
|
|
145
182
|
];
|
|
146
183
|
for (const [deprecatedField, updatedField] of migratedFields) {
|
|
147
184
|
checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
|
|
148
185
|
}
|
|
149
186
|
const { apis, apiDefinitions, referenceDocs, lint } = rawConfig, rest = __rest(rawConfig, ["apis", "apiDefinitions", "referenceDocs", "lint"]);
|
|
150
|
-
|
|
187
|
+
const { styleguideConfig, rawConfigRest } = extractFlatConfig(rest);
|
|
188
|
+
return Object.assign({ 'features.openapi': referenceDocs, apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions), styleguide: styleguideConfig || lint }, rawConfigRest);
|
|
151
189
|
}
|
|
152
190
|
exports.transformConfig = transformConfig;
|
|
153
191
|
function getResolveConfig(resolve) {
|
|
@@ -169,7 +207,7 @@ function getUniquePlugins(plugins) {
|
|
|
169
207
|
seen.add(p.id);
|
|
170
208
|
}
|
|
171
209
|
else if (p.id) {
|
|
172
|
-
|
|
210
|
+
logger_1.logger.warn(`Duplicate plugin id "${logger_1.colorize.red(p.id)}".\n`);
|
|
173
211
|
}
|
|
174
212
|
}
|
|
175
213
|
return results;
|