@redocly/openapi-core 1.0.0-beta.107 → 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/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/bundle.js +5 -2
- package/lib/config/all.js +2 -2
- package/lib/config/config-resolvers.js +31 -13
- 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 +2 -2
- package/lib/config/recommended.js +2 -2
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/utils.js +5 -5
- package/lib/decorators/common/registry-dependencies.js +1 -1
- 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 +28 -26
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -1
- package/lib/js-yaml/index.js +1 -0
- 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 +7 -2
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- package/lib/rules/ajv.js +1 -1
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -1
- package/lib/rules/common/spec.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +2 -2
- package/lib/rules/oas3/index.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 +3 -3
- package/lib/rules/utils.d.ts +1 -1
- package/lib/rules/utils.js +1 -1
- package/lib/types/redocly-yaml.js +1 -1
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +15 -7
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -2
- package/package.json +1 -1
- 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__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
- package/src/bundle.ts +6 -3
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +4 -4
- package/src/config/__tests__/config.test.ts +35 -0
- package/src/config/__tests__/load.test.ts +79 -1
- package/src/config/all.ts +2 -2
- package/src/config/config-resolvers.ts +43 -17
- package/src/config/config.ts +10 -8
- package/src/config/load.ts +28 -5
- package/src/config/minimal.ts +2 -2
- package/src/config/recommended.ts +2 -2
- package/src/config/utils.ts +6 -5
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +15 -9
- package/src/format/format.ts +28 -33
- package/src/index.ts +6 -4
- package/src/js-yaml/index.ts +1 -0
- 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 +16 -6
- package/src/ref-utils.ts +2 -1
- package/src/resolve.ts +4 -4
- package/src/rules/ajv.ts +1 -1
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +1 -1
- package/src/rules/common/operation-security-defined.ts +1 -1
- package/src/rules/common/spec.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +2 -2
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/index.ts +2 -2
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +2 -2
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +4 -4
- package/src/rules/utils.ts +1 -1
- package/src/types/redocly-yaml.ts +1 -1
- package/src/utils.ts +16 -6
- package/src/visitors.ts +5 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
package/lib/bundle.js
CHANGED
|
@@ -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
|
@@ -51,7 +51,7 @@ 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
55
|
},
|
|
56
56
|
oas3_1Rules: {
|
|
57
57
|
'no-server-example.com': 'error',
|
|
@@ -60,6 +60,6 @@ exports.default = {
|
|
|
60
60
|
'no-example-value-and-externalValue': 'error',
|
|
61
61
|
'no-unused-components': 'error',
|
|
62
62
|
'no-undefined-server-variable': 'error',
|
|
63
|
-
'no-
|
|
63
|
+
'no-server-variables-empty-enum': 'error',
|
|
64
64
|
},
|
|
65
65
|
};
|
|
@@ -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 } : {}));
|
|
@@ -124,7 +142,7 @@ 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
|
@@ -44,7 +44,7 @@ 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
50
|
'no-invalid-media-type-examples': 'warn',
|
|
@@ -54,6 +54,6 @@ exports.default = {
|
|
|
54
54
|
'no-example-value-and-externalValue': 'warn',
|
|
55
55
|
'no-unused-components': 'warn',
|
|
56
56
|
'no-undefined-server-variable': 'warn',
|
|
57
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
58
58
|
},
|
|
59
59
|
};
|
|
@@ -44,7 +44,7 @@ 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
50
|
'no-invalid-media-type-examples': 'warn',
|
|
@@ -54,6 +54,6 @@ exports.default = {
|
|
|
54
54
|
'no-example-value-and-externalValue': 'error',
|
|
55
55
|
'no-unused-components': 'warn',
|
|
56
56
|
'no-undefined-server-variable': 'error',
|
|
57
|
-
'no-
|
|
57
|
+
'no-server-variables-empty-enum': 'error',
|
|
58
58
|
},
|
|
59
59
|
};
|
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/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('/');
|
|
@@ -73,7 +73,7 @@ function mergeExtends(rulesConfList) {
|
|
|
73
73
|
pluginPaths: [],
|
|
74
74
|
extendPaths: [],
|
|
75
75
|
};
|
|
76
|
-
for (
|
|
76
|
+
for (const rulesConf of rulesConfList) {
|
|
77
77
|
if (rulesConf.extends) {
|
|
78
78
|
throw new Error(`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
|
|
79
79
|
}
|
|
@@ -112,13 +112,13 @@ function getMergedConfig(config, apiName) {
|
|
|
112
112
|
(_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.extendPaths,
|
|
113
113
|
]
|
|
114
114
|
.flat()
|
|
115
|
-
.filter(
|
|
115
|
+
.filter(utils_1.isTruthy);
|
|
116
116
|
const pluginPaths = [
|
|
117
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
118
|
(_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.styleguide) === null || _d === void 0 ? void 0 : _d.pluginPaths,
|
|
119
119
|
]
|
|
120
120
|
.flat()
|
|
121
|
-
.filter(
|
|
121
|
+
.filter(utils_1.isTruthy);
|
|
122
122
|
return apiName
|
|
123
123
|
? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { styleguide: Object.assign(Object.assign({}, (config.apis[apiName]
|
|
124
124
|
? config.apis[apiName].styleguide
|
|
@@ -169,7 +169,7 @@ function getUniquePlugins(plugins) {
|
|
|
169
169
|
seen.add(p.id);
|
|
170
170
|
}
|
|
171
171
|
else if (p.id) {
|
|
172
|
-
|
|
172
|
+
logger_1.logger.warn(`Duplicate plugin id "${logger_1.colorize.red(p.id)}".\n`);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
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 {
|