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

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 (193) hide show
  1. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  2. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  3. package/lib/bundle.d.ts +1 -1
  4. package/lib/bundle.js +9 -6
  5. package/lib/config/all.js +5 -3
  6. package/lib/config/config-resolvers.js +32 -14
  7. package/lib/config/config.d.ts +3 -5
  8. package/lib/config/config.js +7 -4
  9. package/lib/config/load.d.ts +7 -0
  10. package/lib/config/load.js +14 -6
  11. package/lib/config/minimal.js +7 -4
  12. package/lib/config/recommended.js +7 -4
  13. package/lib/config/rules.d.ts +1 -1
  14. package/lib/config/rules.js +1 -1
  15. package/lib/config/types.d.ts +7 -0
  16. package/lib/config/utils.d.ts +2 -2
  17. package/lib/config/utils.js +49 -11
  18. package/lib/decorators/common/registry-dependencies.js +2 -2
  19. package/lib/env.d.ts +3 -0
  20. package/lib/env.js +8 -0
  21. package/lib/format/codeframes.js +16 -10
  22. package/lib/format/format.d.ts +1 -1
  23. package/lib/format/format.js +49 -26
  24. package/lib/index.d.ts +5 -5
  25. package/lib/index.js +3 -1
  26. package/lib/js-yaml/index.js +1 -0
  27. package/lib/lint.js +2 -2
  28. package/lib/logger.d.ts +10 -0
  29. package/lib/logger.js +31 -0
  30. package/lib/output.d.ts +3 -0
  31. package/lib/output.js +9 -0
  32. package/lib/redocly/index.js +10 -9
  33. package/lib/redocly/registry-api-types.d.ts +28 -30
  34. package/lib/redocly/registry-api.d.ts +3 -3
  35. package/lib/redocly/registry-api.js +7 -1
  36. package/lib/ref-utils.js +2 -1
  37. package/lib/resolve.d.ts +1 -1
  38. package/lib/resolve.js +4 -2
  39. package/lib/rules/ajv.d.ts +1 -1
  40. package/lib/rules/ajv.js +7 -7
  41. package/lib/rules/common/assertions/asserts.js +4 -4
  42. package/lib/rules/common/assertions/index.js +1 -1
  43. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  44. package/lib/rules/common/no-identical-paths.js +1 -1
  45. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  46. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  47. package/lib/rules/common/operation-2xx-response.js +1 -1
  48. package/lib/rules/common/operation-4xx-response.js +1 -1
  49. package/lib/rules/common/operation-operationId.js +1 -1
  50. package/lib/rules/common/operation-tag-defined.js +1 -1
  51. package/lib/rules/common/path-not-include-query.js +1 -1
  52. package/lib/rules/common/security-defined.d.ts +2 -0
  53. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
  54. package/lib/rules/common/spec.js +14 -3
  55. package/lib/rules/common/tags-alphabetical.js +1 -1
  56. package/lib/rules/oas2/index.d.ts +1 -1
  57. package/lib/rules/oas2/index.js +2 -2
  58. package/lib/rules/oas2/remove-unused-components.js +3 -3
  59. package/lib/rules/oas2/request-mime-type.js +1 -1
  60. package/lib/rules/oas2/response-mime-type.js +1 -1
  61. package/lib/rules/oas3/index.js +8 -4
  62. package/lib/rules/oas3/no-empty-servers.js +1 -1
  63. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  64. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  65. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
  66. package/lib/rules/oas3/no-unused-components.js +2 -2
  67. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  68. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  69. package/lib/rules/oas3/remove-unused-components.js +4 -4
  70. package/lib/rules/oas3/request-mime-type.js +1 -1
  71. package/lib/rules/oas3/response-mime-type.js +1 -1
  72. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  73. package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
  74. package/lib/rules/other/stats.d.ts +2 -2
  75. package/lib/rules/other/stats.js +2 -2
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +16 -4
  78. package/lib/types/oas2.js +5 -5
  79. package/lib/types/oas3.js +27 -20
  80. package/lib/types/oas3_1.js +3 -3
  81. package/lib/types/redocly-yaml.js +47 -56
  82. package/lib/utils.d.ts +6 -1
  83. package/lib/utils.js +24 -7
  84. package/lib/visitors.d.ts +12 -12
  85. package/lib/visitors.js +15 -3
  86. package/lib/walk.d.ts +2 -1
  87. package/lib/walk.js +6 -3
  88. package/package.json +2 -2
  89. package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
  90. package/src/__tests__/fixtures/extension.js +3 -3
  91. package/src/__tests__/format.test.ts +76 -0
  92. package/src/__tests__/lint.test.ts +106 -131
  93. package/src/__tests__/logger-browser.test.ts +53 -0
  94. package/src/__tests__/logger.test.ts +47 -0
  95. package/src/__tests__/output-browser.test.ts +18 -0
  96. package/src/__tests__/output.test.ts +15 -0
  97. package/src/__tests__/resolve-http.test.ts +1 -1
  98. package/src/__tests__/resolve.test.ts +9 -9
  99. package/src/__tests__/utils-browser.test.ts +11 -0
  100. package/src/__tests__/utils.test.ts +7 -0
  101. package/src/__tests__/walk.test.ts +78 -10
  102. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
  103. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  104. package/src/bundle.ts +10 -7
  105. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
  106. package/src/config/__tests__/config.test.ts +35 -0
  107. package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
  108. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
  109. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
  110. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
  111. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
  112. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
  113. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
  114. package/src/config/__tests__/load.test.ts +76 -1
  115. package/src/config/__tests__/utils.test.ts +64 -4
  116. package/src/config/all.ts +5 -3
  117. package/src/config/config-resolvers.ts +45 -19
  118. package/src/config/config.ts +10 -8
  119. package/src/config/load.ts +31 -7
  120. package/src/config/minimal.ts +7 -4
  121. package/src/config/recommended.ts +7 -4
  122. package/src/config/rules.ts +2 -2
  123. package/src/config/types.ts +11 -0
  124. package/src/config/utils.ts +115 -25
  125. package/src/decorators/common/registry-dependencies.ts +2 -2
  126. package/src/env.ts +5 -0
  127. package/src/format/codeframes.ts +15 -9
  128. package/src/format/format.ts +59 -34
  129. package/src/index.ts +6 -4
  130. package/src/js-yaml/index.ts +1 -0
  131. package/src/lint.ts +2 -2
  132. package/src/logger.ts +34 -0
  133. package/src/output.ts +7 -0
  134. package/src/redocly/index.ts +7 -4
  135. package/src/redocly/registry-api-types.ts +27 -29
  136. package/src/redocly/registry-api.ts +18 -7
  137. package/src/ref-utils.ts +2 -1
  138. package/src/resolve.ts +7 -5
  139. package/src/rules/__tests__/utils.test.ts +39 -1
  140. package/src/rules/ajv.ts +7 -7
  141. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
  142. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
  143. package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
  144. package/src/rules/common/__tests__/security-defined.test.ts +175 -0
  145. package/src/rules/common/__tests__/spec.test.ts +79 -0
  146. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  147. package/src/rules/common/assertions/asserts.ts +4 -4
  148. package/src/rules/common/assertions/index.ts +1 -1
  149. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  150. package/src/rules/common/no-identical-paths.ts +1 -1
  151. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  152. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  153. package/src/rules/common/operation-2xx-response.ts +1 -1
  154. package/src/rules/common/operation-4xx-response.ts +1 -1
  155. package/src/rules/common/operation-operationId.ts +1 -1
  156. package/src/rules/common/operation-tag-defined.ts +1 -1
  157. package/src/rules/common/path-not-include-query.ts +1 -1
  158. package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
  159. package/src/rules/common/spec.ts +17 -3
  160. package/src/rules/common/tags-alphabetical.ts +1 -1
  161. package/src/rules/oas2/index.ts +2 -2
  162. package/src/rules/oas2/remove-unused-components.ts +3 -3
  163. package/src/rules/oas2/request-mime-type.ts +1 -1
  164. package/src/rules/oas2/response-mime-type.ts +1 -1
  165. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  166. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
  167. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
  168. package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
  169. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
  170. package/src/rules/oas3/index.ts +8 -4
  171. package/src/rules/oas3/no-empty-servers.ts +1 -1
  172. package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
  173. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
  174. package/src/rules/oas3/no-unused-components.ts +2 -2
  175. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
  176. package/src/rules/oas3/remove-unused-components.ts +5 -5
  177. package/src/rules/oas3/request-mime-type.ts +1 -1
  178. package/src/rules/oas3/response-mime-type.ts +1 -1
  179. package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
  180. package/src/rules/other/stats.ts +2 -2
  181. package/src/rules/utils.ts +17 -3
  182. package/src/types/index.ts +2 -2
  183. package/src/types/oas2.ts +5 -5
  184. package/src/types/oas3.ts +27 -20
  185. package/src/types/oas3_1.ts +3 -3
  186. package/src/types/redocly-yaml.ts +53 -41
  187. package/src/utils.ts +31 -4
  188. package/src/visitors.ts +34 -18
  189. package/src/walk.ts +15 -11
  190. package/tsconfig.tsbuildinfo +1 -1
  191. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  192. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  193. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
