@redocly/openapi-core 1.0.0-beta.105 → 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.
Files changed (240) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +2 -2
  8. package/lib/bundle.js +7 -4
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +3 -3
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +70 -49
  15. package/lib/config/config.d.ts +8 -10
  16. package/lib/config/config.js +10 -7
  17. package/lib/config/load.d.ts +7 -0
  18. package/lib/config/load.js +18 -10
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +5 -4
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +5 -4
  23. package/lib/config/rules.d.ts +3 -3
  24. package/lib/config/rules.js +1 -1
  25. package/lib/config/types.d.ts +23 -19
  26. package/lib/config/utils.d.ts +5 -5
  27. package/lib/config/utils.js +48 -31
  28. package/lib/decorators/common/registry-dependencies.js +1 -1
  29. package/lib/decorators/common/remove-x-internal.js +2 -2
  30. package/lib/env.d.ts +3 -0
  31. package/lib/env.js +8 -0
  32. package/lib/format/codeframes.js +16 -10
  33. package/lib/format/format.js +29 -27
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +4 -2
  36. package/lib/js-yaml/index.js +2 -6
  37. package/lib/lint.d.ts +2 -2
  38. package/lib/lint.js +16 -6
  39. package/lib/logger.d.ts +10 -0
  40. package/lib/logger.js +31 -0
  41. package/lib/output.d.ts +3 -0
  42. package/lib/output.js +9 -0
  43. package/lib/redocly/index.js +10 -9
  44. package/lib/redocly/registry-api-types.d.ts +28 -30
  45. package/lib/redocly/registry-api.d.ts +4 -3
  46. package/lib/redocly/registry-api.js +9 -4
  47. package/lib/ref-utils.js +2 -1
  48. package/lib/resolve.d.ts +1 -1
  49. package/lib/resolve.js +1 -1
  50. package/lib/rules/ajv.d.ts +1 -1
  51. package/lib/rules/ajv.js +7 -7
  52. package/lib/rules/common/assertions/asserts.js +4 -4
  53. package/lib/rules/common/assertions/index.js +1 -1
  54. package/lib/rules/common/info-license-url.d.ts +1 -1
  55. package/lib/rules/common/info-license-url.js +5 -10
  56. package/lib/rules/common/info-license.d.ts +2 -0
  57. package/lib/rules/common/info-license.js +17 -0
  58. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  59. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  60. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  61. package/lib/rules/common/operation-operationId.js +1 -1
  62. package/lib/rules/common/operation-security-defined.js +1 -1
  63. package/lib/rules/common/path-not-include-query.js +1 -1
  64. package/lib/rules/common/paths-kebab-case.js +4 -1
  65. package/lib/rules/common/spec.js +3 -3
  66. package/lib/rules/oas2/index.js +4 -4
  67. package/lib/rules/oas2/remove-unused-components.js +5 -5
  68. package/lib/rules/oas3/index.js +6 -6
  69. package/lib/rules/oas3/no-empty-servers.js +1 -1
  70. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  71. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  72. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  73. package/lib/rules/oas3/no-unused-components.js +1 -1
  74. package/lib/rules/oas3/remove-unused-components.js +5 -5
  75. package/lib/rules/other/stats.js +43 -14
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +20 -5
  78. package/lib/types/index.d.ts +2 -2
  79. package/lib/types/redocly-yaml.js +9 -8
  80. package/lib/utils.d.ts +5 -0
  81. package/lib/utils.js +22 -5
  82. package/lib/visitors.d.ts +1 -1
  83. package/lib/visitors.js +2 -2
  84. package/lib/walk.d.ts +2 -1
  85. package/lib/walk.js +6 -3
  86. package/package.json +2 -2
  87. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  88. package/src/__tests__/bundle.test.ts +68 -34
  89. package/src/__tests__/codeframes.test.ts +13 -14
  90. package/src/__tests__/js-yaml.test.ts +6 -4
  91. package/src/__tests__/lint.test.ts +74 -6
  92. package/src/__tests__/logger-browser.test.ts +53 -0
  93. package/src/__tests__/logger.test.ts +47 -0
  94. package/src/__tests__/login.test.ts +2 -2
  95. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  96. package/src/__tests__/output-browser.test.ts +18 -0
  97. package/src/__tests__/output.test.ts +15 -0
  98. package/src/__tests__/ref-utils.test.ts +13 -13
  99. package/src/__tests__/resolve-http.test.ts +1 -1
  100. package/src/__tests__/resolve.test.ts +14 -11
  101. package/src/__tests__/utils-browser.test.ts +11 -0
  102. package/src/__tests__/utils.test.ts +7 -0
  103. package/src/__tests__/walk.test.ts +48 -56
  104. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  105. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  106. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  107. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
  108. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  109. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  110. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  111. package/src/benchmark/benchmark.js +9 -5
  112. package/src/benchmark/utils.ts +5 -5
  113. package/src/bundle.ts +24 -20
  114. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
  115. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  116. package/src/config/__tests__/config.test.ts +111 -76
  117. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  118. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  119. package/src/config/__tests__/load.test.ts +79 -1
  120. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  121. package/src/config/__tests__/utils.test.ts +83 -0
  122. package/src/config/all.ts +5 -6
  123. package/src/config/builtIn.ts +5 -5
  124. package/src/config/config-resolvers.ts +161 -96
  125. package/src/config/config.ts +15 -13
  126. package/src/config/load.ts +34 -11
  127. package/src/config/minimal.ts +7 -6
  128. package/src/config/recommended.ts +7 -6
  129. package/src/config/rules.ts +6 -6
  130. package/src/config/types.ts +28 -19
  131. package/src/config/utils.ts +78 -57
  132. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  133. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  134. package/src/decorators/common/filters/filter-helper.ts +1 -1
  135. package/src/decorators/common/info-description-override.ts +1 -1
  136. package/src/decorators/common/operation-description-override.ts +1 -1
  137. package/src/decorators/common/registry-dependencies.ts +1 -1
  138. package/src/decorators/common/remove-x-internal.ts +4 -4
  139. package/src/decorators/common/tag-description-override.ts +1 -1
  140. package/src/env.ts +5 -0
  141. package/src/format/codeframes.ts +18 -12
  142. package/src/format/format.ts +37 -42
  143. package/src/index.ts +8 -7
  144. package/src/js-yaml/index.ts +4 -8
  145. package/src/lint.ts +22 -18
  146. package/src/logger.ts +34 -0
  147. package/src/oas-types.ts +1 -6
  148. package/src/output.ts +7 -0
  149. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  150. package/src/redocly/index.ts +12 -7
  151. package/src/redocly/registry-api-types.ts +27 -29
  152. package/src/redocly/registry-api.ts +22 -12
  153. package/src/ref-utils.ts +4 -3
  154. package/src/resolve.ts +11 -8
  155. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  156. package/src/rules/__tests__/utils.test.ts +160 -0
  157. package/src/rules/ajv.ts +7 -8
  158. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  159. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  160. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  161. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  162. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  163. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  164. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  165. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  166. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  167. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  168. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  169. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  170. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  171. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  172. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  173. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  174. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  175. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  176. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  177. package/src/rules/common/__tests__/spec.test.ts +2 -2
  178. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  179. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  180. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  181. package/src/rules/common/assertions/asserts.ts +4 -4
  182. package/src/rules/common/assertions/index.ts +7 -7
  183. package/src/rules/common/info-license-url.ts +4 -9
  184. package/src/rules/common/info-license.ts +15 -0
  185. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  186. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  187. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  188. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  189. package/src/rules/common/operation-operationId.ts +1 -1
  190. package/src/rules/common/operation-parameters-unique.ts +2 -2
  191. package/src/rules/common/operation-security-defined.ts +1 -1
  192. package/src/rules/common/path-not-include-query.ts +1 -1
  193. package/src/rules/common/path-params-defined.ts +1 -1
  194. package/src/rules/common/paths-kebab-case.ts +4 -1
  195. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  196. package/src/rules/common/spec.ts +12 -9
  197. package/src/rules/no-unresolved-refs.ts +1 -1
  198. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  199. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  200. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  201. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  202. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  203. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  204. package/src/rules/oas2/index.ts +3 -3
  205. package/src/rules/oas2/remove-unused-components.ts +14 -9
  206. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  207. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  208. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  209. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  210. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  211. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  212. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  213. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  214. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  215. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  216. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  217. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  218. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  219. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  220. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  221. package/src/rules/oas3/index.ts +5 -5
  222. package/src/rules/oas3/no-empty-servers.ts +1 -1
  223. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  224. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
  225. package/src/rules/oas3/no-unused-components.ts +1 -1
  226. package/src/rules/oas3/remove-unused-components.ts +21 -10
  227. package/src/rules/other/stats.ts +46 -17
  228. package/src/rules/utils.ts +20 -4
  229. package/src/types/index.ts +5 -5
  230. package/src/types/redocly-yaml.ts +9 -8
  231. package/src/typings/common.ts +9 -1
  232. package/src/typings/openapi.ts +1 -1
  233. package/src/utils.ts +26 -3
  234. package/src/visitors.ts +9 -9
  235. package/src/walk.ts +15 -11
  236. package/tsconfig.tsbuildinfo +1 -1
  237. package/lib/rules/common/license-url.d.ts +0 -2
  238. package/lib/rules/common/license-url.js +0 -12
  239. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  240. package/src/rules/common/license-url.ts +0 -10
