@redocly/openapi-core 1.0.0-beta.93 → 1.0.0-beta.96

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.
Files changed (127) hide show
  1. package/README.md +1 -1
  2. package/__tests__/bundle.test.ts +6 -6
  3. package/__tests__/fixtures/extension.js +1 -1
  4. package/__tests__/login.test.ts +2 -2
  5. package/__tests__/normalizeVisitors.test.ts +1 -1
  6. package/__tests__/ref-utils.test.ts +1 -1
  7. package/__tests__/utils.ts +30 -18
  8. package/__tests__/walk.test.ts +6 -6
  9. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -3
  10. package/lib/benchmark/utils.d.ts +2 -1
  11. package/lib/benchmark/utils.js +10 -7
  12. package/lib/bundle.d.ts +2 -2
  13. package/lib/config/all.d.ts +2 -2
  14. package/lib/config/builtIn.d.ts +1 -1
  15. package/lib/config/config-resolvers.d.ts +16 -0
  16. package/lib/config/config-resolvers.js +213 -0
  17. package/lib/config/config.d.ts +14 -129
  18. package/lib/config/config.js +17 -234
  19. package/lib/config/index.d.ts +7 -0
  20. package/lib/config/index.js +19 -0
  21. package/lib/config/load.d.ts +2 -1
  22. package/lib/config/load.js +20 -13
  23. package/lib/config/minimal.d.ts +2 -2
  24. package/lib/config/recommended.d.ts +2 -2
  25. package/lib/config/types.d.ts +113 -0
  26. package/lib/config/types.js +2 -0
  27. package/lib/config/utils.d.ts +13 -0
  28. package/lib/config/utils.js +160 -0
  29. package/lib/format/format.d.ts +1 -1
  30. package/lib/format/format.js +28 -0
  31. package/lib/index.d.ts +1 -2
  32. package/lib/index.js +5 -6
  33. package/lib/lint.d.ts +1 -1
  34. package/lib/lint.js +5 -7
  35. package/lib/redocly/index.d.ts +1 -1
  36. package/lib/redocly/index.js +1 -1
  37. package/lib/redocly/redocly-client-types.d.ts +1 -1
  38. package/lib/redocly/registry-api.d.ts +1 -1
  39. package/lib/resolve.d.ts +1 -1
  40. package/lib/resolve.js +1 -2
  41. package/lib/rules/common/assertions/index.js +1 -1
  42. package/lib/rules/common/assertions/utils.d.ts +1 -1
  43. package/lib/rules/common/assertions/utils.js +6 -2
  44. package/lib/types/index.js +2 -2
  45. package/lib/types/oas3_1.js +31 -5
  46. package/lib/utils.d.ts +4 -1
  47. package/lib/utils.js +18 -1
  48. package/package.json +7 -4
  49. package/src/__tests__/lint.test.ts +1 -1
  50. package/src/benchmark/benches/recommended-oas3.bench.ts +2 -3
  51. package/src/benchmark/benchmark.js +1 -1
  52. package/src/benchmark/utils.ts +13 -8
  53. package/src/bundle.ts +2 -1
  54. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +140 -0
  55. package/src/config/__tests__/config-resolvers.test.ts +398 -0
  56. package/src/config/__tests__/config.test.ts +244 -0
  57. package/src/config/__tests__/fixtures/plugin.js +1 -1
  58. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +7 -0
  59. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +67 -0
  60. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +8 -0
  61. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +12 -0
  62. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +10 -0
  63. package/src/config/__tests__/fixtures/resolve-config/plugin.js +66 -0
  64. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +4 -0
  65. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +5 -0
  66. package/src/config/__tests__/load.test.ts +8 -1
  67. package/src/config/all.ts +3 -2
  68. package/src/config/builtIn.ts +2 -1
  69. package/src/config/config-resolvers.ts +304 -0
  70. package/src/config/config.ts +40 -457
  71. package/src/config/index.ts +7 -0
  72. package/src/config/load.ts +37 -31
  73. package/src/config/minimal.ts +2 -2
  74. package/src/config/recommended.ts +2 -2
  75. package/src/config/types.ts +168 -0
  76. package/src/config/utils.ts +208 -0
  77. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  78. package/src/format/format.ts +36 -6
  79. package/src/index.ts +6 -2
  80. package/src/lint.ts +4 -5
  81. package/src/redocly/__tests__/redocly-client.test.ts +7 -0
  82. package/src/redocly/index.ts +4 -2
  83. package/src/redocly/redocly-client-types.ts +1 -1
  84. package/src/redocly/registry-api.ts +3 -1
  85. package/src/resolve.ts +2 -4
  86. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  87. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  88. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  89. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  90. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  91. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  92. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  93. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  94. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  95. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  96. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  97. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  98. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  99. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  100. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  101. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  102. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  103. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  104. package/src/rules/common/__tests__/paths-kebab-case.test.ts +3 -3
  105. package/src/rules/common/__tests__/spec.test.ts +1 -1
  106. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  107. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  108. package/src/rules/common/assertions/index.ts +1 -1
  109. package/src/rules/common/assertions/utils.ts +5 -2
  110. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  111. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  112. package/src/rules/oas2/__tests__/spec/utils.ts +10 -7
  113. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  114. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  115. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  116. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +8 -8
  117. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  118. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  119. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  120. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +23 -14
  121. package/src/rules/oas3/__tests__/spec/servers.test.ts +1 -1
  122. package/src/rules/oas3/__tests__/spec/spec.test.ts +4 -4
  123. package/src/rules/oas3/__tests__/spec/utils.ts +10 -7
  124. package/src/types/index.ts +2 -2
  125. package/src/types/oas3_1.ts +32 -7
  126. package/src/utils.ts +18 -2
  127. package/tsconfig.tsbuildinfo +1 -1
