@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
@@ -9,28 +9,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
12
+ exports.createConfig = exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
13
13
  const fs = require("fs");
14
14
  const path = require("path");
15
15
  const redocly_1 = require("../redocly");
16
16
  const utils_1 = require("../utils");
17
+ const js_yaml_1 = require("../js-yaml");
17
18
  const config_1 = require("./config");
18
19
  const utils_2 = require("./utils");
19
20
  const config_resolvers_1 = require("./config-resolvers");
20
- function addConfigMetadata({ rawConfig, customExtends, configPath, }) {
21
+ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
21
22
  var _a;
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
24
  if (customExtends !== undefined) {
24
- rawConfig.lint = rawConfig.lint || {};
25
- rawConfig.lint.extends = customExtends;
25
+ rawConfig.styleguide = rawConfig.styleguide || {};
26
+ rawConfig.styleguide.extends = customExtends;
26
27
  }
27
28
  else if (utils_1.isEmptyObject(rawConfig)) {
28
29
  // TODO: check if we can add recommended here. add message here?
29
- // rawConfig.lint = { extends: ['recommended'], recommendedFallback: true };
30
+ // rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
30
31
  }
31
- const redoclyClient = new redocly_1.RedoclyClient();
32
- const tokens = yield redoclyClient.getTokens();
33
- if (tokens.length) {
32
+ if (tokens === null || tokens === void 0 ? void 0 : tokens.length) {
34
33
  if (!rawConfig.resolve)
35
34
  rawConfig.resolve = {};
36
35
  if (!rawConfig.resolve.http)
@@ -66,10 +65,13 @@ function loadConfig(configPath = findConfig(), customExtends, processRawConfig)
66
65
  if (typeof processRawConfig === 'function') {
67
66
  yield processRawConfig(rawConfig);
68
67
  }
69
- return yield addConfigMetadata({
68
+ const redoclyClient = new redocly_1.RedoclyClient();
69
+ const tokens = yield redoclyClient.getTokens();
70
+ return addConfigMetadata({
70
71
  rawConfig,
71
72
  customExtends,
72
73
  configPath,
74
+ tokens,
73
75
  });
74
76
  });
75
77
  }
@@ -94,7 +96,7 @@ function getConfig(configPath = findConfig()) {
94
96
  if (!configPath || !utils_1.doesYamlFileExist(configPath))
95
97
  return {};
96
98
  try {
97
- const rawConfig = ((yield utils_1.loadYaml(configPath)) || {});
99
+ const rawConfig = (yield utils_1.loadYaml(configPath)) || {};
98
100
  return utils_2.transformConfig(rawConfig);
99
101
  }
100
102
  catch (e) {
@@ -103,3 +105,9 @@ function getConfig(configPath = findConfig()) {
103
105
  });
104
106
  }
105
107
  exports.getConfig = getConfig;
108
+ function createConfig(config, options) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ return addConfigMetadata(Object.assign({ rawConfig: utils_2.transformConfig(typeof config === 'string' ? js_yaml_1.parseYaml(config) : config) }, options));
111
+ });
112
+ }
113
+ exports.createConfig = createConfig;
@@ -1,3 +1,3 @@
1
- import type { PluginLintConfig } from './types';
2
- declare const _default: PluginLintConfig;
1
+ import type { PluginStyleguideConfig } from './types';
2
+ declare const _default: PluginStyleguideConfig;
3
3
  export default _default;
@@ -18,7 +18,7 @@ exports.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 @@ exports.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 @@ exports.default = {
44
44
  'no-example-value-and-externalValue': 'warn',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'warn',
47
- 'no-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
59
  };
@@ -1,3 +1,3 @@
1
- import type { PluginLintConfig } from './types';
2
- declare const _default: PluginLintConfig;
1
+ import type { PluginStyleguideConfig } from './types';
2
+ declare const _default: PluginStyleguideConfig;
3
3
  export default _default;
@@ -17,7 +17,7 @@ exports.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 @@ exports.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 @@ exports.default = {
44
44
  'no-example-value-and-externalValue': 'error',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'error',
47
- 'no-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
59
  };
