@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.106

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 (189) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/utils.d.ts +2 -2
  5. package/lib/benchmark/utils.js +2 -2
  6. package/lib/bundle.d.ts +2 -2
  7. package/lib/bundle.js +2 -2
  8. package/lib/config/all.d.ts +2 -2
  9. package/lib/config/all.js +1 -1
  10. package/lib/config/builtIn.d.ts +2 -2
  11. package/lib/config/builtIn.js +2 -2
  12. package/lib/config/config-resolvers.d.ts +5 -5
  13. package/lib/config/config-resolvers.js +39 -36
  14. package/lib/config/config.d.ts +5 -5
  15. package/lib/config/config.js +4 -4
  16. package/lib/config/load.js +4 -4
  17. package/lib/config/minimal.d.ts +2 -2
  18. package/lib/config/minimal.js +1 -1
  19. package/lib/config/recommended.d.ts +2 -2
  20. package/lib/config/recommended.js +1 -1
  21. package/lib/config/rules.d.ts +2 -2
  22. package/lib/config/rules.js +1 -1
  23. package/lib/config/types.d.ts +23 -19
  24. package/lib/config/utils.d.ts +5 -5
  25. package/lib/config/utils.js +43 -26
  26. package/lib/decorators/common/remove-x-internal.js +2 -2
  27. package/lib/format/format.js +1 -1
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +2 -2
  30. package/lib/js-yaml/index.js +1 -6
  31. package/lib/lint.d.ts +2 -2
  32. package/lib/lint.js +16 -6
  33. package/lib/redocly/registry-api.d.ts +1 -1
  34. package/lib/redocly/registry-api.js +2 -2
  35. package/lib/rules/common/info-license-url.d.ts +1 -1
  36. package/lib/rules/common/info-license-url.js +5 -10
  37. package/lib/rules/common/info-license.d.ts +2 -0
  38. package/lib/rules/common/info-license.js +17 -0
  39. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  40. package/lib/rules/common/operation-operationId.js +1 -1
  41. package/lib/rules/common/path-not-include-query.js +1 -1
  42. package/lib/rules/common/paths-kebab-case.js +4 -1
  43. package/lib/rules/common/spec.js +1 -1
  44. package/lib/rules/oas2/index.js +4 -4
  45. package/lib/rules/oas2/remove-unused-components.js +3 -3
  46. package/lib/rules/oas3/index.js +4 -4
  47. package/lib/rules/oas3/no-empty-servers.js +1 -1
  48. package/lib/rules/oas3/remove-unused-components.js +2 -2
  49. package/lib/rules/other/stats.js +43 -14
  50. package/lib/rules/utils.d.ts +1 -1
  51. package/lib/rules/utils.js +4 -1
  52. package/lib/types/index.d.ts +2 -2
  53. package/lib/types/redocly-yaml.js +8 -7
  54. package/package.json +1 -1
  55. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  56. package/src/__tests__/bundle.test.ts +68 -34
  57. package/src/__tests__/codeframes.test.ts +13 -14
  58. package/src/__tests__/js-yaml.test.ts +6 -4
  59. package/src/__tests__/lint.test.ts +74 -6
  60. package/src/__tests__/login.test.ts +2 -2
  61. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  62. package/src/__tests__/ref-utils.test.ts +13 -13
  63. package/src/__tests__/resolve-http.test.ts +1 -1
  64. package/src/__tests__/resolve.test.ts +14 -11
  65. package/src/__tests__/walk.test.ts +48 -56
  66. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  67. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  68. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  69. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
  70. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  71. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  72. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  73. package/src/benchmark/benchmark.js +9 -5
  74. package/src/benchmark/utils.ts +5 -5
  75. package/src/bundle.ts +18 -17
  76. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +1 -1
  77. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  78. package/src/config/__tests__/config.test.ts +76 -76
  79. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  80. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  81. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  82. package/src/config/__tests__/utils.test.ts +83 -0
  83. package/src/config/all.ts +3 -4
  84. package/src/config/builtIn.ts +5 -5
  85. package/src/config/config-resolvers.ts +122 -83
  86. package/src/config/config.ts +5 -5
  87. package/src/config/load.ts +6 -6
  88. package/src/config/minimal.ts +3 -3
  89. package/src/config/recommended.ts +3 -3
  90. package/src/config/rules.ts +6 -6
  91. package/src/config/types.ts +28 -19
  92. package/src/config/utils.ts +70 -50
  93. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  94. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  95. package/src/decorators/common/filters/filter-helper.ts +1 -1
  96. package/src/decorators/common/info-description-override.ts +1 -1
  97. package/src/decorators/common/operation-description-override.ts +1 -1
  98. package/src/decorators/common/remove-x-internal.ts +4 -4
  99. package/src/decorators/common/tag-description-override.ts +1 -1
  100. package/src/format/codeframes.ts +4 -4
  101. package/src/format/format.ts +10 -10
  102. package/src/index.ts +2 -3
  103. package/src/js-yaml/index.ts +3 -8
  104. package/src/lint.ts +22 -18
  105. package/src/oas-types.ts +1 -6
  106. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  107. package/src/redocly/index.ts +6 -4
  108. package/src/redocly/registry-api.ts +6 -6
  109. package/src/ref-utils.ts +2 -2
  110. package/src/resolve.ts +7 -4
  111. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  112. package/src/rules/__tests__/utils.test.ts +122 -0
  113. package/src/rules/ajv.ts +3 -4
  114. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  115. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  116. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  117. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  118. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  119. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  120. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  121. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  122. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  123. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  124. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  125. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  126. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  127. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  128. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  129. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  130. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  131. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  132. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  133. package/src/rules/common/__tests__/spec.test.ts +2 -2
  134. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  135. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  136. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  137. package/src/rules/common/assertions/index.ts +6 -6
  138. package/src/rules/common/info-license-url.ts +4 -9
  139. package/src/rules/common/info-license.ts +15 -0
  140. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  141. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  142. package/src/rules/common/no-invalid-parameter-examples.ts +2 -2
  143. package/src/rules/common/no-invalid-schema-examples.ts +1 -1
  144. package/src/rules/common/operation-operationId.ts +1 -1
  145. package/src/rules/common/operation-parameters-unique.ts +2 -2
  146. package/src/rules/common/path-not-include-query.ts +1 -1
  147. package/src/rules/common/path-params-defined.ts +1 -1
  148. package/src/rules/common/paths-kebab-case.ts +4 -1
  149. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  150. package/src/rules/common/spec.ts +10 -7
  151. package/src/rules/no-unresolved-refs.ts +1 -1
  152. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  153. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  154. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  155. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  156. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  157. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  158. package/src/rules/oas2/index.ts +3 -3
  159. package/src/rules/oas2/remove-unused-components.ts +13 -8
  160. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  161. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  162. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +8 -8
  163. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  164. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  165. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  166. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  167. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  168. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  169. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  170. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  171. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  172. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  173. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  174. package/src/rules/oas3/index.ts +3 -3
  175. package/src/rules/oas3/no-empty-servers.ts +1 -1
  176. package/src/rules/oas3/no-invalid-media-type-examples.ts +12 -4
  177. package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
  178. package/src/rules/oas3/remove-unused-components.ts +18 -7
  179. package/src/rules/other/stats.ts +46 -17
  180. package/src/rules/utils.ts +5 -3
  181. package/src/types/index.ts +5 -5
  182. package/src/types/redocly-yaml.ts +8 -7
  183. package/src/typings/common.ts +9 -1
  184. package/src/typings/openapi.ts +1 -1
  185. package/src/visitors.ts +4 -4
  186. package/tsconfig.tsbuildinfo +1 -1
  187. package/lib/rules/common/license-url.d.ts +0 -2
  188. package/lib/rules/common/license-url.js +0 -12
  189. package/src/rules/common/license-url.ts +0 -10