package/lib/utils.js CHANGED
@@ -9,14 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
13
13
  const fs = require("fs");
14
14
  const path_1 = require("path");
15
15
  const minimatch = require("minimatch");
16
16
  const node_fetch_1 = require("node-fetch");
17
17
  const pluralize = require("pluralize");
18
18
  const js_yaml_1 = require("./js-yaml");
19
- const config_1 = require("./config");
19
+ const env_1 = require("./env");
20
+ const logger_1 = require("./logger");
20
21
  var js_yaml_2 = require("./js-yaml");
21
22
  Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
22
23
  Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
@@ -36,10 +37,10 @@ function loadYaml(filename) {
36
37
  });
37
38
  }
38
39
  exports.loadYaml = loadYaml;
39
- function notUndefined(x) {
40
+ function isDefined(x) {
40
41
  return x !== undefined;
41
42
  }
42
- exports.notUndefined = notUndefined;
43
+ exports.isDefined = isDefined;
43
44
  function isPlainObject(value) {
44
45
  return value !== null && typeof value === 'object' && !Array.isArray(value);
45
46
  }
@@ -58,7 +59,7 @@ function readFileFromUrl(url, config) {
58
59
  for (const header of config.headers) {
59
60
  if (match(url, header.matches)) {
60
61
  headers[header.name] =
61
- header.envVariable !== undefined ? config_1.env[header.envVariable] || '' : header.value;
62
+ header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
62
63
  }
63
64
  }
64
65
  const req = yield (config.customFetch || node_fetch_1.default)(url, {
@@ -89,7 +90,7 @@ exports.omitObjectProps = omitObjectProps;
89
90
  function splitCamelCaseIntoWords(str) {
90
91
  const camel = str
91
92
  .split(/(?:[-._])|([A-Z][a-z]+)/)
92
- .filter(Boolean)
93
+ .filter(isTruthy)
93
94
  .map((item) => item.toLocaleLowerCase());
94
95
  const caps = str
95
96
  .split(/([A-Z]{2,})/)
@@ -167,7 +168,7 @@ function isNotString(value) {
167
168
  }
168
169
  exports.isNotString = isNotString;
169
170
  function assignExisting(target, obj) {
170
- for (let k of Object.keys(obj)) {
171
+ for (const k of Object.keys(obj)) {
171
172
  if (target.hasOwnProperty(k)) {
172
173
  target[k] = obj[k];
173
174
  }
@@ -188,3 +189,19 @@ function doesYamlFileExist(filePath) {
188
189
  fs.existsSync(filePath));
189
190
  }
190
191
  exports.doesYamlFileExist = doesYamlFileExist;
192
+ function showWarningForDeprecatedField(deprecatedField, updatedField) {
193
+ logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField ? `Use ${logger_1.colorize.green(updatedField)} instead. ` : ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
194
+ }
195
+ exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
196
+ function showErrorForDeprecatedField(deprecatedField, updatedField) {
197
+ throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${updatedField}' instead. ` : ''}\n`);
198
+ }
199
+ exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
200
+ function isTruthy(value) {
201
+ return !!value;
202
+ }
203
+ exports.isTruthy = isTruthy;
204
+ function identity(value) {
205
+ return value;
206
+ }
207
+ exports.identity = identity;
package/lib/visitors.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Oas3Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3License, Oas3Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
2
- import { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
3
- import { NormalizedNodeType } from './types';
4
- import { Stack } from './utils';
5
- import { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
- import { Location } from './ref-utils';
2
+ import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
3
+ import type { NormalizedNodeType } from './types';
4
+ import type { Stack } from './utils';
5
+ import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
+ import type { Location } from './ref-utils';
7
7
  export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
8
8
  ignoreNextVisitorsOnNode: () => void;
9
9
  }, parents?: any, context?: any) => void;
@@ -16,7 +16,7 @@ declare type VisitObject<T> = {
16
16
  };
17
17
  declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
18
18
  declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
19
- declare type VisitorNode<T extends any> = {
19
+ declare type VisitorNode<T> = {
20
20
  ruleId: string;
21
21
  severity: ProblemSeverity;
22
22
  context: VisitorLevelContext | VisitorSkippedLevelContext;
@@ -61,7 +61,7 @@ export declare type BaseVisitor = {
61
61
  } | VisitRefFunction;
62
62
  };
63
63
  declare type Oas3FlatVisitor = {
64
- DefinitionRoot?: VisitFunctionOrObject<Oas3Definition>;
64
+ Root?: VisitFunctionOrObject<Oas3Definition>;
65
65
  Tag?: VisitFunctionOrObject<Oas3Tag>;
66
66
  ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
67
67
  Server?: VisitFunctionOrObject<Oas3Server>;
@@ -70,13 +70,13 @@ declare type Oas3FlatVisitor = {
70
70
  Info?: VisitFunctionOrObject<Oas3Info>;
71
71
  Contact?: VisitFunctionOrObject<Oas3Contact>;
72
72
  License?: VisitFunctionOrObject<Oas3License>;
73
- PathMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
73
+ PathsMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
74
74
  PathItem?: VisitFunctionOrObject<Oas3PathItem>;
75
75
  Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
76
76
  Parameter?: VisitFunctionOrObject<Oas3Parameter>;
77
77
  Operation?: VisitFunctionOrObject<Oas3Operation>;
78
78
  RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
79
- MediaTypeMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
79
+ MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
80
80
  MediaType?: VisitFunctionOrObject<Oas3MediaType>;
81
81
  Example?: VisitFunctionOrObject<Oas3Example>;
82
82
  Encoding?: VisitFunctionOrObject<Oas3Encoding>;
@@ -107,14 +107,14 @@ declare type Oas3FlatVisitor = {
107
107
  SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
108
108
  };
109
109
  declare type Oas2FlatVisitor = {
110
- DefinitionRoot?: VisitFunctionOrObject<Oas2Definition>;
110
+ Root?: VisitFunctionOrObject<Oas2Definition>;
111
111
  Tag?: VisitFunctionOrObject<Oas2Tag>;
112
112
  ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
113
113
  SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
114
114
  Info?: VisitFunctionOrObject<Oas2Info>;
115
115
  Contact?: VisitFunctionOrObject<Oas2Contact>;
116
116
  License?: VisitFunctionOrObject<Oas2License>;
117
- PathMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
117
+ PathsMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
118
118
  PathItem?: VisitFunctionOrObject<Oas2PathItem>;
119
119
  Parameter?: VisitFunctionOrObject<any>;
120
120
  Operation?: VisitFunctionOrObject<Oas2Operation>;
@@ -140,7 +140,7 @@ export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<strin
140
140
  export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
141
141
  export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
142
142
  export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
143
- export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'DefinitionRoot'>;
143
+ export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
144
144
  export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
145
145
  [V in keyof T]-?: {
146
146
  enter: Array<NormalizeVisitor<T[V]>>;
package/lib/visitors.js CHANGED
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeVisitors = void 0;
4
+ const legacyTypesMap = {
5
+ Root: 'DefinitionRoot',
6
+ ServerVariablesMap: 'ServerVariableMap',
7
+ PathsMap: 'PathMap',
8
+ CallbacksMap: 'CallbackMap',
9
+ MediaTypesMap: 'MediaTypeMap',
10
+ ExamplesMap: 'ExampleMap',
11
+ EncodingsMap: 'EncodingMap',
12
+ HeadersMap: 'HeaderMap',
13
+ LinksMap: 'LinkMap',
14
+ };
4
15
  function normalizeVisitors(visitorsConfig, types) {
5
16
  const normalizedVisitors = {};
6
17
  normalizedVisitors.any = {
@@ -30,7 +41,7 @@ function normalizeVisitors(visitorsConfig, types) {
30
41
  return;
31
42
  stack = [...stack, from];
32
43
  const possibleChildren = new Set();
33
- for (let type of Object.values(from.properties)) {
44
+ for (const type of Object.values(from.properties)) {
34
45
  if (type === to) {
35
46
  addWeakFromStack(ruleConf, stack);
36
47
  continue;
@@ -55,7 +66,7 @@ function normalizeVisitors(visitorsConfig, types) {
55
66
  possibleChildren.add(from.items);
56
67
  }
57
68
  }
58
- for (let fromType of Array.from(possibleChildren.values())) {
69
+ for (const fromType of Array.from(possibleChildren.values())) {
59
70
  addWeakNodes(ruleConf, fromType, to, parentContext, stack);
60
71
  }
61
72
  function addWeakFromStack(ruleConf, stack) {
@@ -89,7 +100,8 @@ function normalizeVisitors(visitorsConfig, types) {
89
100
  }
90
101
  }
91
102
  for (const typeName of visitorKeys) {
92
- const typeVisitor = visitor[typeName];
103
+ const typeVisitor = (visitor[typeName] ||
104
+ visitor[legacyTypesMap[typeName]]);
93
105
  const normalizedTypeVisitor = normalizedVisitors[typeName];
94
106
  if (!typeVisitor)
95
107
  continue;
package/lib/walk.d.ts CHANGED
@@ -4,6 +4,7 @@ import { NormalizedOasVisitors } from './visitors';
4
4
  import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
5
5
  import { OasVersion } from './oas-types';
6
6
  import { NormalizedNodeType } from './types';
7
+ import type { RuleSeverity } from './config';
7
8
  declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
8
9
  export declare type ResolveResult<T extends NonUndefined> = {
9
10
  node: T;
@@ -49,7 +50,7 @@ export declare type Problem = {
49
50
  suggest?: string[];
50
51
  location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
51
52
  from?: LocationObject;
52
- forceSeverity?: ProblemSeverity;
53
+ forceSeverity?: RuleSeverity;
53
54
  ruleId?: string;
54
55
  };
55
56
  export declare type NormalizedProblem = {
package/lib/walk.js CHANGED
@@ -249,9 +249,12 @@ function walkDocument(opts) {
249
249
  ? opts.location
250
250
  : [opts.location]
251
251
  : [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
252
- ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: opts.forceSeverity || severity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
253
- return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
254
- }) }));
252
+ const ruleSeverity = opts.forceSeverity || severity;
253
+ if (ruleSeverity !== 'off') {
254
+ ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
255
+ return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
256
+ }) }));
257
+ }
255
258
  }
256
259
  function getVisitorDataFn(ruleId) {
257
260
  ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.106",
3
+ "version": "1.0.0-beta.109",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -34,7 +34,7 @@
34
34
  "Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
35
35
  ],
36
36
  "dependencies": {
37
- "@redocly/ajv": "^8.6.4",
37
+ "@redocly/ajv": "^8.6.5",
38
38
  "@types/node": "^14.11.8",
39
39
  "colorette": "^1.2.0",
40
40
  "js-levenshtein": "^1.1.6",
@@ -47,7 +47,7 @@ rootType:
47
47
  description:
48
48
  type: string
49
49
  variables:
50
- name: ServerVariableMap
50
+ name: ServerVariablesMap
51
51
  properties: {}
52
52
  required:
53
53
  - url
@@ -94,7 +94,7 @@ rootType:
94
94
  name: ExternalDocs
95
95
  paths:
96
96
  properties: {}
97
- name: PathMap
97
+ name: PathsMap
98
98
  components:
99
99
  properties:
100
100
  parameters:
@@ -132,7 +132,7 @@ rootType:
132
132
  - openapi
133
133
  - paths
134
134
  - info
135
- name: DefinitionRoot
135
+ name: Root
136
136
  refTypes: {}
137
137
  visitorsData:
138
138
  registry-dependencies:
@@ -9,10 +9,10 @@ function oas3_0(types) {
9
9
  parameters: listOf('Parameter'),
10
10
  },
11
11
  },
12
- DefinitionRoot: {
13
- ...types.DefinitionRoot,
12
+ Root: {
13
+ ...types.Root,
14
14
  properties: {
15
- ...types.DefinitionRoot.properties,
15
+ ...types.Root.properties,
16
16
  'x-webhooks': 'XWebHooks',
17
17
  },
18
18
  },
@@ -0,0 +1,76 @@
1
+ import { outdent } from 'outdent';
2
+
3
+ import { formatProblems, getTotals } from '../format/format';
4
+
5
+ describe('format', () => {
6
+ function replaceColors(log: string) {
7
+ return log
8
+ .replace(/\x1b\[33m(.*?)\x1b\[39m/g, '<o>$1</o>') // orange
9
+ .replace(/\x1b\[31m(.*?)\x1b\[39m/g, '<r>$1</r>'); // red
10
+ }
11
+
12
+ const problems = [
13
+ {
14
+ ruleId: 'spec',
15
+ location: [],
16
+ severity: 'error' as const,
17
+ message: 'message',
18
+ suggest: [],
19
+ },
20
+ {
21
+ ruleId: 'spec',
22
+ location: [],
23
+ severity: 'error' as const,
24
+ message: 'message 2',
25
+ suggest: [],
26
+ },
27
+ {
28
+ ruleId: 'other-rule',
29
+ location: [],
30
+ severity: 'warn' as const,
31
+ message: 'message',
32
+ suggest: [],
33
+ },
34
+ ];
35
+
36
+ let output = '';
37
+ beforeEach(() => {
38
+ output = '';
39
+ jest.spyOn(process.stderr, 'write').mockImplementation((str: string | Uint8Array) => {
40
+ output += str;
41
+ return true;
42
+ });
43
+ });
44
+
45
+ it('should correctly format summary output', () => {
46
+ formatProblems(problems, {
47
+ format: 'summary',
48
+ version: '1.0.0',
49
+ totals: getTotals(problems),
50
+ color: false,
51
+ });
52
+
53
+ expect(output).toMatchInlineSnapshot(`
54
+ "error spec: 2
55
+ warning other-rule: 1
56
+
57
+ "
58
+ `);
59
+ });
60
+
61
+ it('should correctly format summary output in color mode', () => {
62
+ formatProblems(problems, {
63
+ format: 'summary',
64
+ version: '1.0.0',
65
+ totals: getTotals(problems),
66
+ color: true,
67
+ });
68
+
69
+ expect(replaceColors(output)).toMatchInlineSnapshot(`
70
+ "<r>error </r> spec: 2
71
+ <o>warning</o> other-rule: 1
72
+
73
+ "
74
+ `);
75
+ });
76
+ });