@@ -1,107 +1,15 @@
1
- import { OasVersion, Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet } from '../oas-types';
2
- import { ProblemSeverity, NormalizedProblem } from '../walk';
3
- import { NodeType } from '../types';
1
+ import { NormalizedProblem } from '../walk';
2
+ import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
3
+ import type { NodeType } from '../types';
4
+ import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedLintConfig, RuleConfig } from './types';
4
5
  export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
5
- export declare type RuleConfig = ProblemSeverity | 'off' | ({
6
- severity?: ProblemSeverity;
7
- } & Record<string, any>);
8
- export declare type PreprocessorConfig = ProblemSeverity | 'off' | 'on' | ({
9
- severity?: ProblemSeverity;
10
- } & Record<string, any>);
11
- export declare type DecoratorConfig = PreprocessorConfig;
12
- export declare type LintRawConfig = {
13
- plugins?: (string | Plugin)[];
14
- extends?: string[];
15
- doNotResolveExamples?: boolean;
16
- rules?: Record<string, RuleConfig>;
17
- oas2Rules?: Record<string, RuleConfig>;
18
- oas3_0Rules?: Record<string, RuleConfig>;
19
- oas3_1Rules?: Record<string, RuleConfig>;
20
- preprocessors?: Record<string, PreprocessorConfig>;
21
- oas2Preprocessors?: Record<string, PreprocessorConfig>;
22
- oas3_0Preprocessors?: Record<string, PreprocessorConfig>;
23
- oas3_1Preprocessors?: Record<string, PreprocessorConfig>;
24
- decorators?: Record<string, DecoratorConfig>;
25
- oas2Decorators?: Record<string, DecoratorConfig>;
26
- oas3_0Decorators?: Record<string, DecoratorConfig>;
27
- oas3_1Decorators?: Record<string, DecoratorConfig>;
28
- };
29
- export declare type PreprocessorsConfig = {
30
- oas3?: Oas3PreprocessorsSet;
31
- oas2?: Oas2PreprocessorsSet;
32
- };
33
- export declare type DecoratorsConfig = {
34
- oas3?: Oas3DecoratorsSet;
35
- oas2?: Oas2DecoratorsSet;
36
- };
37
- export declare type TypesExtensionFn = (types: Record<string, NodeType>, oasVersion: OasVersion) => Record<string, NodeType>;
38
- export declare type TypeExtensionsConfig = Partial<Record<OasMajorVersion, TypesExtensionFn>>;
39
- export declare type CustomRulesConfig = {
40
- oas3?: Oas3RuleSet;
41
- oas2?: Oas2RuleSet;
42
- };
43
- export declare type Plugin = {
44
- id: string;
45
- configs?: Record<string, LintRawConfig>;
46
- rules?: CustomRulesConfig;
47
- preprocessors?: PreprocessorsConfig;
48
- decorators?: DecoratorsConfig;
49
- typeExtension?: TypeExtensionsConfig;
50
- };
51
- export declare type ResolveHeader = {
52
- name: string;
53
- envVariable?: undefined;
54
- value: string;
55
- matches: string;
56
- } | {
57
- name: string;
58
- value?: undefined;
59
- envVariable: string;
60
- matches: string;
61
- };
62
- export declare type RawResolveConfig = {
63
- http?: Partial<HttpResolveConfig>;
64
- };
65
- export declare type HttpResolveConfig = {
66
- headers: ResolveHeader[];
67
- customFetch?: Function;
68
- };
69
- export declare type ResolveConfig = {
70
- http: HttpResolveConfig;
71
- };
72
6
  export declare const DEFAULT_REGION = "us";