@@ -12,28 +12,30 @@ import {
12
12
  transformConfig,
13
13
  } from './utils';
14
14
  import type {
15
- LintRawConfig,
15
+ StyleguideRawConfig,
16
+ ApiStyleguideRawConfig,
16
17
  Plugin,
17
18
  RawConfig,
18
19
  ResolvedApi,
19
- ResolvedLintConfig,
20
+ ResolvedStyleguideConfig,
20
21
  RuleConfig,
22
+ DeprecatedInRawConfig,
21
23
  } from './types';
22
24
  import { isNotString, isString, notUndefined, parseYaml } from '../utils';
23
25
  import { Config } from './config';
24
26
 
25
- export async function resolveConfig(rawConfig: RawConfig, configPath?: string) {
26
- if (rawConfig.lint?.extends?.some(isNotString)) {
27
+ export async function resolveConfig(rawConfig: RawConfig, configPath?: string): Promise<Config> {
28
+ if (rawConfig.styleguide?.extends?.some(isNotString)) {
27
29
  throw new Error(
28
- `Error configuration format not detected in extends value must contain strings`,
30
+ `Error configuration format not detected in extends value must contain strings`
29
31
  );
30
32
  }
31
33
 
32
34
  const resolver = new BaseResolver(getResolveConfig(rawConfig.resolve));
33
- const configExtends = rawConfig?.lint?.extends ?? ['recommended'];
34
- const recommendedFallback = !rawConfig?.lint?.extends;
35
- const lintConfig = {
36
- ...rawConfig?.lint,
35
+ const configExtends = rawConfig?.styleguide?.extends ?? ['recommended'];
36
+ const recommendedFallback = !rawConfig?.styleguide?.extends;
37
+ const styleguideConfig = {
38
+ ...rawConfig?.styleguide,
37
39
  extends: configExtends,
38
40
  recommendedFallback,
39
41
  };
@@ -41,14 +43,14 @@ export async function resolveConfig(rawConfig: RawConfig, configPath?: string) {
41
43
  const apis = await resolveApis({
42
44
  rawConfig: {
43
45
  ...rawConfig,
44
- lint: lintConfig,
46
+ styleguide: styleguideConfig,
45
47
  },
46
48
  configPath,
47
49
  resolver,
48
50
  });
49
51
 
50
- const lint = await resolveLint({
51
- lintConfig,
52
+ const styleguide = await resolveStyleguideConfig({
53
+ styleguideConfig,
52
54
  configPath,
53
55
  resolver,
54
56
  });
@@ -57,15 +59,15 @@ export async function resolveConfig(rawConfig: RawConfig, configPath?: string) {
57
59
  {
58
60
  ...rawConfig,
59
61
  apis,
60
- lint,
62
+ styleguide,
61
63
  },
62
- configPath,
64
+ configPath
63
65
  );
64
66
  }
65
67
 
66
68
  export function resolvePlugins(
67
69
  plugins: (string | Plugin)[] | null,
68
- configPath: string = '',
70
+ configPath: string = ''
69
71
  ): Plugin[] {
70
72
  if (!plugins) return [];
71
73
 
@@ -95,9 +97,9 @@ export function resolvePlugins(
95
97
  throw new Error(
96
98
  red(
97
99
  `Plugin "id" must be unique. Plugin ${blue(p.toString())} uses id "${blue(
98
- id,
99
- )}" already seen in ${blue(pluginPath)}`,
100
- ),
100
+ id
101
+ )}" already seen in ${blue(pluginPath)}`
102
+ )
101
103
  );
102
104
  }
103
105
 
@@ -124,7 +126,7 @@ export function resolvePlugins(
124
126
  if (pluginModule.preprocessors) {
125
127
  if (!pluginModule.preprocessors.oas3 && !pluginModule.preprocessors.oas2) {
126
128
  throw new Error(
127
- `Plugin \`preprocessors\` must have \`oas3\` or \`oas2\` preprocessors "${p}.`,
129
+ `Plugin \`preprocessors\` must have \`oas3\` or \`oas2\` preprocessors "${p}.`
128
130
  );
129
131
  }
130
132
  plugin.preprocessors = {};
@@ -163,45 +165,48 @@ export async function resolveApis({
163
165
  configPath?: string;
164
166
  resolver?: BaseResolver;
165
167
  }): Promise<Record<string, ResolvedApi>> {
166
- const { apis = {}, lint: lintConfig = {} } = rawConfig;
168
+ const { apis = {}, styleguide: styleguideConfig = {} } = rawConfig;
167
169
  let resolvedApis: Record<string, ResolvedApi> = {};
168
170
  for (const [apiName, apiContent] of Object.entries(apis || {})) {
169
- if (apiContent.lint?.extends?.some(isNotString)) {
171
+ if (apiContent.styleguide?.extends?.some(isNotString)) {
170
172
  throw new Error(
171
- `Error configuration format not detected in extends value must contain strings`,
173
+ `Error configuration format not detected in extends value must contain strings`
172
174
  );
173
175
  }
174
- const rawLintConfig = getMergedLintRawConfig(lintConfig, apiContent.lint);
175
- const apiLint = await resolveLint({
176
- lintConfig: rawLintConfig,
176
+ const rawStyleguideConfig = getMergedRawStyleguideConfig(
177
+ styleguideConfig,
178
+ apiContent.styleguide
179
+ );
180
+ const resolvedApiConfig = await resolveStyleguideConfig({
181
+ styleguideConfig: rawStyleguideConfig,
177
182
  configPath,
178
183
  resolver,
179
184
  });
180
- resolvedApis[apiName] = { ...apiContent, lint: apiLint };
185
+ resolvedApis[apiName] = { ...apiContent, styleguide: resolvedApiConfig };
181
186
  }
182
187
  return resolvedApis;
183
188
  }
184
189
 
185
- async function resolveAndMergeNestedLint(
190
+ async function resolveAndMergeNestedStyleguideConfig(
186
191
  {
187
- lintConfig,
192
+ styleguideConfig,
188
193
  configPath = '',
189
194
  resolver = new BaseResolver(),
190
195
  }: {
191
- lintConfig?: LintRawConfig;
196
+ styleguideConfig?: StyleguideRawConfig;
192
197
  configPath?: string;
193
198
  resolver?: BaseResolver;
194
199
  },
195
200
  parentConfigPaths: string[] = [],
196
- extendPaths: string[] = [],
197
- ): Promise<ResolvedLintConfig> {
201
+ extendPaths: string[] = []
202
+ ): Promise<ResolvedStyleguideConfig> {
198
203
  if (parentConfigPaths.includes(configPath)) {
199
204
  throw new Error(`Circular dependency in config file: "${configPath}"`);
200
205
  }
201
206
  const plugins = getUniquePlugins(
202
- resolvePlugins([...(lintConfig?.plugins || []), defaultPlugin], configPath),
207
+ resolvePlugins([...(styleguideConfig?.plugins || []), defaultPlugin], configPath)
203
208
  );
204
- const pluginPaths = lintConfig?.plugins
209
+ const pluginPaths = styleguideConfig?.plugins
205
210
  ?.filter(isString)
206
211
  .map((p) => path.resolve(path.dirname(configPath), p));
207
212
 
@@ -209,8 +214,8 @@ async function resolveAndMergeNestedLint(
209
214
  ? configPath
210
215
  : configPath && path.resolve(configPath);
211
216
 
212
- const extendConfigs: ResolvedLintConfig[] = await Promise.all(
213
- lintConfig?.extends?.map(async (presetItem) => {
217
+ const extendConfigs: ResolvedStyleguideConfig[] = await Promise.all(
218
+ styleguideConfig?.extends?.map(async (presetItem) => {
214
219
  if (!isAbsoluteUrl(presetItem) && !path.extname(presetItem)) {
215
220
  return resolvePreset(presetItem, plugins);
216
221
  }
@@ -219,23 +224,23 @@ async function resolveAndMergeNestedLint(
219
224
  : isAbsoluteUrl(configPath)
220
225
  ? new URL(presetItem, configPath).href
221
226
  : path.resolve(path.dirname(configPath), presetItem);
222
- const extendedLintConfig = await loadExtendLintConfig(pathItem, resolver);
223
- return await resolveAndMergeNestedLint(
227
+ const extendedStyleguideConfig = await loadExtendStyleguideConfig(pathItem, resolver);
228
+ return await resolveAndMergeNestedStyleguideConfig(
224
229
  {
225
- lintConfig: extendedLintConfig,
230
+ styleguideConfig: extendedStyleguideConfig,
226
231
  configPath: pathItem,
227
232
  resolver: resolver,
228
233
  },
229
234
  [...parentConfigPaths, resolvedConfigPath],
230
- extendPaths,
235
+ extendPaths
231
236
  );
232
- }) || [],
237
+ }) || []
233
238
  );
234
239
 
235
- const { plugins: mergedPlugins = [], ...lint } = mergeExtends([
240
+ const { plugins: mergedPlugins = [], ...styleguide } = mergeExtends([
236
241
  ...extendConfigs,
237
242
  {
238
- ...lintConfig,
243
+ ...styleguideConfig,
239
244
  plugins,
240
245
  extends: undefined,
241
246
  extendPaths: [...parentConfigPaths, resolvedConfigPath],
@@ -244,91 +249,125 @@ async function resolveAndMergeNestedLint(
244
249
  ]);
245
250
 
246
251
  return {
247
- ...lint,
248
- extendPaths: lint.extendPaths?.filter((path) => path && !isAbsoluteUrl(path)),
252
+ ...styleguide,
253
+ extendPaths: styleguide.extendPaths?.filter((path) => path && !isAbsoluteUrl(path)),
249
254
  plugins: getUniquePlugins(mergedPlugins),
250
- recommendedFallback: lintConfig?.recommendedFallback,
251
- doNotResolveExamples: lintConfig?.doNotResolveExamples,
255
+ recommendedFallback: styleguideConfig?.recommendedFallback,
256
+ doNotResolveExamples: styleguideConfig?.doNotResolveExamples,
252
257
  };
253
258
  }
254
259
 
255
- export async function resolveLint(
256
- lintOpts: {
257
- lintConfig?: LintRawConfig;
260
+ export async function resolveStyleguideConfig(
261
+ opts: {
262
+ styleguideConfig?: StyleguideRawConfig;
258
263
  configPath?: string;
259
264
  resolver?: BaseResolver;
260
265
  },
261
266
  parentConfigPaths: string[] = [],
262
- extendPaths: string[] = [],
263
- ): Promise<ResolvedLintConfig> {
264
- const resolvedLint = await resolveAndMergeNestedLint(lintOpts, parentConfigPaths, extendPaths);
267
+ extendPaths: string[] = []
268
+ ): Promise<ResolvedStyleguideConfig> {
269
+ const resolvedStyleguideConfig = await resolveAndMergeNestedStyleguideConfig(
270
+ opts,
271
+ parentConfigPaths,
272
+ extendPaths
273
+ );
265
274
 
266
275
  return {
267
- ...resolvedLint,
268
- rules: resolvedLint.rules && groupLintAssertionRules(resolvedLint.rules),
276
+ ...resolvedStyleguideConfig,
277
+ rules:
278
+ resolvedStyleguideConfig.rules &&
279
+ groupStyleguideAssertionRules(resolvedStyleguideConfig.rules),
269
280
  };
270
281
  }
271
282
 
272
- export function resolvePreset(presetName: string, plugins: Plugin[]): ResolvedLintConfig {
283
+ export function resolvePreset(presetName: string, plugins: Plugin[]): ResolvedStyleguideConfig {
273
284
  const { pluginId, configName } = parsePresetName(presetName);
274
285
  const plugin = plugins.find((p) => p.id === pluginId);
275
286
  if (!plugin) {
276
287
  throw new Error(`Invalid config ${red(presetName)}: plugin ${pluginId} is not included.`);
277
288
  }
278
289
 
279
- const preset = plugin.configs?.[configName]! as ResolvedLintConfig;
290
+ const preset = plugin.configs?.[configName]! as ResolvedStyleguideConfig;
280
291
  if (!preset) {
281
292
  throw new Error(
282
293
  pluginId
283
294
  ? `Invalid config ${red(
284
- presetName,
295
+ presetName
285
296
  )}: plugin ${pluginId} doesn't export config with name ${configName}.`
286
- : `Invalid config ${red(presetName)}: there is no such built-in config.`,
297
+ : `Invalid config ${red(presetName)}: there is no such built-in config.`
287
298
  );
288
299
  }
289
300
  return preset;
290
301
  }
291
302
 
292
- async function loadExtendLintConfig(
303
+ async function loadExtendStyleguideConfig(
293
304
  filePath: string,
294
- resolver: BaseResolver,
295
- ): Promise<LintRawConfig> {
305
+ resolver: BaseResolver
306
+ ): Promise<StyleguideRawConfig> {
296
307
  try {
297
308
  const fileSource = await resolver.loadExternalRef(filePath);
298
- const rawConfig = transformConfig(parseYaml(fileSource.body) as RawConfig);
299
- if (!rawConfig.lint) {
300
- throw new Error(`Lint configuration format not detected: "${filePath}"`);
309
+ const rawConfig = transformConfig(
310
+ parseYaml(fileSource.body) as RawConfig & DeprecatedInRawConfig
311
+ );
312
+ if (!rawConfig.styleguide) {
313
+ throw new Error(`Styleguide configuration format not detected: "${filePath}"`);
301
314
  }
302
315
 
303
- return rawConfig.lint;
316
+ return rawConfig.styleguide;
304
317
  } catch (error) {
305
318
  throw new Error(`Failed to load "${filePath}": ${error.message}`);
306
319
  }
307
320
  }
308
321
 
309
- function getMergedLintRawConfig(configLint: LintRawConfig, apiLint?: LintRawConfig) {
322
+ function getMergedRawStyleguideConfig(
323
+ rootStyleguideConfig: StyleguideRawConfig,
324
+ apiStyleguideConfig?: ApiStyleguideRawConfig
325
+ ) {
310
326
  const resultLint = {
311
- ...configLint,
312
- ...apiLint,
313
- rules: { ...configLint?.rules, ...apiLint?.rules },
314
- oas2Rules: { ...configLint?.oas2Rules, ...apiLint?.oas2Rules },
315
- oas3_0Rules: { ...configLint?.oas3_0Rules, ...apiLint?.oas3_0Rules },
316
- oas3_1Rules: { ...configLint?.oas3_1Rules, ...apiLint?.oas3_1Rules },
317
- preprocessors: { ...configLint?.preprocessors, ...apiLint?.preprocessors },
318
- oas2Preprocessors: { ...configLint?.oas2Preprocessors, ...apiLint?.oas2Preprocessors },
319
- oas3_0Preprocessors: { ...configLint?.oas3_0Preprocessors, ...apiLint?.oas3_0Preprocessors },
320
- oas3_1Preprocessors: { ...configLint?.oas3_1Preprocessors, ...apiLint?.oas3_1Preprocessors },
321
- decorators: { ...configLint?.decorators, ...apiLint?.decorators },
322
- oas2Decorators: { ...configLint?.oas2Decorators, ...apiLint?.oas2Decorators },
323
- oas3_0Decorators: { ...configLint?.oas3_0Decorators, ...apiLint?.oas3_0Decorators },
324
- oas3_1Decorators: { ...configLint?.oas3_1Decorators, ...apiLint?.oas3_1Decorators },
325
- recommendedFallback: apiLint?.extends ? false : configLint.recommendedFallback,
327
+ ...rootStyleguideConfig,
328
+ ...apiStyleguideConfig,
329
+ rules: { ...rootStyleguideConfig?.rules, ...apiStyleguideConfig?.rules },
330
+ oas2Rules: { ...rootStyleguideConfig?.oas2Rules, ...apiStyleguideConfig?.oas2Rules },
331
+ oas3_0Rules: { ...rootStyleguideConfig?.oas3_0Rules, ...apiStyleguideConfig?.oas3_0Rules },
332
+ oas3_1Rules: { ...rootStyleguideConfig?.oas3_1Rules, ...apiStyleguideConfig?.oas3_1Rules },
333
+ preprocessors: {
334
+ ...rootStyleguideConfig?.preprocessors,
335
+ ...apiStyleguideConfig?.preprocessors,
336
+ },
337
+ oas2Preprocessors: {
338
+ ...rootStyleguideConfig?.oas2Preprocessors,
339
+ ...apiStyleguideConfig?.oas2Preprocessors,
340
+ },
341
+ oas3_0Preprocessors: {
342
+ ...rootStyleguideConfig?.oas3_0Preprocessors,
343
+ ...apiStyleguideConfig?.oas3_0Preprocessors,
344
+ },
345
+ oas3_1Preprocessors: {
346
+ ...rootStyleguideConfig?.oas3_1Preprocessors,
347
+ ...apiStyleguideConfig?.oas3_1Preprocessors,
348
+ },
349
+ decorators: { ...rootStyleguideConfig?.decorators, ...apiStyleguideConfig?.decorators },
350
+ oas2Decorators: {
351
+ ...rootStyleguideConfig?.oas2Decorators,
352
+ ...apiStyleguideConfig?.oas2Decorators,
353
+ },
354
+ oas3_0Decorators: {
355
+ ...rootStyleguideConfig?.oas3_0Decorators,
356
+ ...apiStyleguideConfig?.oas3_0Decorators,
357
+ },
358
+ oas3_1Decorators: {
359
+ ...rootStyleguideConfig?.oas3_1Decorators,
360
+ ...apiStyleguideConfig?.oas3_1Decorators,
361
+ },
362
+ recommendedFallback: apiStyleguideConfig?.extends
363
+ ? false
364
+ : rootStyleguideConfig.recommendedFallback,
326
365
  };
327
366
  return resultLint;
328
367
  }
329
368
 
330
- function groupLintAssertionRules(
331
- rules: Record<string, RuleConfig> | undefined,
369
+ function groupStyleguideAssertionRules(
370
+ rules: Record<string, RuleConfig> | undefined
332
371
  ): Record<string, RuleConfig> | undefined {
333
372
  if (!rules) {
334
373
  return rules;
@@ -14,7 +14,7 @@ import type {
14
14
  ResolveConfig,
15
15
  ResolvedApi,
16
16
  ResolvedConfig,
17
- ResolvedLintConfig,
17
+ ResolvedStyleguideConfig,
18
18
  RuleConfig,
19
19
  } from './types';
20
20
  import { getResolveConfig } from './utils';
@@ -59,7 +59,7 @@ function getIgnoreFilePath(configFile?: string): string | undefined {
59
59
  export const DOMAINS = getDomains();
60
60
  export const AVAILABLE_REGIONS = Object.keys(DOMAINS) as Region[];
61
61
 
62
- export class LintConfig {
62
+ export class StyleguideConfig {
63
63
  plugins: Plugin[];
64
64
  ignore: Record<string, Record<string, Set<string>>> = {};
65
65
  doNotResolveExamples: boolean;
@@ -75,7 +75,7 @@ export class LintConfig {
75
75
  extendPaths: string[];
76
76
  pluginPaths: string[];
77
77
 
78
- constructor(public rawConfig: ResolvedLintConfig, public configFile?: string) {
78
+ constructor(public rawConfig: ResolvedStyleguideConfig, public configFile?: string) {
79
79
  this.plugins = rawConfig.plugins || [];
80
80
  this.doNotResolveExamples = !!rawConfig.doNotResolveExamples;
81
81
 
@@ -297,7 +297,7 @@ export class LintConfig {
297
297
 
298
298
  export class Config {
299
299
  apis: Record<string, ResolvedApi>;
300
- lint: LintConfig;
300
+ styleguide: StyleguideConfig;
301
301
  resolve: ResolveConfig;
302
302
  licenseKey?: string;
303
303
  region?: Region;
@@ -306,7 +306,7 @@ export class Config {
306
306
  organization?: string;
307
307
  constructor(public rawConfig: ResolvedConfig, public configFile?: string) {
308
308
  this.apis = rawConfig.apis || {};
309
- this.lint = new LintConfig(rawConfig.lint || {}, configFile);
309
+ this.styleguide = new StyleguideConfig(rawConfig.styleguide || {}, configFile);
310
310
  this['features.openapi'] = rawConfig['features.openapi'] || {};
311
311
  this['features.mockServer'] = rawConfig['features.mockServer'] || {};
312
312
  this.resolve = getResolveConfig(rawConfig?.resolve);
@@ -6,7 +6,7 @@ import { Config, DOMAINS } from './config';
6
6
  import { transformConfig } from './utils';
7
7
  import { resolveConfig } from './config-resolvers';
8
8
 
9
- import type { RawConfig, Region } from './types';
9
+ import type { DeprecatedInRawConfig, RawConfig, Region } from './types';
10
10
 
11
11
  async function addConfigMetadata({
12
12
  rawConfig,
@@ -18,11 +18,11 @@ async function addConfigMetadata({
18
18
  configPath?: string;
19
19
  }): Promise<Config> {
20
20
  if (customExtends !== undefined) {
21
- rawConfig.lint = rawConfig.lint || {};
22
- rawConfig.lint.extends = customExtends;
21
+ rawConfig.styleguide = rawConfig.styleguide || {};
22
+ rawConfig.styleguide.extends = customExtends;
23
23
  } else if (isEmptyObject(rawConfig)) {
24
24
  // TODO: check if we can add recommended here. add message here?
25
- // rawConfig.lint = { extends: ['recommended'], recommendedFallback: true };
25
+ // rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
26
26
  }
27
27
 
28
28
  const redoclyClient = new RedoclyClient();
@@ -93,10 +93,10 @@ export function findConfig(dir?: string): string | undefined {
93
93
  return existingConfigFiles[0];
94
94
  }
95
95
 
96
- export async function getConfig(configPath: string | undefined = findConfig()) {
96
+ export async function getConfig(configPath: string | undefined = findConfig()): Promise<RawConfig> {
97
97
  if (!configPath || !doesYamlFileExist(configPath)) return {};
98
98
  try {
99
- const rawConfig = ((await loadYaml(configPath)) || {}) as RawConfig;
99
+ const rawConfig = (await loadYaml<RawConfig & DeprecatedInRawConfig>(configPath)) || {};
100
100
  return transformConfig(rawConfig);
101
101
  } catch (e) {
102
102
  throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
@@ -1,4 +1,4 @@
1
- import type { PluginLintConfig } from './types';
1
+ import type { PluginStyleguideConfig } from './types';
2
2
 
3
3
  export default {
4
4
  rules: {
@@ -18,7 +18,7 @@ export default {
18
18
  'operation-description': 'off',
19
19
  'operation-2xx-response': 'warn',
20
20
  'operation-4xx-response': 'off',
21
- 'assertions': 'warn',
21
+ assertions: 'warn',
22
22
  'operation-operationId': 'warn',
23
23
  'operation-summary': 'warn',
24
24
  'operation-operationId-unique': 'warn',
@@ -55,4 +55,4 @@ export default {
55
55
  'no-undefined-server-variable': 'warn',
56
56
  'no-servers-empty-enum': 'error',
57
57
  },
58
- } as PluginLintConfig;
58
+ } as PluginStyleguideConfig;
@@ -1,4 +1,4 @@
1
- import type { PluginLintConfig } from './types';
1
+ import type { PluginStyleguideConfig } from './types';
2
2
 
3
3
  export default {
4
4
  rules: {
@@ -17,7 +17,7 @@ export default {
17
17
  'path-parameters-defined': 'error',
18
18
  'operation-description': 'off',
19
19
  'operation-2xx-response': 'warn',
20
- 'assertions': 'warn',
20
+ assertions: 'warn',
21
21
  'operation-4xx-response': 'warn',
22
22
  'operation-operationId': 'warn',
23
23
  'operation-summary': 'error',
@@ -55,4 +55,4 @@ export default {
55
55
  'no-undefined-server-variable': 'error',
56
56
  'no-servers-empty-enum': 'error',
57
57
  },
58
- } as PluginLintConfig;
58
+ } as PluginStyleguideConfig;
@@ -1,12 +1,12 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
- import { LintConfig } from './config';
2
+ import { StyleguideConfig } from './config';
3
3
  import { notUndefined } from '../utils';
4
4
 
5
5
  export function initRules<T extends Function, P extends RuleSet<T>>(
6
6
  rules: P[],
7
- config: LintConfig,
7
+ config: StyleguideConfig,
8
8
  type: 'rules' | 'preprocessors' | 'decorators',
9
- oasVersion: OasVersion,
9
+ oasVersion: OasVersion
10
10
  ) {
11
11
  return rules
12
12
  .flatMap((ruleset) =>
@@ -31,7 +31,7 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
31
31
  severity: ruleSettings.severity,
32
32
  ruleId,
33
33
  visitor: visitor,
34
- }))
34
+ }));
35
35
  }
36
36
 
37
37
  return {
@@ -39,8 +39,8 @@ export function initRules<T extends Function, P extends RuleSet<T>>(
39
39
  ruleId,
40
40
  visitor: visitors, // note: actually it is only one visitor object
41
41
  };
42
- }),
42
+ })
43
43
  )
44
- .flatMap(visitor => visitor)
44
+ .flatMap((visitor) => visitor)
45
45
  .filter(notUndefined);
46
46
  }
@@ -29,7 +29,7 @@ export type PreprocessorConfig =
29
29
 
30
30
  export type DecoratorConfig = PreprocessorConfig;
31
31
 
32
- export type LintRawConfig = {
32
+ export type StyleguideRawConfig = {
33
33
  plugins?: (string | Plugin)[];
34
34
  extends?: string[];
35
35
  doNotResolveExamples?: boolean;
@@ -51,7 +51,9 @@ export type LintRawConfig = {
51
51
  oas3_1Decorators?: Record<string, DecoratorConfig>;
52
52
  };
53
53
 
54
- export type ResolvedLintConfig = PluginLintConfig & {
54
+ export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
55
+
56
+ export type ResolvedStyleguideConfig = PluginStyleguideConfig & {
55
57
  plugins?: Plugin[];
56
58
  recommendedFallback?: boolean;
57
59
  extends?: void | never;
@@ -71,7 +73,7 @@ export type DecoratorsConfig = {
71
73
 
72
74
  export type TypesExtensionFn = (
73
75
  types: Record<string, NodeType>,
74
- oasVersion: OasVersion,
76
+ oasVersion: OasVersion
75
77
  ) => Record<string, NodeType>;
76
78
 
77
79
  export type TypeExtensionsConfig = Partial<Record<OasMajorVersion, TypesExtensionFn>>;
@@ -83,14 +85,14 @@ export type CustomRulesConfig = {
83
85
 
84
86
  export type Plugin = {
85
87
  id: string;
86
- configs?: Record<string, PluginLintConfig>;
88
+ configs?: Record<string, PluginStyleguideConfig>;
87
89
  rules?: CustomRulesConfig;
88
90
  preprocessors?: PreprocessorsConfig;
89
91
  decorators?: DecoratorsConfig;
90
92
  typeExtension?: TypeExtensionsConfig;
91
93
  };
92
94
 
93
- export type PluginLintConfig = Omit<LintRawConfig, 'plugins' | 'extends'>;
95
+ export type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
94
96
 
95
97
  export type ResolveHeader =
96
98
  | {
@@ -123,35 +125,42 @@ export type Region = 'us' | 'eu';
123
125
 
124
126
  export type AccessTokens = { [region in Region]?: string };
125
127
 
126
- export type DeprecatedRawConfig = {
128
+ export type DeprecatedInRawConfig = {
127
129
  apiDefinitions?: Record<string, string>;
128
- lint?: LintRawConfig;
129
- resolve?: RawResolveConfig;
130
- region?: Region;
130
+ lint?: StyleguideRawConfig;
131
131
  referenceDocs?: Record<string, any>;
132
+ apis?: Record<string, Api & DeprecatedInApi>;
132
133
  };
133
134
 
134
135
  export type Api = {
135
136
  root: string;
136
- lint?: Omit<LintRawConfig, 'plugins'>;
137
- 'features.openapi'?: Record<string, any>;
138
- 'features.mockServer'?: Record<string, any>;
137
+ styleguide?: ApiStyleguideRawConfig;
138
+ } & FeaturesConfig;
139
+
140
+ export type DeprecatedInApi = {
141
+ lint?: ApiStyleguideRawConfig;
142
+ };
143
+
144
+ export type ResolvedApi = Omit<Api, 'styleguide'> & {
145
+ styleguide: ResolvedStyleguideConfig;
139
146
  };
140
- export type ResolvedApi = Omit<Api, 'lint'> & { lint: Omit<ResolvedLintConfig, 'plugins'>};
141
147
 
142
148
  export type RawConfig = {
143
149
  apis?: Record<string, Api>;
144
- lint?: LintRawConfig;
150
+ styleguide?: StyleguideRawConfig;
145
151
  resolve?: RawResolveConfig;
146
152
  region?: Region;
147
- 'features.openapi'?: Record<string, any>;
148
- 'features.mockServer'?: Record<string, any>;
149
153
  organization?: string;
154
+ } & FeaturesConfig;
155
+
156
+ export type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
157
+ apis: Record<string, ResolvedApi>;
158
+ styleguide: ResolvedStyleguideConfig;
150
159
  };
151
160
 
152
- export type ResolvedConfig = Omit<RawConfig, 'lint' | 'apis'> & {
153
- lint: ResolvedLintConfig;
154
- apis: Record<string,ResolvedApi>
161
+ type FeaturesConfig = {
162
+ 'features.openapi'?: Record<string, any>;
163
+ 'features.mockServer'?: Record<string, any>;
155
164
  };
156
165
 
157
166
  export type RulesFields =