@redocly/openapi-core 1.18.1 → 1.19.0

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 (139) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/benchmark/benches/lint-with-many-rules.bench.js +2 -2
  3. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +2 -2
  4. package/lib/benchmark/benches/lint-with-no-rules.bench.js +2 -2
  5. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +2 -2
  6. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +2 -2
  7. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -2
  8. package/lib/benchmark/benches/resolve-with-no-external.bench.js +2 -2
  9. package/lib/benchmark/utils.js +7 -4
  10. package/lib/bundle.d.ts +2 -2
  11. package/lib/bundle.js +127 -120
  12. package/lib/config/all.js +9 -0
  13. package/lib/config/builtIn.js +7 -1
  14. package/lib/config/config-resolvers.js +179 -138
  15. package/lib/config/config.d.ts +2 -2
  16. package/lib/config/config.js +53 -34
  17. package/lib/config/load.js +105 -117
  18. package/lib/config/minimal.js +9 -0
  19. package/lib/config/recommended-strict.js +9 -0
  20. package/lib/config/recommended.js +9 -0
  21. package/lib/config/rules.d.ts +3 -3
  22. package/lib/config/rules.js +1 -2
  23. package/lib/config/types.d.ts +9 -3
  24. package/lib/config/utils.js +70 -49
  25. package/lib/decorators/async3/index.d.ts +1 -0
  26. package/lib/decorators/async3/index.js +4 -0
  27. package/lib/decorators/common/filters/filter-helper.js +2 -3
  28. package/lib/decorators/common/filters/filter-in.js +1 -1
  29. package/lib/decorators/common/filters/filter-out.js +1 -1
  30. package/lib/decorators/common/info-override.js +1 -12
  31. package/lib/decorators/common/media-type-examples-override.js +8 -2
  32. package/lib/decorators/common/remove-x-internal.js +4 -5
  33. package/lib/decorators/oas2/remove-unused-components.js +1 -2
  34. package/lib/decorators/oas3/remove-unused-components.js +1 -2
  35. package/lib/env.d.ts +0 -1
  36. package/lib/env.js +1 -1
  37. package/lib/format/codeframes.js +10 -8
  38. package/lib/format/format.js +23 -15
  39. package/lib/index.d.ts +2 -1
  40. package/lib/index.js +6 -4
  41. package/lib/js-yaml/index.js +1 -1
  42. package/lib/lint.d.ts +2 -0
  43. package/lib/lint.js +92 -99
  44. package/lib/oas-types.d.ts +9 -5
  45. package/lib/oas-types.js +22 -12
  46. package/lib/redocly/domains.js +6 -6
  47. package/lib/redocly/index.js +60 -73
  48. package/lib/redocly/registry-api.js +64 -82
  49. package/lib/ref-utils.js +13 -13
  50. package/lib/resolve.js +186 -205
  51. package/lib/rules/ajv.js +10 -8
  52. package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
  53. package/lib/rules/async3/channels-kebab-case.js +19 -0
  54. package/lib/rules/async3/index.d.ts +3 -0
  55. package/lib/rules/async3/index.js +22 -0
  56. package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
  57. package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
  58. package/lib/rules/common/assertions/asserts.js +5 -5
  59. package/lib/rules/common/assertions/index.d.ts +5 -4
  60. package/lib/rules/common/assertions/utils.js +43 -28
  61. package/lib/rules/common/no-invalid-parameter-examples.js +1 -2
  62. package/lib/rules/common/no-invalid-schema-examples.js +1 -2
  63. package/lib/rules/common/no-required-schema-properties-undefined.js +1 -2
  64. package/lib/rules/common/operation-tag-defined.js +1 -2
  65. package/lib/rules/common/path-http-verbs-order.js +1 -1
  66. package/lib/rules/common/required-string-property-missing-min-length.js +2 -2
  67. package/lib/rules/common/response-contains-header.js +2 -2
  68. package/lib/rules/common/security-defined.js +3 -7
  69. package/lib/rules/common/spec.d.ts +2 -2
  70. package/lib/rules/common/spec.js +6 -7
  71. package/lib/rules/no-unresolved-refs.js +3 -4
  72. package/lib/rules/oas2/response-contains-property.js +1 -2
  73. package/lib/rules/oas3/array-parameter-serialization.js +1 -2
  74. package/lib/rules/oas3/component-name-unique.js +2 -4
  75. package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -2
  76. package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -2
  77. package/lib/rules/oas3/no-undefined-server-variable.js +2 -3
  78. package/lib/rules/oas3/no-unused-components.js +1 -2
  79. package/lib/rules/oas3/response-contains-property.js +1 -2
  80. package/lib/rules/utils.js +14 -12
  81. package/lib/types/asyncapi2.d.ts +17 -0
  82. package/lib/types/{asyncapi.js → asyncapi2.js} +56 -52
  83. package/lib/types/asyncapi3.d.ts +2 -0
  84. package/lib/types/asyncapi3.js +347 -0
  85. package/lib/types/index.js +19 -10
  86. package/lib/types/json-schema-adapter.js +4 -18
  87. package/lib/types/oas2.js +6 -6
  88. package/lib/types/oas3.js +10 -10
  89. package/lib/types/oas3_1.js +14 -8
  90. package/lib/types/redocly-yaml.d.ts +3 -1
  91. package/lib/types/redocly-yaml.js +131 -35
  92. package/lib/typings/asyncapi3.d.ts +53 -0
  93. package/lib/typings/asyncapi3.js +2 -0
  94. package/lib/utils.d.ts +4 -3
  95. package/lib/utils.js +55 -72
  96. package/lib/visitors.d.ts +11 -0
  97. package/lib/visitors.js +21 -8
  98. package/lib/walk.js +30 -23
  99. package/package.json +2 -2
  100. package/src/__tests__/bundle.test.ts +142 -0
  101. package/src/bundle.ts +17 -3
  102. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +22 -0
  103. package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
  104. package/src/config/__tests__/config.test.ts +11 -0
  105. package/src/config/all.ts +9 -0
  106. package/src/config/builtIn.ts +6 -0
  107. package/src/config/config-resolvers.ts +15 -2
  108. package/src/config/config.ts +24 -5
  109. package/src/config/minimal.ts +9 -0
  110. package/src/config/recommended-strict.ts +9 -0
  111. package/src/config/recommended.ts +9 -0
  112. package/src/config/rules.ts +12 -4
  113. package/src/config/types.ts +15 -2
  114. package/src/config/utils.ts +15 -0
  115. package/src/decorators/async3/index.ts +1 -0
  116. package/src/decorators/common/remove-x-internal.ts +2 -2
  117. package/src/index.ts +2 -1
  118. package/src/lint.ts +26 -3
  119. package/src/oas-types.ts +31 -13
  120. package/src/rules/arazzo/index.ts +1 -1
  121. package/src/rules/async2/index.ts +5 -5
  122. package/src/rules/async3/__tests__/channels-kebab-case.test.ts +141 -0
  123. package/src/rules/async3/__tests__/no-channel-trailing-slash.test.ts +96 -0
  124. package/src/rules/async3/channels-kebab-case.ts +19 -0
  125. package/src/rules/async3/index.ts +23 -0
  126. package/src/rules/async3/no-channel-trailing-slash.ts +16 -0
  127. package/src/rules/common/assertions/index.ts +13 -4
  128. package/src/rules/common/spec.ts +2 -2
  129. package/src/rules/oas2/index.ts +4 -4
  130. package/src/rules/oas3/index.ts +39 -37
  131. package/src/types/{asyncapi.ts → asyncapi2.ts} +37 -34
  132. package/src/types/asyncapi3.ts +381 -0
  133. package/src/types/oas3_1.ts +2 -1
  134. package/src/types/redocly-yaml.ts +14 -0
  135. package/src/typings/asyncapi3.ts +61 -0
  136. package/src/utils.ts +5 -3
  137. package/src/visitors.ts +18 -0
  138. package/tsconfig.tsbuildinfo +1 -1
  139. package/lib/types/asyncapi.d.ts +0 -2
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.RegistryApi = void 0;
13
4
  const node_fetch_1 = require("node-fetch");