@@ -1,7 +1,7 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
- import { LintConfig } from './config';
3
- export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: LintConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
4
- severity: import("./types").RuleSeverity;
2
+ import { StyleguideConfig } from './config';
3
+ export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
4
+ severity: string;
5
5
  ruleId: string;
6
6
  visitor: any;
7
7
  }[];
@@ -28,7 +28,7 @@ function initRules(rules, config, type, oasVersion) {
28
28
  visitor: visitors, // note: actually it is only one visitor object
29
29
  };
30
30
  }))
31
- .flatMap(visitor => visitor)
31
+ .flatMap((visitor) => visitor)
32
32
  .filter(utils_1.notUndefined);
33
33
  }
34
34
  exports.initRules = initRules;
@@ -10,7 +10,7 @@ export declare type PreprocessorConfig = PreprocessorSeverity | ({
10
10
  severity?: ProblemSeverity;
11
11
  } & Record<string, any>);
12
12
  export declare type DecoratorConfig = PreprocessorConfig;
13
- export declare type LintRawConfig = {
13
+ export declare type StyleguideRawConfig = {
14
14
  plugins?: (string | Plugin)[];
15
15
  extends?: string[];
16
16
  doNotResolveExamples?: boolean;
@@ -28,7 +28,8 @@ export declare type LintRawConfig = {
28
28
  oas3_0Decorators?: Record<string, DecoratorConfig>;
29
29
  oas3_1Decorators?: Record<string, DecoratorConfig>;
30
30
  };
31
- export declare type ResolvedLintConfig = PluginLintConfig & {
31
+ export declare type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
32
+ export declare type ResolvedStyleguideConfig = PluginStyleguideConfig & {
32
33
  plugins?: Plugin[];
33
34
  recommendedFallback?: boolean;
34
35
  extends?: void | never;
@@ -51,13 +52,13 @@ export declare type CustomRulesConfig = {
51
52
  };
52
53
  export declare type Plugin = {
53
54
  id: string;
54
- configs?: Record<string, PluginLintConfig>;
55
+ configs?: Record<string, PluginStyleguideConfig>;
55
56
  rules?: CustomRulesConfig;
56
57
  preprocessors?: PreprocessorsConfig;
57
58
  decorators?: DecoratorsConfig;
58
59
  typeExtension?: TypeExtensionsConfig;
59
60
  };
60
- export declare type PluginLintConfig = Omit<LintRawConfig, 'plugins' | 'extends'>;
61
+ export declare type PluginStyleguideConfig = Omit<StyleguideRawConfig, 'plugins' | 'extends'>;
61
62
  export declare type ResolveHeader = {
62
63
  name: string;
63
64
  envVariable?: undefined;
@@ -83,33 +84,36 @@ export declare type Region = 'us' | 'eu';
83
84
  export declare type AccessTokens = {
84
85
  [region in Region]?: string;
85
86
  };
86
- export declare type DeprecatedRawConfig = {
87
+ export declare type DeprecatedInRawConfig = {
87
88
  apiDefinitions?: Record<string, string>;
88
- lint?: LintRawConfig;
89
- resolve?: RawResolveConfig;
90
- region?: Region;
89
+ lint?: StyleguideRawConfig;
91
90
  referenceDocs?: Record<string, any>;
91
+ apis?: Record<string, Api & DeprecatedInApi>;
92
92
  };
93
93
  export declare type Api = {
94
94
  root: string;
95
- lint?: Omit<LintRawConfig, 'plugins'>;
96
- 'features.openapi'?: Record<string, any>;
97
- 'features.mockServer'?: Record<string, any>;
95
+ styleguide?: ApiStyleguideRawConfig;
96
+ } & FeaturesConfig;
97
+ export declare type DeprecatedInApi = {
98
+ lint?: ApiStyleguideRawConfig;
98
99
  };
99
- export declare type ResolvedApi = Omit<Api, 'lint'> & {
100
- lint: Omit<ResolvedLintConfig, 'plugins'>;
100
+ export declare type ResolvedApi = Omit<Api, 'styleguide'> & {
101
+ styleguide: ResolvedStyleguideConfig;
101
102
  };
102
103
  export declare type RawConfig = {
103
104
  apis?: Record<string, Api>;
104
- lint?: LintRawConfig;
105
+ styleguide?: StyleguideRawConfig;
105
106
  resolve?: RawResolveConfig;
106
107
  region?: Region;
107
- 'features.openapi'?: Record<string, any>;
108
- 'features.mockServer'?: Record<string, any>;
109
108
  organization?: string;
110
- };
111
- export declare type ResolvedConfig = Omit<RawConfig, 'lint' | 'apis'> & {
112
- lint: ResolvedLintConfig;
109
+ } & FeaturesConfig;
110
+ export declare type ResolvedConfig = Omit<RawConfig, 'apis' | 'styleguide'> & {
113
111
  apis: Record<string, ResolvedApi>;
112
+ styleguide: ResolvedStyleguideConfig;
113
+ };
114
+ declare type FeaturesConfig = {
115
+ 'features.openapi'?: Record<string, any>;
116
+ 'features.mockServer'?: Record<string, any>;
114
117
  };
115
118
  export declare type RulesFields = 'rules' | 'oas2Rules' | 'oas3_0Rules' | 'oas3_1Rules' | 'preprocessors' | 'oas2Preprocessors' | 'oas3_0Preprocessors' | 'oas3_1Preprocessors' | 'decorators' | 'oas2Decorators' | 'oas3_0Decorators' | 'oas3_1Decorators';
119
+ export {};
@@ -1,13 +1,13 @@
1
1
  import { Config } from './config';
2
- import type { Api, DeprecatedRawConfig, Plugin, RawConfig, RawResolveConfig, ResolveConfig, ResolvedLintConfig, RulesFields } from './types';
2
+ import type { Api, DeprecatedInRawConfig, Plugin, RawConfig, RawResolveConfig, ResolveConfig, ResolvedStyleguideConfig, RulesFields } from './types';
3
3
  export declare function parsePresetName(presetName: string): {
4
4
  pluginId: string;
5
5
  configName: string;
6
6
  };
7
- export declare function transformApiDefinitionsToApis(apiDefinitions?: Record<string, string>): Record<string, Api>;
7
+ export declare function transformApiDefinitionsToApis(apiDefinitions?: DeprecatedInRawConfig['apiDefinitions']): Record<string, Api> | undefined;
8
8
  export declare function prefixRules<T extends Record<string, any>>(rules: T, prefix: string): any;
9
- export declare function mergeExtends(rulesConfList: ResolvedLintConfig[]): Omit<ResolvedLintConfig, RulesFields> & Required<Pick<ResolvedLintConfig, RulesFields>>;
10
- export declare function getMergedConfig(config: Config, entrypointAlias?: string): Config;
11
- export declare function transformConfig(rawConfig: DeprecatedRawConfig | RawConfig): RawConfig;
9
+ export declare function mergeExtends(rulesConfList: ResolvedStyleguideConfig[]): Omit<ResolvedStyleguideConfig, RulesFields> & Required<Pick<ResolvedStyleguideConfig, RulesFields>>;
10
+ export declare function getMergedConfig(config: Config, apiName?: string): Config;
11
+ export declare function transformConfig(rawConfig: DeprecatedInRawConfig & RawConfig): RawConfig;
12
12
  export declare function getResolveConfig(resolve?: RawResolveConfig): ResolveConfig;
13
13
  export declare function getUniquePlugins(plugins: Plugin[]): Plugin[];
@@ -12,9 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.getUniquePlugins = exports.getResolveConfig = exports.transformConfig = exports.getMergedConfig = exports.mergeExtends = exports.prefixRules = exports.transformApiDefinitionsToApis = exports.parsePresetName = void 0;
15
- const colorette_1 = require("colorette");
16
15
  const utils_1 = require("../utils");
17
16
  const config_1 = require("./config");
17
+ const logger_1 = require("../logger");
18
18
  function parsePresetName(presetName) {
19
19
  if (presetName.indexOf('/') > -1) {
20
20
  const [pluginId, configName] = presetName.split('/');
@@ -25,14 +25,26 @@ function parsePresetName(presetName) {
25
25
  }
26
26
  }
27
27
  exports.parsePresetName = parsePresetName;
28
- function transformApiDefinitionsToApis(apiDefinitions = {}) {
29
- let apis = {};
28
+ function transformApiDefinitionsToApis(apiDefinitions) {
29
+ if (!apiDefinitions)
30
+ return undefined;
31
+ const apis = {};
30
32
  for (const [apiName, apiPath] of Object.entries(apiDefinitions)) {
31
33
  apis[apiName] = { root: apiPath };
32
34
  }
33
35
  return apis;
34
36
  }
35
37
  exports.transformApiDefinitionsToApis = transformApiDefinitionsToApis;
38
+ function transformApis(legacyApis) {
39
+ if (!legacyApis)
40
+ return undefined;
41
+ const apis = {};
42
+ for (let _a of Object.entries(legacyApis)) {
43
+ const [apiName, _b] = _a, { lint } = _b, apiContent = __rest(_b, ["lint"]);
44
+ apis[apiName] = Object.assign({ styleguide: lint }, apiContent);
45
+ }
46
+ return apis;
47
+ }
36
48
  function prefixRules(rules, prefix) {
37
49
  if (!prefix)
38
50
  return rules;
@@ -61,9 +73,9 @@ function mergeExtends(rulesConfList) {
61
73
  pluginPaths: [],
62
74
  extendPaths: [],
63
75
  };
64
- for (let rulesConf of rulesConfList) {
76
+ for (const rulesConf of rulesConfList) {
65
77
  if (rulesConf.extends) {
66
- throw new Error(`\`extends\` is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
78
+ throw new Error(`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
67
79
  }
68
80
  Object.assign(result.rules, rulesConf.rules);
69
81
  Object.assign(result.oas2Rules, rulesConf.oas2Rules);
@@ -93,44 +105,49 @@ function mergeExtends(rulesConfList) {
93
105
  return result;
94
106
  }
95
107
  exports.mergeExtends = mergeExtends;
96
- function getMergedConfig(config, entrypointAlias) {
108
+ function getMergedConfig(config, apiName) {
97
109
  var _a, _b, _c, _d, _e, _f;
98
110
  const extendPaths = [
99
- ...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.lint) === null || _a === void 0 ? void 0 : _a.extendPaths; }),
100
- (_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.lint) === null || _b === void 0 ? void 0 : _b.extendPaths,
111
+ ...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.styleguide) === null || _a === void 0 ? void 0 : _a.extendPaths; }),
112
+ (_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.extendPaths,
101
113
  ]
102
114
  .flat()
103
- .filter(Boolean);
115
+ .filter(utils_1.isTruthy);
104
116
  const pluginPaths = [
105
- ...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.lint) === null || _a === void 0 ? void 0 : _a.pluginPaths; }),
106
- (_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.lint) === null || _d === void 0 ? void 0 : _d.pluginPaths,
117
+ ...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.styleguide) === null || _a === void 0 ? void 0 : _a.pluginPaths; }),
118
+ (_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.styleguide) === null || _d === void 0 ? void 0 : _d.pluginPaths,
107
119
  ]
108
120
  .flat()
109
- .filter(Boolean);
110
- return entrypointAlias
111
- ? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { lint: Object.assign(Object.assign({}, (config.apis[entrypointAlias]
112
- ? config.apis[entrypointAlias].lint
113
- : config.rawConfig.lint)), { extendPaths,
114
- pluginPaths }), 'features.openapi': Object.assign(Object.assign({}, config['features.openapi']), (_e = config.apis[entrypointAlias]) === null || _e === void 0 ? void 0 : _e['features.openapi']), 'features.mockServer': Object.assign(Object.assign({}, config['features.mockServer']), (_f = config.apis[entrypointAlias]) === null || _f === void 0 ? void 0 : _f['features.mockServer']) }), config.configFile)
121
+ .filter(utils_1.isTruthy);
122
+ return apiName
123
+ ? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { styleguide: Object.assign(Object.assign({}, (config.apis[apiName]
124
+ ? config.apis[apiName].styleguide
125
+ : config.rawConfig.styleguide)), { extendPaths,
126
+ pluginPaths }), 'features.openapi': Object.assign(Object.assign({}, config['features.openapi']), (_e = config.apis[apiName]) === null || _e === void 0 ? void 0 : _e['features.openapi']), 'features.mockServer': Object.assign(Object.assign({}, config['features.mockServer']), (_f = config.apis[apiName]) === null || _f === void 0 ? void 0 : _f['features.mockServer']) }), config.configFile)
115
127
  : config;