73
- export declare type Region = 'us' | 'eu';
74
- export declare type AccessTokens = {
75
- [region in Region]?: string;
76
- };
77
7
  export declare const DOMAINS: {
78
8
  [region in Region]: string;
79
9
  };
80
10
  export declare const AVAILABLE_REGIONS: Region[];
81
- export declare type DeprecatedRawConfig = {
82
- apiDefinitions?: Record<string, string>;
83
- lint?: LintRawConfig;
84
- resolve?: RawResolveConfig;
85
- region?: Region;
86
- referenceDocs?: Record<string, any>;
87
- };
88
- export declare type Api = {
89
- root: string;
90
- lint?: Omit<LintRawConfig, 'plugins'>;
91
- 'features.openapi'?: Record<string, any>;
92
- 'features.mockServer'?: Record<string, any>;
93
- };
94
- export declare type RawConfig = {
95
- apis?: Record<string, Api>;
96
- lint?: LintRawConfig;
97
- resolve?: RawResolveConfig;
98
- region?: Region;
99
- 'features.openapi'?: Record<string, any>;
100
- 'features.mockServer'?: Record<string, any>;
101
- organization?: string;
102
- };
103
11
  export declare class LintConfig {
104
- rawConfig: LintRawConfig;
12
+ rawConfig: ResolvedLintConfig;
105
13
  configFile?: string | undefined;
106
14
  plugins: Plugin[];
107
15
  ignore: Record<string, Record<string, Set<string>>>;
@@ -112,19 +20,21 @@ export declare class LintConfig {
112
20
  private _usedRules;
113
21
  private _usedVersions;
114
22
  recommendedFallback: boolean;
115
- constructor(rawConfig: LintRawConfig, configFile?: string | undefined);
23
+ extendPaths: string[];
24
+ pluginPaths: string[];
25
+ constructor(rawConfig: ResolvedLintConfig, configFile?: string | undefined);
116
26
  saveIgnore(): void;
117
27
  addIgnore(problem: NormalizedProblem): void;
118
28
  addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
119
29
  extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
120
30
  getRuleSettings(ruleId: string, oasVersion: OasVersion): {
121
- severity: ProblemSeverity | "off";
31
+ severity: import("../walk").ProblemSeverity | "off";
122
32
  };
123
33
  getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
124
- severity: ProblemSeverity | "off";
34
+ severity: import("../walk").ProblemSeverity | "off";
125
35
  };
126
36
  getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
127
- severity: ProblemSeverity | "off";
37
+ severity: import("../walk").ProblemSeverity | "off";
128
38
  };