@@ -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',
@@ -36,7 +36,7 @@ export default {
36
36
  oas3_0Rules: {
37
37
  'no-invalid-media-type-examples': {
38
38
  severity: 'warn',
39
- disallowAdditionalProperties: true,
39
+ allowAdditionalProperties: false,
40
40
  },
41
41
  'no-server-example.com': 'warn',
42
42
  'no-server-trailing-slash': 'error',
@@ -44,15 +44,16 @@ export default {
44
44
  'no-example-value-and-externalValue': 'warn',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'warn',
47
- 'no-servers-empty-enum': 'error',
47
+ 'no-server-variables-empty-enum': 'error',
48
48
  },
49
49
  oas3_1Rules: {
50
+ 'no-invalid-media-type-examples': 'warn',
50
51
  'no-server-example.com': 'warn',
51
52
  'no-server-trailing-slash': 'error',
52
53
  'no-empty-servers': 'warn',
53
54
  'no-example-value-and-externalValue': 'warn',
54
55
  'no-unused-components': 'warn',
55
56
  'no-undefined-server-variable': 'warn',
56
- 'no-servers-empty-enum': 'error',
57
+ 'no-server-variables-empty-enum': 'error',
57
58
  },
58
- } as PluginLintConfig;
59
+ } 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',
@@ -36,7 +36,7 @@ export default {
36
36
  oas3_0Rules: {
37
37
  'no-invalid-media-type-examples': {
38
38
  severity: 'warn',
39
- disallowAdditionalProperties: true,
39
+ allowAdditionalProperties: false,
40
40
  },
41
41
  'no-server-example.com': 'warn',
42
42
  'no-server-trailing-slash': 'error',
@@ -44,15 +44,16 @@ export default {
44
44
  'no-example-value-and-externalValue': 'error',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'error',
47
- 'no-servers-empty-enum': 'error',
47
+ 'no-server-variables-empty-enum': 'error',
48
48
  },
49
49
  oas3_1Rules: {
50
+ 'no-invalid-media-type-examples': 'warn',
50
51
  'no-server-example.com': 'warn',
51
52
  'no-server-trailing-slash': 'error',
52
53
  'no-empty-servers': 'error',
53
54
  'no-example-value-and-externalValue': 'error',
54
55
  'no-unused-components': 'warn',
55
56
  'no-undefined-server-variable': 'error',
56
- 'no-servers-empty-enum': 'error',
57
+ 'no-server-variables-empty-enum': 'error',
57
58
  },
58
- } as PluginLintConfig;
59
+ } 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 =
@@ -1,17 +1,23 @@
1
- import { green, yellow } from 'colorette';
2
- import { assignExisting } from '../utils';
1
+ import {
2
+ assignExisting,
3
+ isTruthy,
4
+ showErrorForDeprecatedField,
5
+ showWarningForDeprecatedField,
6
+ } from '../utils';
3
7
  import { Config } from './config';