116
128
  }
117
129
  exports.getMergedConfig = getMergedConfig;
118
- function transformConfig(rawConfig) {
119
- if (rawConfig.apis && rawConfig.apiDefinitions) {
120
- throw new Error("Do not use 'apiDefinitions' field. Use 'apis' instead.\n");
130
+ function checkForDeprecatedFields(deprecatedField, updatedField, rawConfig) {
131
+ const isDeprecatedFieldInApis = rawConfig.apis &&
132
+ Object.values(rawConfig.apis).some((api) => api[deprecatedField]);
133
+ if (rawConfig[deprecatedField] && rawConfig[updatedField]) {
134
+ utils_1.showErrorForDeprecatedField(deprecatedField, updatedField);
121
135
  }
122
- if (rawConfig['features.openapi'] &&
123
- rawConfig.referenceDocs) {
124
- throw new Error("Do not use 'referenceDocs' field. Use 'features.openapi' instead.\n");
136
+ if (rawConfig[deprecatedField] || isDeprecatedFieldInApis) {
137
+ utils_1.showWarningForDeprecatedField(deprecatedField, updatedField);
125
138
  }
126
- const _a = rawConfig, { apiDefinitions, referenceDocs } = _a, rest = __rest(_a, ["apiDefinitions", "referenceDocs"]);
127
- if (apiDefinitions) {
128
- 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`);
129
- }
130
- if (referenceDocs) {
131
- 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`);
139
+ }
140
+ function transformConfig(rawConfig) {
141
+ const migratedFields = [
142
+ ['apiDefinitions', 'apis'],
143
+ ['referenceDocs', 'features.openapi'],
144
+ ['lint', 'styleguide'], // TODO: update docs
145
+ ];
146
+ for (const [deprecatedField, updatedField] of migratedFields) {
147
+ checkForDeprecatedFields(deprecatedField, updatedField, rawConfig);
132
148
  }
133
- return Object.assign({ 'features.openapi': referenceDocs, apis: transformApiDefinitionsToApis(apiDefinitions) }, rest);
149
+ const { apis, apiDefinitions, referenceDocs, lint } = rawConfig, rest = __rest(rawConfig, ["apis", "apiDefinitions", "referenceDocs", "lint"]);
150
+ return Object.assign({ 'features.openapi': referenceDocs, apis: transformApis(apis) || transformApiDefinitionsToApis(apiDefinitions), styleguide: lint }, rest);
134
151
  }
135
152
  exports.transformConfig = transformConfig;
136
153
  function getResolveConfig(resolve) {
@@ -152,7 +169,7 @@ function getUniquePlugins(plugins) {
152
169
  seen.add(p.id);
153
170
  }
154
171
  else if (p.id) {
155
- process.stderr.write(`Duplicate plugin id "${colorette_1.yellow(p.id)}".\n`);
172
+ logger_1.logger.warn(`Duplicate plugin id "${logger_1.colorize.red(p.id)}".\n`);
156
173
  }
157
174
  }
158
175
  return results;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegistryDependencies = void 0;
4
4
  const redocly_1 = require("../../redocly");
5
5
  const RegistryDependencies = () => {
6
- let registryDependencies = new Set();
6
+ const registryDependencies = new Set();
7
7
  return {
8
8
  DefinitionRoot: {
9
9
  leave(_, ctx) {
@@ -51,8 +51,8 @@ const RemoveXInternal = ({ internalFlagProperty }) => {
51
51
  any: {
52
52
  enter: (node, ctx) => {
53
53
  removeInternal(node, ctx);
54
- }
55
- }
54
+ },
55
+ },
56
56
  };
57
57
  };
58
58
  exports.RemoveXInternal = RemoveXInternal;
package/lib/env.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ export declare const isBrowser: boolean;
3
+ export declare const env: NodeJS.ProcessEnv;
package/lib/env.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.env = exports.isBrowser = void 0;
4
+ exports.isBrowser =
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore
7
+ typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
8
+ exports.env = exports.isBrowser ? {} : process.env || {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAstNodeByPointer = exports.getLineColLocation = exports.getCodeframe = void 0;
4
- const colorette_1 = require("colorette");
5
4
  const yamlAst = require("yaml-ast-parser");
6
5
  const ref_utils_1 = require("../ref-utils");
6
+ const logger_1 = require("../logger");
7
7
  const MAX_LINE_LENGTH = 150;
8
8
  const MAX_CODEFRAME_LINES = 3;
9
9
  // TODO: temporary
@@ -11,7 +11,7 @@ function parsePointer(pointer) {
11
11
  return pointer.substr(2).split('/').map(ref_utils_1.unescapePointer);
12
12
  }
13
13
  function getCodeframe(location, color) {
14
- colorette_1.options.enabled = color;
14
+ logger_1.colorOptions.enabled = color;
15
15
  const { start, end = { line: start.line, col: start.col + 1 }, source } = location;
16
16
  const lines = source.getLines();
17
17
  const startLineNum = start.line;
@@ -28,16 +28,22 @@ function getCodeframe(location, color) {
28
28
  const line = lines[i - 1] || '';
29
29
  if (line !== '')
30
30
  currentPad = padSize(line);
31
- let startIdx = i === startLineNum ? start.col - 1 : currentPad;
32
- let endIdx = i === endLineNum ? end.col - 1 : line.length;
33
- prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, colorette_1.red)]);
31
+ const startIdx = i === startLineNum ? start.col - 1 : currentPad;
32
+ const endIdx = i === endLineNum ? end.col - 1 : line.length;
33
+ prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, logger_1.colorize.red)]);
34
34
  if (!color)
35
35
  prefixedLines.push(['', underlineLine(line, startIdx, endIdx)]);
36
36
  }