@@ -29,86 +20,77 @@ class RegistryApi {
29
20
  this.accessTokens = accessTokens;
30
21
  return this;
31
22
  }
32
- request(path = '', options = {}) {
33
- var _a, _b;
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const currentCommand = typeof process !== 'undefined' ? ((_a = process.env) === null || _a === void 0 ? void 0 : _a.REDOCLY_CLI_COMMAND) || '' : '';
36
- const redoclyEnv = typeof process !== 'undefined' ? ((_b = process.env) === null || _b === void 0 ? void 0 : _b.REDOCLY_ENVIRONMENT) || '' : '';
37
- const headers = Object.assign({}, options.headers || {}, {
38
- 'x-redocly-cli-version': version,
39
- 'user-agent': `redocly-cli / ${version} ${currentCommand} ${redoclyEnv}`,
40
- });
41
- if (!headers.hasOwnProperty('authorization')) {
42
- throw new Error('Unauthorized');
43
- }
44
- const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl()}${path}`, Object.assign({}, options, { headers, agent: (0, utils_1.getProxyAgent)() }));
45
- if (response.status === 401) {
46
- throw new Error('Unauthorized');
47
- }
48
- if (response.status === 404) {
49
- const body = yield response.json();
50
- throw new Error(body.code);
51
- }
52
- return response;
23
+ async request(path = '', options = {}) {
24
+ const currentCommand = typeof process !== 'undefined' ? process.env?.REDOCLY_CLI_COMMAND || '' : '';
25
+ const redoclyEnv = typeof process !== 'undefined' ? process.env?.REDOCLY_ENVIRONMENT || '' : '';
26
+ const headers = Object.assign({}, options.headers || {}, {
27
+ 'x-redocly-cli-version': version,
28
+ 'user-agent': `redocly-cli / ${version} ${currentCommand} ${redoclyEnv}`,
53
29
  });
30
+ if (!headers.hasOwnProperty('authorization')) {
31
+ throw new Error('Unauthorized');
32
+ }
33
+ const response = await (0, node_fetch_1.default)(`${this.getBaseUrl()}${path}`, Object.assign({}, options, { headers, agent: (0, utils_1.getProxyAgent)() }));
34
+ if (response.status === 401) {
35
+ throw new Error('Unauthorized');
36
+ }
37
+ if (response.status === 404) {
38
+ const body = await response.json();
39
+ throw new Error(body.code);
40
+ }
41
+ return response;
54
42
  }
55
- authStatus(accessToken, verbose = false) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- try {
58
- const response = yield this.request('', { headers: { authorization: accessToken } });
59
- return yield response.json();
60
- }
61
- catch (error) {
62
- if (verbose) {
63
- console.log(error);
64
- }
65
- throw error;
43
+ async authStatus(accessToken, verbose = false) {
44
+ try {
45
+ const response = await this.request('', { headers: { authorization: accessToken } });
46
+ return await response.json();
47
+ }
48
+ catch (error) {
49
+ if (verbose) {
50
+ console.log(error);
66
51
  }
67
- });
52
+ throw error;
53
+ }
68
54
  }
69
- prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const response = yield this.request(`/${organizationId}/${name}/${version}/prepare-file-upload`, {
72
- method: 'POST',
73
- headers: {
74
- 'content-type': 'application/json',
75
- authorization: this.accessToken,
76
- },
77
- body: JSON.stringify({
78
- filesHash,
79
- filename,
80
- isUpsert,
81
- }),
82
- });
83
- if (response.ok) {
84
- return response.json();
85
- }
86
- throw new Error('Could not prepare file upload');
55
+ async prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }) {
56
+ const response = await this.request(`/${organizationId}/${name}/${version}/prepare-file-upload`, {
57
+ method: 'POST',
58
+ headers: {
59
+ 'content-type': 'application/json',
60
+ authorization: this.accessToken,
61
+ },
62
+ body: JSON.stringify({
63
+ filesHash,
64
+ filename,
65
+ isUpsert,
66
+ }),
87
67
  });
68
+ if (response.ok) {
69
+ return response.json();
70
+ }
71
+ throw new Error('Could not prepare file upload');
88
72
  }
89
- pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const response = yield this.request(`/${organizationId}/${name}/${version}`, {
92
- method: 'PUT',
93
- headers: {
94
- 'content-type': 'application/json',
95
- authorization: this.accessToken,
96
- },
97
- body: JSON.stringify({
98
- rootFilePath,
99
- filePaths,
100
- branch,
101
- isUpsert,
102
- isPublic,
103
- batchId,
104
- batchSize,
105
- }),
106
- });
107
- if (response.ok) {
108
- return;
109
- }
110
- throw new Error('Could not push api');
73
+ async pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }) {
74
+ const response = await this.request(`/${organizationId}/${name}/${version}`, {
75
+ method: 'PUT',
76
+ headers: {
77
+ 'content-type': 'application/json',
78
+ authorization: this.accessToken,
79
+ },
80
+ body: JSON.stringify({
81
+ rootFilePath,
82
+ filePaths,
83
+ branch,
84
+ isUpsert,
85
+ isPublic,
86
+ batchId,
87
+ batchSize,
88
+ }),
111
89
  });
90
+ if (response.ok) {
91
+ return;
92
+ }
93
+ throw new Error('Could not push api');
112
94
  }
113
95
  }
114
96
  exports.RegistryApi = RegistryApi;
package/lib/ref-utils.js CHANGED
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAnchor = exports.isMappingRef = exports.isAbsoluteUrl = exports.refBaseName = exports.pointerBaseName = exports.parsePointer = exports.parseRef = exports.escapePointer = exports.unescapePointer = exports.Location = exports.isRef = exports.joinPointer = void 0;
3
+ exports.Location = void 0;
4
+ exports.joinPointer = joinPointer;
5
+ exports.isRef = isRef;
6
+ exports.unescapePointer = unescapePointer;
7
+ exports.escapePointer = escapePointer;
8
+ exports.parseRef = parseRef;
9
+ exports.parsePointer = parsePointer;
10
+ exports.pointerBaseName = pointerBaseName;
11
+ exports.refBaseName = refBaseName;
12
+ exports.isAbsoluteUrl = isAbsoluteUrl;
13
+ exports.isMappingRef = isMappingRef;
14
+ exports.isAnchor = isAnchor;
4
15
  const utils_1 = require("./utils");
5
16
  function joinPointer(base, key) {
6
17
  if (base === '')
7
18
  base = '#/';
8
19
  return base[base.length - 1] === '/' ? base + key : base + '/' + key;
9
20
  }
10
- exports.joinPointer = joinPointer;
11
21
  function isRef(node) {
12
22
  return node && typeof node.$ref === 'string';
13
23
  }
14
- exports.isRef = isRef;
15
24
  class Location {
16
25
  constructor(source, pointer) {
17
26
  this.source = source;
@@ -21,7 +30,7 @@ class Location {
21
30
  return new Location(this.source, joinPointer(this.pointer, (Array.isArray(components) ? components : [components]).map(escapePointer).join('/')));
22
31
  }
23
32
  key() {
24
- return Object.assign(Object.assign({}, this), { reportOnKey: true });
33
+ return { ...this, reportOnKey: true };
25
34
  }
26
35
  get absolutePointer() {
27
36
  return this.source.absoluteRef + (this.pointer === '#/' ? '' : this.pointer);
@@ -31,13 +40,11 @@ exports.Location = Location;
31
40
  function unescapePointer(fragment) {
32
41
  return decodeURIComponent(fragment.replace(/~1/g, '/').replace(/~0/g, '~'));
33
42
  }
34
- exports.unescapePointer = unescapePointer;
35
43
  function escapePointer(fragment) {
36
44
  if (typeof fragment === 'number')
37
45
  return fragment;
38
46
  return fragment.replace(/~/g, '~0').replace(/\//g, '~1');
39
47
  }
40
- exports.escapePointer = escapePointer;
41
48
  function parseRef(ref) {
42
49
  const [uri, pointer = ''] = ref.split('#/');
43
50
  return {
@@ -45,25 +52,20 @@ function parseRef(ref) {
45
52
  pointer: parsePointer(pointer),
46
53
  };
47
54
  }
48
- exports.parseRef = parseRef;
49
55
  function parsePointer(pointer) {
50
56
  return pointer.split('/').map(unescapePointer).filter(utils_1.isTruthy);
51
57
  }
52
- exports.parsePointer = parsePointer;
53
58
  function pointerBaseName(pointer) {
54
59
  const parts = pointer.split('/');
55
60
  return parts[parts.length - 1];
56
61
  }
57
- exports.pointerBaseName = pointerBaseName;
58
62
  function refBaseName(ref) {
59
63
  const parts = ref.split(/[\/\\]/); // split by '\' and '/'
60
64
  return parts[parts.length - 1].replace(/\.[^.]+$/, ''); // replace extension with empty string
61
65
  }
62
- exports.refBaseName = refBaseName;
63
66
  function isAbsoluteUrl(ref) {
64
67
  return ref.startsWith('http://') || ref.startsWith('https://');
65
68
  }
66
- exports.isAbsoluteUrl = isAbsoluteUrl;
67
69
  function isMappingRef(mapping) {
68
70
  // TODO: proper detection of mapping refs
69
71
  return (mapping.startsWith('#') ||
@@ -73,8 +75,6 @@ function isMappingRef(mapping) {
73
75
  mapping.startsWith('../') ||
74
76
  mapping.indexOf('/') > -1);
75
77
  }
76
- exports.isMappingRef = isMappingRef;
77
78
  function isAnchor(ref) {
78
79
  return /^#[A-Za-z][A-Za-z0-9\-_:.]*$/.test(ref);
79
80
  }
80
- exports.isAnchor = isAnchor;