129
39
  getUnusedRules(): {
130
40
  rules: string[];
@@ -137,9 +47,9 @@ export declare class LintConfig {
137
47
  skipDecorators(decorators?: string[]): void;
138
48
  }
139
49
  export declare class Config {
140
- rawConfig: RawConfig;
50
+ rawConfig: ResolvedConfig;
141
51
  configFile?: string | undefined;
142
- apis: Record<string, Api>;
52
+ apis: Record<string, ResolvedApi>;
143
53
  lint: LintConfig;
144
54
  resolve: ResolveConfig;
145
55
  licenseKey?: string;
@@ -147,30 +57,5 @@ export declare class Config {
147
57
  'features.openapi': Record<string, any>;
148
58
  'features.mockServer'?: Record<string, any>;
149
59
  organization?: string;
150
- constructor(rawConfig: RawConfig, configFile?: string | undefined);
60
+ constructor(rawConfig: ResolvedConfig, configFile?: string | undefined);
151
61
  }
152
- export declare function getMergedConfig(config: Config, entrypointAlias?: string): Config;
153
- export declare function getMergedLintConfig(config: Config, entrypointAlias?: string): {
154
- rules: {
155
- [x: string]: RuleConfig;
156
- };
157
- preprocessors: {
158
- [x: string]: PreprocessorConfig;
159
- };
160
- decorators: {
161
- [x: string]: PreprocessorConfig;
162
- };
163
- extends?: string[] | undefined;
164
- doNotResolveExamples?: boolean | undefined;
165
- oas2Rules?: Record<string, RuleConfig> | undefined;
166
- oas3_0Rules?: Record<string, RuleConfig> | undefined;
167
- oas3_1Rules?: Record<string, RuleConfig> | undefined;
168
- oas2Preprocessors?: Record<string, PreprocessorConfig> | undefined;
169
- oas3_0Preprocessors?: Record<string, PreprocessorConfig> | undefined;
170
- oas3_1Preprocessors?: Record<string, PreprocessorConfig> | undefined;
171
- oas2Decorators?: Record<string, PreprocessorConfig> | undefined;
172
- oas3_0Decorators?: Record<string, PreprocessorConfig> | undefined;
173
- oas3_1Decorators?: Record<string, PreprocessorConfig> | undefined;
174
- plugins?: (string | Plugin)[] | undefined;
175
- };
176
- export declare function transformConfig(rawConfig: DeprecatedRawConfig | RawConfig): RawConfig;
@@ -1,25 +1,12 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.transformConfig = exports.getMergedLintConfig = exports.getMergedConfig = exports.Config = exports.LintConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
3
+ exports.Config = exports.LintConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
15
4
  const fs = require("fs");
16
5
  const path = require("path");
17
- const path_1 = require("path");
18
- const colorette_1 = require("colorette");
19
6
  const js_yaml_1 = require("../js-yaml");
20
7
  const utils_1 = require("../utils");
21
8
  const oas_types_1 = require("../oas-types");
22
- const recommended_1 = require("./recommended");
9
+ const utils_2 = require("./utils");
23
10
  exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
24
11
  const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
25
12
  `# See https://redoc.ly/docs/cli/ for more information.\n`;
@@ -44,38 +31,26 @@ class LintConfig {
44
31
  this.ignore = {};
45
32
  this._usedRules = new Set();
46
33
  this._usedVersions = new Set();
47
- this.recommendedFallback = false;
48
- this.plugins = rawConfig.plugins ? resolvePlugins(rawConfig.plugins, configFile) : [];
34
+ this.plugins = rawConfig.plugins || [];
49
35
  this.doNotResolveExamples = !!rawConfig.doNotResolveExamples;
50
- if (!rawConfig.extends) {
51
- this.recommendedFallback = true;
52
- }
53
- const extendConfigs = rawConfig.extends
54
- ? resolvePresets(rawConfig.extends, this.plugins)
55
- : [recommended_1.default];
56
- if (rawConfig.rules || rawConfig.preprocessors || rawConfig.decorators) {
57
- extendConfigs.push({
58
- rules: rawConfig.rules,
59
- preprocessors: rawConfig.preprocessors,
60
- decorators: rawConfig.decorators,
61
- });
62
- }
63
- const merged = mergeExtends(extendConfigs);
36
+ this.recommendedFallback = rawConfig.recommendedFallback || false;
64
37
  this.rules = {
65
- [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, merged.rules), merged.oas2Rules),
66
- [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, merged.rules), merged.oas3_0Rules),
67
- [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, merged.rules), merged.oas3_1Rules),
38
+ [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas2Rules),
39
+ [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas3_0Rules),
40
+ [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, rawConfig.rules), rawConfig.oas3_1Rules),
68
41
  };
69
42
  this.preprocessors = {
70
- [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, merged.preprocessors), merged.oas2Preprocessors),
71
- [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, merged.preprocessors), merged.oas3_0Preprocessors),
72
- [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, merged.preprocessors), merged.oas3_1Preprocessors),
43
+ [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas2Preprocessors),
44
+ [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas3_0Preprocessors),
45
+ [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, rawConfig.preprocessors), rawConfig.oas3_1Preprocessors),
73
46
  };
74
47
  this.decorators = {
75
- [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, merged.decorators), merged.oas2Decorators),
76
- [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, merged.decorators), merged.oas3_0Decorators),
77
- [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, merged.decorators), merged.oas3_1Decorators),
48
+ [oas_types_1.OasVersion.Version2]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas2Decorators),
49
+ [oas_types_1.OasVersion.Version3_0]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas3_0Decorators),
50
+ [oas_types_1.OasVersion.Version3_1]: Object.assign(Object.assign({}, rawConfig.decorators), rawConfig.oas3_1Decorators),
78
51
  };