37
37
  if (skipLines > 0) {
38
- prefixedLines.push([`…`, `${whitespace(currentPad)}${colorette_1.gray(`< ${skipLines} more lines >`)}`]);
38
+ prefixedLines.push([
39
+ `…`,
40
+ `${whitespace(currentPad)}${logger_1.colorize.gray(`< ${skipLines} more lines >`)}`,
41
+ ]);
39
42
  // print last line
40
- prefixedLines.push([`${endLineNum}`, markLine(lines[endLineNum - 1], -1, end.col - 1, colorette_1.red)]);
43
+ prefixedLines.push([
44
+ `${endLineNum}`,
45
+ markLine(lines[endLineNum - 1], -1, end.col - 1, logger_1.colorize.red),
46
+ ]);
41
47
  if (!color)
42
48
  prefixedLines.push(['', underlineLine(lines[endLineNum - 1], -1, end.col - 1)]);
43
49
  }
@@ -48,7 +54,7 @@ function getCodeframe(location, color) {
48
54
  [`${endLineNum + 1}`, markLine(lines[endLineNum - 1 + 1])],
49
55
  [`${endLineNum + 2}`, markLine(lines[endLineNum - 1 + 2])],
50
56
  ]);
51
- function markLine(line, startIdx = -1, endIdx = +Infinity, variant = colorette_1.gray) {
57
+ function markLine(line, startIdx = -1, endIdx = +Infinity, variant = logger_1.colorize.gray) {
52
58
  if (!color)
53
59
  return line;
54
60
  if (!line)
@@ -66,14 +72,14 @@ function printPrefixedLines(lines) {
66
72
  const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
67
73
  const dedentLen = Math.min(...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))));
68
74
  return existingLines
69
- .map(([prefix, line]) => colorette_1.gray(leftPad(padLen, prefix) + ' |') +
75
+ .map(([prefix, line]) => logger_1.colorize.gray(leftPad(padLen, prefix) + ' |') +
70
76
  (line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''))
71
77
  .join('\n');
72
78
  }
73
79
  function limitLineLength(line, maxLen = MAX_LINE_LENGTH) {
74
80
  const overflowLen = line.length - maxLen;
75
81
  if (overflowLen > 0) {
76
- const charsMoreText = colorette_1.gray(`...<${overflowLen} chars>`);
82
+ const charsMoreText = logger_1.colorize.gray(`...<${overflowLen} chars>`);
77
83
  return line.substring(0, maxLen - charsMoreText.length) + charsMoreText;
78
84
  }
79
85
  else {