4
8
 
5
9
  import type {
6
10
  Api,
7
- DeprecatedRawConfig,
11
+ DeprecatedInApi,
12
+ DeprecatedInRawConfig,
8
13
  Plugin,
9
14
  RawConfig,
10
15
  RawResolveConfig,
11
16
  ResolveConfig,
12
- ResolvedLintConfig,
17
+ ResolvedStyleguideConfig,
13
18
  RulesFields,
14
19
  } from './types';
20
+ import { logger, colorize } from '../logger';
15
21
 
16
22
  export function parsePresetName(presetName: string): { pluginId: string; configName: string } {
17
23
  if (presetName.indexOf('/') > -1) {
@@ -23,15 +29,27 @@ export function parsePresetName(presetName: string): { pluginId: string; configN
23
29
  }
24
30
 
25
31
  export function transformApiDefinitionsToApis(
26
- apiDefinitions: Record<string, string> = {},
27
- ): Record<string, Api> {
28
- let apis: Record<string, Api> = {};
32
+ apiDefinitions?: DeprecatedInRawConfig['apiDefinitions']
33
+ ): Record<string, Api> | undefined {
34
+ if (!apiDefinitions) return undefined;
35
+ const apis: Record<string, Api> = {};
29
36
  for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
30
37
  apis[apiName] = { root: apiPath };
31
38
  }
32
39
  return apis;
33
40
  }
34
41
 
42
+ function transformApis(
43
+ legacyApis?: Record<string, Api & DeprecatedInApi>
44
+ ): Record<string, Api> | undefined {
45
+ if (!legacyApis) return undefined;
46
+ const apis: Record<string, Api> = {};
47
+ for (const [apiName, { lint, ...apiContent }] of Object.entries(legacyApis)) {
48
+ apis[apiName] = { styleguide: lint, ...apiContent };
49
+ }
50
+ return apis;
51
+ }
52
+
35
53
  export function prefixRules<T extends Record<string, any>>(rules: T, prefix: string) {
36
54
  if (!prefix) return rules;
37
55
 
@@ -43,9 +61,9 @@ export function prefixRules<T extends Record<string, any>>(rules: T, prefix: str
43
61
  return res;
44
62
  }
45
63
 
46
- export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
47
- const result: Omit<ResolvedLintConfig, RulesFields> &
48
- Required<Pick<ResolvedLintConfig, RulesFields>> = {
64
+ export function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]) {
65
+ const result: Omit<ResolvedStyleguideConfig, RulesFields> &
66
+ Required<Pick<ResolvedStyleguideConfig, RulesFields>> = {
49
67
  rules: {},
50
68
  oas2Rules: {},
51
69
  oas3_0Rules: {},
@@ -66,14 +84,10 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
66
84
  extendPaths: [],
67
85
  };
68
86
 
69
- for (let rulesConf of rulesConfList) {
87
+ for (const rulesConf of rulesConfList) {
70
88
  if (rulesConf.extends) {
71
89
  throw new Error(
72
- `\`extends\` is not supported in shared configs yet: ${JSON.stringify(
73
- rulesConf,
74
- null,
75
- 2,
76
- )}.`,
90
+ `'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`
77
91
  );
78
92
  }
79
93
 
@@ -109,75 +123,84 @@ export function mergeExtends(rulesConfList: ResolvedLintConfig[]) {
109
123
  return result;
110
124
  }
111
125
 
112
- export function getMergedConfig(config: Config, entrypointAlias?: string): Config {
126
+ export function getMergedConfig(config: Config, apiName?: string): Config {
113
127
  const extendPaths = [
114
- ...Object.values(config.apis).map((api) => api?.lint?.extendPaths),
115
- config.rawConfig?.lint?.extendPaths,
128
+ ...Object.values(config.apis).map((api) => api?.styleguide?.extendPaths),
129
+ config.rawConfig?.styleguide?.extendPaths,
116
130
  ]
117
131
  .flat()
118
- .filter(Boolean) as string[];
132
+ .filter(isTruthy);
119
133
 
120
134
  const pluginPaths = [
121
- ...Object.values(config.apis).map((api) => api?.lint?.pluginPaths),
122
- config.rawConfig?.lint?.pluginPaths,
135
+ ...Object.values(config.apis).map((api) => api?.styleguide?.pluginPaths),
136
+ config.rawConfig?.styleguide?.pluginPaths,
123
137
  ]
124
138
  .flat()
125
- .filter(Boolean) as string[];
139
+ .filter(isTruthy);
126
140
 
127
- return entrypointAlias
141
+ return apiName
128
142
  ? new Config(
129
143
  {
130
144
  ...config.rawConfig,
131
- lint: {
132
- ...(config.apis[entrypointAlias]
133
- ? config.apis[entrypointAlias].lint
134
- : config.rawConfig.lint),
145
+ styleguide: {
146
+ ...(config.apis[apiName]
147
+ ? config.apis[apiName].styleguide
148
+ : config.rawConfig.styleguide),
135
149
  extendPaths,
136
150
  pluginPaths,
137
151
  },
138
152
  'features.openapi': {
139
153
  ...config['features.openapi'],
140
- ...config.apis[entrypointAlias]?.['features.openapi'],
154
+ ...config.apis[apiName]?.['features.openapi'],
141
155
  },
142
156
  'features.mockServer': {
143
157
  ...config['features.mockServer'],
144
- ...config.apis[entrypointAlias]?.['features.mockServer'],
158
+ ...config.apis[apiName]?.['features.mockServer'],
145
159
  },
146
160
  // TODO: merge everything else here
147
161
  },
148
- config.configFile,
162
+ config.configFile
149
163
  )
150
164
  : config;
151
165
  }
152
166
 
153
- export function transformConfig(rawConfig: DeprecatedRawConfig | RawConfig): RawConfig {
154
- if ((rawConfig as RawConfig).apis && (rawConfig as DeprecatedRawConfig).apiDefinitions) {
155
- throw new Error("Do not use 'apiDefinitions' field. Use 'apis' instead.\n");
156
- }
157
- if (
158
- (rawConfig as RawConfig)['features.openapi'] &&
159
- (rawConfig as DeprecatedRawConfig).referenceDocs
160
- ) {
161
- throw new Error("Do not use 'referenceDocs' field. Use 'features.openapi' instead.\n");
162
- }
163
- const { apiDefinitions, referenceDocs, ...rest } = rawConfig as DeprecatedRawConfig & RawConfig;
164
- if (apiDefinitions) {
165
- process.stderr.write(
166
- `The ${yellow('apiDefinitions')} field is deprecated. Use ${green(
167
- 'apis',
168
- )} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`,
167
+ function checkForDeprecatedFields(
168
+ deprecatedField: keyof DeprecatedInRawConfig,
169
+ updatedField: keyof RawConfig,
170
+ rawConfig: DeprecatedInRawConfig & RawConfig
171
+ ): void {
172
+ const isDeprecatedFieldInApis =
173
+ rawConfig.apis &&
174
+ Object.values(rawConfig.apis).some(
175
+ (api: Api & DeprecatedInApi & DeprecatedInRawConfig) => api[deprecatedField]
169
176
  );
177
+
178
+ if (rawConfig[deprecatedField] && rawConfig[updatedField]) {
179
+ showErrorForDeprecatedField(deprecatedField, updatedField);
170
180
  }
171
- if (referenceDocs) {
172
- process.stderr.write(
173
- `The ${yellow('referenceDocs')} field is deprecated. Use ${green(
174
- 'features.openapi',
175
- )} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`,
176
- );
181
+
182
+ if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
183
+ showWarningForDeprecatedField(deprecatedField, updatedField);
184
+ }
185
+ }
186
+
187
+ export function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig {
188
+ const migratedFields: [keyof DeprecatedInRawConfig, keyof RawConfig][] = [
189
+ ['apiDefinitions', 'apis'],
190
+ ['referenceDocs', 'features.openapi'],
191
+ ['lint', 'styleguide'], // TODO: update docs
192
+ ];
193
+
194
+ for (const [deprecatedField, updatedField] of migratedFields) {
195
+ checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
177
196
  }
197
+
198
+ const { apis, apiDefinitions, referenceDocs, lint, ...rest } = rawConfig;
199
+
178
200
  return {
179
201
  'features.openapi': referenceDocs,
180
- apis: transformApiDefinitionsToApis(apiDefinitions),
202
+ apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions),
203
+ styleguide: lint,
181
204
  ...rest,
182
205
  };
183
206
  }
@@ -199,9 +222,7 @@ export function getUniquePlugins(plugins: Plugin[]): Plugin[] {
199
222
  results.push(p);
200
223
  seen.add(p.id);
201
224
  } else if (p.id) {
202
- process.stderr.write(
203
- `Duplicate plugin id "${yellow(p.id)}".\n`,
204
- );
225
+ logger.warn(`Duplicate plugin id "${colorize.red(p.id)}".\n`);
205
226
  }
206
227
  }
207
228
  return results;
@@ -27,7 +27,8 @@ describe('oas3 filter-out', () => {
27
27
  callbacks:
28
28
  x-access: protected
29
29
  orderInProgress:
30
- x-internal: true`);
30
+ x-internal: true`
31
+ );
31
32
 
32
33
  it('should remove /pet path and y parameter', async () => {
33
34
  const testDocument = parseYamlToDocument(
@@ -132,7 +133,8 @@ describe('oas3 filter-out', () => {
132
133
  type: object
133
134
  components: {}
134
135
 
135
- `);
136
+ `
137
+ );
136
138
  const { bundle: res } = await bundleDocument({
137
139
  document: testDoc,
138
140
  externalRefResolver: new BaseResolver(),
@@ -185,7 +187,8 @@ describe('oas3 filter-out', () => {
185
187
  x:
186
188
  name: x
187
189
 
188
- `);
190
+ `
191
+ );
189
192
  const { bundle: res } = await bundleDocument({
190
193
  document: testDocument,
191
194
  externalRefResolver: new BaseResolver(),
@@ -236,7 +239,8 @@ describe('oas3 filter-out', () => {
236
239
  x:
237
240
  name: x
238
241
 
239
- `);
242
+ `
243
+ );
240
244
  const { bundle: res } = await bundleDocument({
241
245
  document: testDocument,
242
246
  externalRefResolver: new BaseResolver(),
@@ -18,7 +18,7 @@ describe('oas3 remove-x-internal', () => {
18
18
  parameters:
19
19
  x:
20
20
  name: x
21
- `,
21
+ `
22
22
  );
23
23
 
24
24
  it('should use `internalFlagProperty` option to remove internal paths', async () => {
@@ -87,7 +87,7 @@ describe('oas3 remove-x-internal', () => {
87
87
  name: x
88
88
  y:
89
89
  name: y
90
- `,
90
+ `
91
91
  );
92
92
  const { bundle: res } = await bundleDocument({
93
93
  document: testDoc,
@@ -160,7 +160,7 @@ describe('oas3 remove-x-internal', () => {
160
160
  servers:
161
161
  - url: //callback-url.path-level/v1
162
162
  description: Path level server
163
- `,
163
+ `
164
164
  );
165
165
  const { bundle: res } = await bundleDocument({
166
166
  document: testDoc,
@@ -234,7 +234,7 @@ describe('oas3 remove-x-internal', () => {
234
234
  schema:
235
235
  type: string
236
236
  x-internal: true
237
- `,
237
+ `
238
238
  );
239
239
  const { bundle: res } = await bundleDocument({
240
240
  document: testDoc,
@@ -297,7 +297,7 @@ describe('oas2 remove-x-internal', () => {
297
297
  '200':
298
298
  x-internal: true
299
299
  description: List of recent media entries.
300
- `,
300
+ `
301
301
  );
302
302
  const { bundle: res } = await bundleDocument({
303
303
  document: testDoc,
@@ -47,7 +47,7 @@ export function checkIfMatchByStrategy(
47
47
  decoratorValue: any,
48
48
  strategy: 'all' | 'any'
49
49
  ): boolean {
50
- if (nodeValue===undefined || decoratorValue===undefined) {
50
+ if (nodeValue === undefined || decoratorValue === undefined) {
51
51
  return false;
52
52
  }
53
53
 
@@ -8,7 +8,7 @@ export const InfoDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ filePat
8
8
  leave(info, { report, location }: UserContext) {
9
9
  if (!filePath)
10
10
  throw new Error(
11
- `Parameter "filePath" is not provided for "info-description-override" rule`,
11
+ `Parameter "filePath" is not provided for "info-description-override" rule`
12
12
  );
13
13
  try {
14
14
  info.description = readFileAsStringSync(filePath);
@@ -11,7 +11,7 @@ export const OperationDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ op
11
11
  if (!operation.operationId) return;
12
12
  if (!operationIds)
13
13
  throw new Error(
14
- `Parameter "operationIds" is not provided for "operation-description-override" rule`,
14
+ `Parameter "operationIds" is not provided for "operation-description-override" rule`
15
15
  );
16
16
  const operationId = operation.operationId;
17
17
  if (operationIds[operationId]) {
@@ -4,7 +4,7 @@ import { isRedoclyRegistryURL } from '../../redocly';
4
4
  import { Oas3Decorator, Oas2Decorator } from '../../visitors';
5
5
 
6
6
  export const RegistryDependencies: Oas3Decorator | Oas2Decorator = () => {
7
- let registryDependencies = new Set<string>();
7
+ const registryDependencies = new Set<string>();
8
8
 
9
9
  return {
10
10
  DefinitionRoot: {
@@ -53,7 +53,7 @@ export const RemoveXInternal: Oas3Decorator | Oas2Decorator = ({ internalFlagPro
53
53
  any: {
54
54
  enter: (node, ctx) => {
55
55
  removeInternal(node, ctx);
56
- }
57
- }
58
- }
59
- }
56
+ },
57
+ },
58
+ };
59
+ };
@@ -8,7 +8,7 @@ export const TagDescriptionOverride: Oas3Decorator | Oas2Decorator = ({ tagNames
8
8
  leave(tag, { report }: UserContext) {
9
9
  if (!tagNames)
10
10
  throw new Error(
11
- `Parameter "tagNames" is not provided for "tag-description-override" rule`,
11
+ `Parameter "tagNames" is not provided for "tag-description-override" rule`
12
12
  );
13
13
  if (tagNames[tag.name]) {
14
14
  try {
package/src/env.ts ADDED
@@ -0,0 +1,5 @@
1
+ export const isBrowser =
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore
4
+ typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
5
+ export const env = isBrowser ? {} : process.env || {};