52
+ this.extendPaths = rawConfig.extendPaths || [];
53
+ this.pluginPaths = rawConfig.pluginPaths || [];
79
54
  const dir = this.configFile
80
55
  ? path.dirname(this.configFile)
81
56
  : (typeof process !== 'undefined' && process.cwd()) || '';
@@ -87,7 +62,7 @@ class LintConfig {
87
62
  js_yaml_1.parseYaml(fs.readFileSync(ignoreFile, 'utf-8')) || {};
88
63
  // resolve ignore paths
89
64
  for (const fileName of Object.keys(this.ignore)) {
90
- this.ignore[path.resolve(path_1.dirname(ignoreFile), fileName)] = this.ignore[fileName];
65
+ this.ignore[path.resolve(path.dirname(ignoreFile), fileName)] = this.ignore[fileName];
91
66
  for (const ruleId of Object.keys(this.ignore[fileName])) {
92
67
  this.ignore[fileName][ruleId] = new Set(this.ignore[fileName][ruleId]);
93
68
  }
@@ -249,207 +224,15 @@ class LintConfig {
249
224
  exports.LintConfig = LintConfig;
250
225
  class Config {
251
226
  constructor(rawConfig, configFile) {
252
- var _a, _b, _c;
253
227
  this.rawConfig = rawConfig;
254
228
  this.configFile = configFile;
255
229
  this.apis = rawConfig.apis || {};
256
230
  this.lint = new LintConfig(rawConfig.lint || {}, configFile);
257
231
  this['features.openapi'] = rawConfig['features.openapi'] || {};
258
232
  this['features.mockServer'] = rawConfig['features.mockServer'] || {};
259
- this.resolve = {
260
- http: {
261
- headers: (_c = (_b = (_a = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.resolve) === null || _a === void 0 ? void 0 : _a.http) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : [],
262
- customFetch: undefined,
263
- },
264
- };
233
+ this.resolve = utils_2.getResolveConfig(rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.resolve);
265
234
  this.region = rawConfig.region;
266
235
  this.organization = rawConfig.organization;
267
236
  }
268
237
  }
269
238
  exports.Config = Config;
270
- function resolvePresets(presets, plugins) {
271
- return presets.map((presetName) => {
272
- var _a;
273
- const { pluginId, configName } = parsePresetName(presetName);
274
- const plugin = plugins.find((p) => p.id === pluginId);
275
- if (!plugin) {
276
- throw new Error(`Invalid config ${colorette_1.red(presetName)}: plugin ${pluginId} is not included.`);
277
- }
278
- const preset = (_a = plugin.configs) === null || _a === void 0 ? void 0 : _a[configName];
279
- if (!preset) {
280
- throw new Error(pluginId
281
- ? `Invalid config ${colorette_1.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
282
- : `Invalid config ${colorette_1.red(presetName)}: there is no such built-in config.`);
283
- }
284
- return preset;
285
- });
286
- }
287
- function parsePresetName(presetName) {
288
- if (presetName.indexOf('/') > -1) {
289
- const [pluginId, configName] = presetName.split('/');
290
- return { pluginId, configName };
291
- }
292
- else {
293
- return { pluginId: '', configName: presetName };
294
- }
295
- }
296
- function resolvePlugins(plugins, configPath = '') {
297
- if (!plugins)
298
- return [];
299
- // @ts-ignore
300
- const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
301
- const seenPluginIds = new Map();
302
- return plugins
303
- .map((p) => {
304
- // TODO: resolve npm packages similar to eslint
305
- const pluginModule = typeof p === 'string'
306
- ? requireFunc(path.resolve(path.dirname(configPath), p))
307
- : p;
308
- const id = pluginModule.id;
309
- if (typeof id !== 'string') {
310
- throw new Error(colorette_1.red(`Plugin must define \`id\` property in ${colorette_1.blue(p.toString())}.`));
311
- }
312
- if (seenPluginIds.has(id)) {
313
- const pluginPath = seenPluginIds.get(id);
314
- throw new Error(colorette_1.red(`Plugin "id" must be unique. Plugin ${colorette_1.blue(p.toString())} uses id "${colorette_1.blue(id)}" already seen in ${colorette_1.blue(pluginPath)}`));
315
- }
316
- seenPluginIds.set(id, p.toString());
317
- const plugin = Object.assign(Object.assign({ id }, (pluginModule.configs ? { configs: pluginModule.configs } : {})), (pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}));
318
- if (pluginModule.rules) {
319
- if (!pluginModule.rules.oas3 && !pluginModule.rules.oas2) {
320
- throw new Error(`Plugin rules must have \`oas3\` or \`oas2\` rules "${p}.`);
321
- }
322
- plugin.rules = {};
323
- if (pluginModule.rules.oas3) {
324
- plugin.rules.oas3 = prefixRules(pluginModule.rules.oas3, id);
325
- }
326
- if (pluginModule.rules.oas2) {
327
- plugin.rules.oas2 = prefixRules(pluginModule.rules.oas2, id);
328
- }
329
- }
330
- if (pluginModule.preprocessors) {
331
- if (!pluginModule.preprocessors.oas3 && !pluginModule.preprocessors.oas2) {
332
- throw new Error(`Plugin \`preprocessors\` must have \`oas3\` or \`oas2\` preprocessors "${p}.`);
333
- }
334
- plugin.preprocessors = {};
335
- if (pluginModule.preprocessors.oas3) {
336
- plugin.preprocessors.oas3 = prefixRules(pluginModule.preprocessors.oas3, id);
337
- }
338
- if (pluginModule.preprocessors.oas2) {
339
- plugin.preprocessors.oas2 = prefixRules(pluginModule.preprocessors.oas2, id);
340
- }
341
- }
342
- if (pluginModule.decorators) {
343
- if (!pluginModule.decorators.oas3 && !pluginModule.decorators.oas2) {
344
- throw new Error(`Plugin \`decorators\` must have \`oas3\` or \`oas2\` decorators "${p}.`);
345
- }
346
- plugin.decorators = {};
347
- if (pluginModule.decorators.oas3) {
348
- plugin.decorators.oas3 = prefixRules(pluginModule.decorators.oas3, id);
349
- }
350
- if (pluginModule.decorators.oas2) {
351
- plugin.decorators.oas2 = prefixRules(pluginModule.decorators.oas2, id);
352
- }
353
- }
354
- return plugin;
355
- })
356
- .filter(utils_1.notUndefined);
357
- }
358
- function prefixRules(rules, prefix) {
359
- if (!prefix)
360
- return rules;
361
- const res = {};
362
- for (const name of Object.keys(rules)) {
363
- res[`${prefix}/${name}`] = rules[name];
364
- }
365
- return res;
366
- }
367
- function mergeExtends(rulesConfList) {
368
- const result = {
369
- rules: {},
370
- oas2Rules: {},
371
- oas3_0Rules: {},
372
- oas3_1Rules: {},
373
- preprocessors: {},
374
- oas2Preprocessors: {},
375
- oas3_0Preprocessors: {},
376
- oas3_1Preprocessors: {},
377
- decorators: {},
378
- oas2Decorators: {},
379
- oas3_0Decorators: {},
380
- oas3_1Decorators: {},
381
- };
382
- for (let rulesConf of rulesConfList) {
383
- if (rulesConf.extends) {
384
- throw new Error(`\`extends\` is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
385
- }
386
- Object.assign(result.rules, rulesConf.rules);
387
- Object.assign(result.oas2Rules, rulesConf.oas2Rules);
388
- assignExisting(result.oas2Rules, rulesConf.rules || {});
389
- Object.assign(result.oas3_0Rules, rulesConf.oas3_0Rules);
390
- assignExisting(result.oas3_0Rules, rulesConf.rules || {});
391
- Object.assign(result.oas3_1Rules, rulesConf.oas3_1Rules);
392
- assignExisting(result.oas3_1Rules, rulesConf.rules || {});
393
- Object.assign(result.preprocessors, rulesConf.preprocessors);
394
- Object.assign(result.oas2Preprocessors, rulesConf.oas2Preprocessors);
395
- assignExisting(result.oas2Preprocessors, rulesConf.preprocessors || {});
396
- Object.assign(result.oas3_0Preprocessors, rulesConf.oas3_0Preprocessors);
397
- assignExisting(result.oas3_0Preprocessors, rulesConf.preprocessors || {});
398
- Object.assign(result.oas3_1Preprocessors, rulesConf.oas3_1Preprocessors);
399
- assignExisting(result.oas3_1Preprocessors, rulesConf.preprocessors || {});
400
- Object.assign(result.decorators, rulesConf.decorators);
401
- Object.assign(result.oas2Decorators, rulesConf.oas2Decorators);
402
- assignExisting(result.oas2Decorators, rulesConf.decorators || {});
403
- Object.assign(result.oas3_0Decorators, rulesConf.oas3_0Decorators);
404
- assignExisting(result.oas3_0Decorators, rulesConf.decorators || {});
405
- Object.assign(result.oas3_1Decorators, rulesConf.oas3_1Decorators);
406
- assignExisting(result.oas3_1Decorators, rulesConf.decorators || {});
407
- }
408
- return result;
409
- }
410
- function assignExisting(target, obj) {
411
- for (let k of Object.keys(obj)) {
412
- if (target.hasOwnProperty(k)) {
413
- target[k] = obj[k];
414
- }
415
- }
416
- }
417
- function getMergedConfig(config, entrypointAlias) {
418
- var _a, _b;
419
- return entrypointAlias
420
- ? new Config(Object.assign(Object.assign({}, config.rawConfig), { lint: getMergedLintConfig(config, entrypointAlias), 'features.openapi': Object.assign(Object.assign({}, config['features.openapi']), (_a = config.apis[entrypointAlias]) === null || _a === void 0 ? void 0 : _a['features.openapi']), 'features.mockServer': Object.assign(Object.assign({}, config['features.mockServer']), (_b = config.apis[entrypointAlias]) === null || _b === void 0 ? void 0 : _b['features.mockServer']) }), config.configFile)
421
- : config;
422
- }
423
- exports.getMergedConfig = getMergedConfig;
424
- function getMergedLintConfig(config, entrypointAlias) {
425
- var _a, _b, _c, _d;
426
- const apiLint = entrypointAlias ? (_a = config.apis[entrypointAlias]) === null || _a === void 0 ? void 0 : _a.lint : {};
427
- const mergedLint = Object.assign(Object.assign(Object.assign({}, config.rawConfig.lint), apiLint), { rules: Object.assign(Object.assign({}, (_b = config.rawConfig.lint) === null || _b === void 0 ? void 0 : _b.rules), apiLint === null || apiLint === void 0 ? void 0 : apiLint.rules), preprocessors: Object.assign(Object.assign({}, (_c = config.rawConfig.lint) === null || _c === void 0 ? void 0 : _c.preprocessors), apiLint === null || apiLint === void 0 ? void 0 : apiLint.preprocessors), decorators: Object.assign(Object.assign({}, (_d = config.rawConfig.lint) === null || _d === void 0 ? void 0 : _d.decorators), apiLint === null || apiLint === void 0 ? void 0 : apiLint.decorators) });
428
- return mergedLint;
429
- }
430
- exports.getMergedLintConfig = getMergedLintConfig;
431
- function transformApiDefinitionsToApis(apiDefinitions = {}) {
432
- let apis = {};
433
- for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
434
- apis[apiName] = { root: apiPath };
435
- }
436
- return apis;
437
- }
438
- function transformConfig(rawConfig) {
439
- if (rawConfig.apis && rawConfig.apiDefinitions) {
440
- throw new Error("Do not use 'apiDefinitions' field. Use 'apis' instead.\n");
441
- }
442
- if (rawConfig['features.openapi'] &&
443
- rawConfig.referenceDocs) {
444
- throw new Error("Do not use 'referenceDocs' field. Use 'features.openapi' instead.\n");
445
- }
446
- const _a = rawConfig, { apiDefinitions, referenceDocs } = _a, rest = __rest(_a, ["apiDefinitions", "referenceDocs"]);
447
- if (apiDefinitions) {
448
- process.stderr.write(`The ${colorette_1.yellow('apiDefinitions')} field is deprecated. Use ${colorette_1.green('apis')} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
449
- }
450
- if (referenceDocs) {
451
- process.stderr.write(`The ${colorette_1.yellow('referenceDocs')} field is deprecated. Use ${colorette_1.green('features.openapi')} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
452
- }
453
- return Object.assign({ 'features.openapi': referenceDocs, apis: transformApiDefinitionsToApis(apiDefinitions) }, rest);
454
- }
455
- exports.transformConfig = transformConfig;
@@ -0,0 +1,7 @@
1
+ export * from './config';
2
+ export * from './types';
3
+ export * from './rules';
4
+ export * from './builtIn';
5
+ export * from './load';
6
+ export * from './utils';
7
+ export * from './config-resolvers';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./config"), exports);
14
+ __exportStar(require("./types"), exports);
15
+ __exportStar(require("./rules"), exports);
16
+ __exportStar(require("./builtIn"), exports);
17
+ __exportStar(require("./load"), exports);
18
+ __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./config-resolvers"), exports);
@@ -1,4 +1,5 @@
1
- import { Config, RawConfig } from './config';
1
+ import { Config } from './config';
2
+ import type { RawConfig } from './types';
2
3
  export declare function loadConfig(configPath?: string | undefined, customExtends?: string[]): Promise<Config>;
3
4
  export declare const CONFIG_FILE_NAMES: string[];
4
5
  export declare function findConfig(dir?: string): string | undefined;
@@ -15,15 +15,20 @@ const path = require("path");
15
15
  const redocly_1 = require("../redocly");
16
16
  const utils_1 = require("../utils");
17
17
  const config_1 = require("./config");
18
- const builtIn_1 = require("./builtIn");
18
+ const utils_2 = require("./utils");
19
+ const config_resolvers_1 = require("./config-resolvers");
19
20
  function loadConfig(configPath = findConfig(), customExtends) {
20
- var _a, _b;
21
+ var _a;
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
23
  const rawConfig = yield getConfig(configPath);
23
24
  if (customExtends !== undefined) {
24
25
  rawConfig.lint = rawConfig.lint || {};
25
26
  rawConfig.lint.extends = customExtends;
26
27
  }
28
+ else if (utils_1.isEmptyObject(rawConfig)) {
29
+ // TODO: check if we can add recommended here. add message here?
30
+ // rawConfig.lint = { extends: ['recommended'], recommendedFallback: true };
31
+ }
27
32
  const redoclyClient = new redocly_1.RedoclyClient();
28
33
  const tokens = yield redoclyClient.getTokens();
29
34
  if (tokens.length) {
@@ -41,15 +46,19 @@ function loadConfig(configPath = findConfig(), customExtends) {
41
46
  value: item.token,
42
47
  },
43
48
  //support redocly.com domain for future compatibility
44
- ...(item.region === 'us' ? [{
45
- matches: `https://api.redoc.ly/registry/**`,
46
- name: 'Authorization',
47
- envVariable: undefined,
48
- value: item.token,
49
- }] : []));
49
+ ...(item.region === 'us'
50
+ ? [
51
+ {
52
+ matches: `https://api.redoc.ly/registry/**`,
53
+ name: 'Authorization',
54
+ envVariable: undefined,
55
+ value: item.token,
56
+ },
57
+ ]
58
+ : []));
50
59
  }
51
60
  }
52
- return new config_1.Config(Object.assign(Object.assign({}, rawConfig), { lint: Object.assign(Object.assign({}, rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.lint), { plugins: [...(((_b = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.lint) === null || _b === void 0 ? void 0 : _b.plugins) || []), builtIn_1.defaultPlugin] }) }), configPath);
61
+ return config_resolvers_1.resolveConfig(rawConfig, configPath);
53
62
  });
54
63
  }
55
64
  exports.loadConfig = loadConfig;
@@ -57,9 +66,7 @@ exports.CONFIG_FILE_NAMES = ['redocly.yaml', 'redocly.yml', '.redocly.yaml', '.r
57
66
  function findConfig(dir) {
58
67
  if (!fs.hasOwnProperty('existsSync'))
59
68
  return;
60
- const existingConfigFiles = exports.CONFIG_FILE_NAMES
61
- .map(name => dir ? path.resolve(dir, name) : name)
62
- .filter(fs.existsSync);
69
+ const existingConfigFiles = exports.CONFIG_FILE_NAMES.map((name) => dir ? path.resolve(dir, name) : name).filter(fs.existsSync);
63
70
  if (existingConfigFiles.length > 1) {
64
71
  throw new Error(`
65
72
  Multiple configuration files are not allowed.
@@ -76,7 +83,7 @@ function getConfig(configPath = findConfig()) {
76
83
  return {};
77
84
  try {
78
85
  const rawConfig = ((yield utils_1.loadYaml(configPath)) || {});
79
- return config_1.transformConfig(rawConfig);
86
+ return utils_2.transformConfig(rawConfig);
80
87
  }
81
88
  catch (e) {
82
89
  throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
@@ -1,3 +1,3 @@
1
- import { LintRawConfig } from './config';
2
- declare const _default: LintRawConfig;
1
+ import type { PluginLintConfig } from './types';
2
+ declare const _default: PluginLintConfig;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { LintRawConfig } from './config';
2
- declare const _default: LintRawConfig;
1
+ import type { PluginLintConfig } from './types';
2
+ declare const _default: PluginLintConfig;
3
3
  export default _default;