@redocly/openapi-core 1.3.0 → 1.4.1

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 (202) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/lib/benchmark/benches/lint-with-many-rules.bench.js +4 -4
  3. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +4 -4
  4. package/lib/benchmark/benches/lint-with-no-rules.bench.js +4 -4
  5. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +4 -4
  6. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +4 -4
  7. package/lib/benchmark/benches/recommended-oas3.bench.js +4 -4
  8. package/lib/benchmark/benches/resolve-with-no-external.bench.js +3 -3
  9. package/lib/benchmark/utils.js +3 -3
  10. package/lib/bundle.d.ts +4 -4
  11. package/lib/bundle.js +25 -25
  12. package/lib/config/all.d.ts +2 -2
  13. package/lib/config/all.js +44 -8
  14. package/lib/config/builtIn.js +2 -0
  15. package/lib/config/config-resolvers.js +25 -25
  16. package/lib/config/config.js +9 -9
  17. package/lib/config/index.js +5 -1
  18. package/lib/config/load.d.ts +1 -1
  19. package/lib/config/load.js +6 -6
  20. package/lib/config/minimal.d.ts +2 -2
  21. package/lib/config/minimal.js +34 -3
  22. package/lib/config/recommended-strict.d.ts +3 -0
  23. package/lib/config/recommended-strict.js +92 -0
  24. package/lib/config/recommended.d.ts +2 -2
  25. package/lib/config/recommended.js +34 -3
  26. package/lib/config/rules.d.ts +1 -1
  27. package/lib/config/types.d.ts +47 -46
  28. package/lib/config/types.js +2 -2
  29. package/lib/config/utils.js +26 -14
  30. package/lib/decorators/common/filters/filter-helper.js +4 -4
  31. package/lib/decorators/common/filters/filter-in.js +2 -2
  32. package/lib/decorators/common/filters/filter-out.js +2 -2
  33. package/lib/decorators/common/info-description-override.js +1 -1
  34. package/lib/decorators/common/media-type-examples-override.js +3 -3
  35. package/lib/decorators/common/operation-description-override.js +1 -1
  36. package/lib/decorators/common/registry-dependencies.js +1 -1
  37. package/lib/decorators/common/remove-x-internal.js +4 -4
  38. package/lib/decorators/common/tag-description-override.js +1 -1
  39. package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
  40. package/lib/{rules → decorators}/oas2/remove-unused-components.js +1 -1
  41. package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
  42. package/lib/{rules → decorators}/oas3/remove-unused-components.js +2 -2
  43. package/lib/env.js +1 -1
  44. package/lib/format/codeframes.d.ts +6 -6
  45. package/lib/format/format.d.ts +2 -2
  46. package/lib/format/format.js +12 -12
  47. package/lib/js-yaml/index.d.ts +2 -2
  48. package/lib/js-yaml/index.js +2 -2
  49. package/lib/lint.js +18 -18
  50. package/lib/oas-types.d.ts +12 -10
  51. package/lib/oas-types.js +2 -2
  52. package/lib/redocly/index.js +10 -10
  53. package/lib/redocly/registry-api.js +2 -2
  54. package/lib/resolve.d.ts +4 -4
  55. package/lib/resolve.js +18 -18
  56. package/lib/rules/ajv.js +1 -1
  57. package/lib/rules/async2/index.d.ts +2 -11
  58. package/lib/rules/common/assertions/asserts.d.ts +3 -3
  59. package/lib/rules/common/assertions/asserts.js +21 -21
  60. package/lib/rules/common/assertions/index.d.ts +4 -4
  61. package/lib/rules/common/assertions/index.js +3 -3
  62. package/lib/rules/common/assertions/utils.d.ts +4 -4
  63. package/lib/rules/common/assertions/utils.js +3 -3
  64. package/lib/rules/common/info-contact.js +1 -1
  65. package/lib/rules/common/info-license-url.js +1 -1
  66. package/lib/rules/common/info-license.js +1 -1
  67. package/lib/rules/common/no-enum-type-mismatch.js +3 -3
  68. package/lib/rules/common/no-http-verbs-in-paths.js +2 -2
  69. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  70. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  71. package/lib/rules/common/operation-2xx-response.js +2 -2
  72. package/lib/rules/common/operation-4xx-response.js +2 -2
  73. package/lib/rules/common/operation-description.js +1 -1
  74. package/lib/rules/common/operation-operationId.js +1 -1
  75. package/lib/rules/common/operation-summary.js +1 -1
  76. package/lib/rules/common/path-segment-plural.js +1 -1
  77. package/lib/rules/common/response-contains-header.js +2 -2
  78. package/lib/rules/common/spec-strict-refs.js +1 -1
  79. package/lib/rules/common/spec.js +11 -11
  80. package/lib/rules/common/tag-description.js +1 -1
  81. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  82. package/lib/rules/oas2/index.d.ts +2 -46
  83. package/lib/rules/oas2/request-mime-type.js +2 -2
  84. package/lib/rules/oas2/response-contains-property.js +2 -2
  85. package/lib/rules/oas2/response-mime-type.js +2 -2
  86. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  87. package/lib/rules/oas3/index.d.ts +1 -1
  88. package/lib/rules/oas3/index.js +1 -1
  89. package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -3
  90. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
  91. package/lib/rules/oas3/request-mime-type.js +3 -3
  92. package/lib/rules/oas3/response-contains-property.js +2 -2
  93. package/lib/rules/oas3/response-mime-type.js +3 -3
  94. package/lib/rules/utils.js +3 -3
  95. package/lib/types/asyncapi.js +21 -21
  96. package/lib/types/index.d.ts +8 -8
  97. package/lib/types/oas2.js +14 -14
  98. package/lib/types/oas3.js +27 -27
  99. package/lib/types/oas3_1.js +18 -6
  100. package/lib/types/redocly-yaml.d.ts +11 -0
  101. package/lib/types/redocly-yaml.js +71 -53
  102. package/lib/types/theme-config.js +1 -1
  103. package/lib/typings/common.d.ts +2 -2
  104. package/lib/typings/openapi.d.ts +6 -6
  105. package/lib/typings/swagger.d.ts +3 -3
  106. package/lib/utils.d.ts +5 -5
  107. package/lib/utils.js +3 -3
  108. package/lib/visitors.d.ts +38 -40
  109. package/lib/walk.d.ts +14 -15
  110. package/lib/walk.js +11 -11
  111. package/package.json +2 -2
  112. package/src/__tests__/lint.test.ts +40 -40
  113. package/src/__tests__/normalizeVisitors.test.ts +23 -5
  114. package/src/__tests__/ref-utils.test.ts +7 -7
  115. package/src/__tests__/resolve-http.test.ts +10 -10
  116. package/src/__tests__/resolve.test.ts +39 -39
  117. package/src/__tests__/walk.test.ts +48 -48
  118. package/src/bundle.ts +4 -4
  119. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +95 -32
  120. package/src/config/__tests__/__snapshots__/config.test.ts.snap +81 -81
  121. package/src/config/__tests__/config-resolvers.test.ts +30 -1
  122. package/src/config/__tests__/config.test.ts +88 -88
  123. package/src/config/__tests__/load.test.ts +12 -8
  124. package/src/config/__tests__/utils.test.ts +18 -18
  125. package/src/config/all.ts +46 -9
  126. package/src/config/builtIn.ts +2 -0
  127. package/src/config/minimal.ts +36 -4
  128. package/src/config/recommended-strict.ts +93 -0
  129. package/src/config/recommended.ts +36 -4
  130. package/src/config/types.ts +22 -8
  131. package/src/config/utils.ts +15 -0
  132. package/src/decorators/common/media-type-examples-override.ts +2 -2
  133. package/src/{rules → decorators}/oas2/remove-unused-components.ts +3 -3
  134. package/src/{rules → decorators}/oas3/remove-unused-components.ts +3 -3
  135. package/src/env.ts +1 -1
  136. package/src/lint.ts +3 -3
  137. package/src/oas-types.ts +26 -3
  138. package/src/rules/__tests__/no-unresolved-refs.test.ts +26 -26
  139. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +12 -12
  140. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +7 -7
  141. package/src/rules/async2/index.ts +2 -1
  142. package/src/rules/common/__tests__/info-license.test.ts +6 -6
  143. package/src/rules/common/__tests__/license-url.test.ts +6 -6
  144. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +13 -13
  145. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +18 -18
  146. package/src/rules/common/__tests__/no-identical-paths.test.ts +5 -5
  147. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +12 -12
  148. package/src/rules/common/__tests__/operation-2xx-response.test.ts +18 -18
  149. package/src/rules/common/__tests__/operation-4xx-response.test.ts +23 -23
  150. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +6 -6
  151. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +5 -5
  152. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +16 -16
  153. package/src/rules/common/__tests__/operation-singular-tag.test.ts +6 -6
  154. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +10 -10
  155. package/src/rules/common/__tests__/path-not-include-query.test.ts +6 -6
  156. package/src/rules/common/__tests__/path-params-defined.test.ts +21 -21
  157. package/src/rules/common/__tests__/paths-kebab-case.test.ts +11 -11
  158. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +18 -18
  159. package/src/rules/common/__tests__/security-defined.test.ts +21 -21
  160. package/src/rules/common/__tests__/spec-strict-refs.test.ts +9 -9
  161. package/src/rules/common/__tests__/spec.test.ts +102 -102
  162. package/src/rules/common/__tests__/tag-description.test.ts +6 -6
  163. package/src/rules/common/__tests__/tags-alphabetical.test.ts +12 -12
  164. package/src/rules/common/assertions/__tests__/index.test.ts +15 -15
  165. package/src/rules/common/assertions/__tests__/utils.test.ts +9 -9
  166. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  167. package/src/rules/oas2/__tests__/response-contains-header.test.ts +13 -13
  168. package/src/rules/oas2/__tests__/response-contains-property.test.ts +8 -8
  169. package/src/rules/oas2/__tests__/spec/info.test.ts +21 -21
  170. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  171. package/src/rules/oas2/__tests__/spec/paths.test.ts +12 -12
  172. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  173. package/src/rules/oas2/index.ts +3 -1
  174. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -7
  175. package/src/rules/oas3/__tests__/component-name-unique.test.ts +186 -186
  176. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +18 -18
  177. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +6 -6
  178. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +36 -36
  179. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +11 -11
  180. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +7 -7
  181. package/src/rules/oas3/__tests__/no-unused-components.test.ts +31 -31
  182. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +15 -15
  183. package/src/rules/oas3/__tests__/response-contains-header.test.ts +26 -26
  184. package/src/rules/oas3/__tests__/response-contains-property.test.ts +27 -27
  185. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  186. package/src/rules/oas3/__tests__/spec/info.test.ts +21 -21
  187. package/src/rules/oas3/__tests__/spec/operation.test.ts +10 -10
  188. package/src/rules/oas3/__tests__/spec/paths.test.ts +13 -13
  189. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +2 -2
  190. package/src/rules/oas3/__tests__/spec/servers.test.ts +25 -25
  191. package/src/rules/oas3/__tests__/spec/spec.test.ts +56 -56
  192. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +28 -28
  193. package/src/rules/oas3/index.ts +3 -3
  194. package/src/types/oas3_1.ts +12 -0
  195. package/src/types/redocly-yaml.ts +75 -40
  196. package/src/visitors.ts +10 -21
  197. package/src/walk.ts +23 -10
  198. package/tsconfig.tsbuildinfo +1 -1
  199. package/lib/rules/oas2/remove-unused-components.d.ts +0 -2
  200. package/lib/rules/oas3/remove-unused-components.d.ts +0 -2
  201. /package/src/{rules → decorators}/oas2/__tests__/remove-unused-components.test.ts +0 -0
  202. /package/src/{rules → decorators}/oas3/__tests__/remove-unused-components.test.ts +0 -0
@@ -76,7 +76,7 @@ function formatProblems(problems, opts) {
76
76
  case 'stylish': {
77
77
  const groupedByFile = groupByFiles(problems);
78
78
  for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(groupedByFile)) {
79
- logger_1.logger.info(`${logger_1.colorize.blue(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}:\n`);
79
+ logger_1.logger.info(`${logger_1.colorize.blue((0, ref_utils_1.isAbsoluteUrl)(file) ? file : path.relative(cwd, file))}:\n`);
80
80
  for (let i = 0; i < fileProblems.length; i++) {
81
81
  const problem = fileProblems[i];
82
82
  logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
@@ -90,7 +90,7 @@ function formatProblems(problems, opts) {
90
90
  output_1.output.write('<?xml version="1.0" encoding="UTF-8"?>\n');
91
91
  output_1.output.write('<checkstyle version="4.3">\n');
92
92
  for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
93
- output_1.output.write(`<file name="${xmlEscape(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}">\n`);
93
+ output_1.output.write(`<file name="${xmlEscape((0, ref_utils_1.isAbsoluteUrl)(file) ? file : path.relative(cwd, file))}">\n`);
94
94
  fileProblems.forEach(formatCheckstyle);
95
95
  output_1.output.write(`</file>\n`);
96
96
  }
@@ -110,11 +110,11 @@ function formatProblems(problems, opts) {
110
110
  function outputForCodeClimate() {
111
111
  const issues = problems.map((p) => {
112
112
  const location = p.location[0]; // TODO: support multiple location
113
- const lineCol = codeframes_1.getLineColLocation(location);
113
+ const lineCol = (0, codeframes_1.getLineColLocation)(location);
114
114
  return {
115
115
  description: p.message,
116
116
  location: {
117
- path: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
117
+ path: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
118
118
  ? location.source.absoluteRef
119
119
  : path.relative(cwd, location.source.absoluteRef),
120
120
  lines: {
@@ -134,19 +134,19 @@ function formatProblems(problems, opts) {
134
134
  problems: problems.map((p) => {
135
135
  var _a, _b, _c;
136
136
  const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
137
- ref: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
137
+ ref: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
138
138
  ? location.source.absoluteRef
139
139
  : path.relative(cwd, location.source.absoluteRef),
140
140
  } }))), from: p.from
141
141
  ? Object.assign(Object.assign({}, p.from), { source: {
142
- ref: ref_utils_1.isAbsoluteUrl((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef)
142
+ ref: (0, ref_utils_1.isAbsoluteUrl)((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef)
143
143
  ? (_b = p.from) === null || _b === void 0 ? void 0 : _b.source.absoluteRef
144
144
  : path.relative(cwd, ((_c = p.from) === null || _c === void 0 ? void 0 : _c.source.absoluteRef) || cwd),
145
145
  } }) : undefined });
146
146
  if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
147
147
  const location = p.location[0]; // TODO: support multiple locations
148
- const loc = codeframes_1.getLineColLocation(location);
149
- problem.codeframe = codeframes_1.getCodeframe(loc, color);
148
+ const loc = (0, codeframes_1.getLineColLocation)(location);
149
+ problem.codeframe = (0, codeframes_1.getCodeframe)(loc, color);
150
150
  }
151
151
  return problem;
152
152
  }),
@@ -163,16 +163,16 @@ function formatProblems(problems, opts) {
163
163
  function formatCodeframe(problem, idx) {
164
164
  const bgColor = getBgColor(problem);
165
165
  const location = problem.location[0]; // TODO: support multiple locations
166
- const relativePath = ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
166
+ const relativePath = (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
167
167
  ? location.source.absoluteRef
168
168
  : path.relative(cwd, location.source.absoluteRef);
169
- const loc = codeframes_1.getLineColLocation(location);
169
+ const loc = (0, codeframes_1.getLineColLocation)(location);
170
170
  const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
171
171
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
172
172
  return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
173
173
  `${problem.message}\n\n` +
174
174
  formatDidYouMean(problem) +
175
- codeframes_1.getCodeframe(loc, color) +
175
+ (0, codeframes_1.getCodeframe)(loc, color) +
176
176
  '\n\n' +
177
177
  formatFrom(cwd, problem.from) +
178
178
  `${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
@@ -216,7 +216,7 @@ function formatFrom(cwd, location) {
216
216
  if (!location)
217
217
  return '';
218
218
  const relativePath = path.relative(cwd, location.source.absoluteRef);
219
- const loc = codeframes_1.getLineColLocation(location);
219
+ const loc = (0, codeframes_1.getLineColLocation)(location);
220
220
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
221
221
  const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
222
222
  return `referenced from ${logger_1.colorize.blue(fileWithLoc)} ${atPointer} \n\n`;
@@ -1,3 +1,3 @@
1
1
  import { LoadOptions, DumpOptions } from 'js-yaml';
2
- export declare const parseYaml: (str: string, opts?: LoadOptions | undefined) => unknown;
3
- export declare const stringifyYaml: (obj: any, opts?: DumpOptions | undefined) => string;
2
+ export declare const parseYaml: (str: string, opts?: LoadOptions) => unknown;
3
+ export declare const stringifyYaml: (obj: any, opts?: DumpOptions) => string;
@@ -9,7 +9,7 @@ const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
9
9
  implicit: [js_yaml_1.types.merge],
10
10
  explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
11
11
  });
12
- const parseYaml = (str, opts) => js_yaml_1.load(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
12
+ const parseYaml = (str, opts) => (0, js_yaml_1.load)(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
13
13
  exports.parseYaml = parseYaml;
14
- const stringifyYaml = (obj, opts) => js_yaml_1.dump(obj, opts);
14
+ const stringifyYaml = (obj, opts) => (0, js_yaml_1.dump)(obj, opts);
15
15
  exports.stringifyYaml = stringifyYaml;
package/lib/lint.js CHANGED
@@ -30,48 +30,48 @@ exports.lint = lint;
30
30
  function lintFromString(opts) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
33
- const document = resolve_1.makeDocumentFromString(source, absoluteRef || '/');
33
+ const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
34
34
  return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
35
35
  });
36
36
  }
37
37
  exports.lintFromString = lintFromString;
38
38
  function lintDocument(opts) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
- ajv_1.releaseAjvInstance(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
40
+ (0, ajv_1.releaseAjvInstance)(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
41
41
  const { document, customTypes, externalRefResolver, config } = opts;
42
- const specVersion = oas_types_1.detectSpec(document.parsed);
43
- const specMajorVersion = oas_types_1.getMajorSpecVersion(specVersion);
42
+ const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
43
+ const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
44
44
  const rules = config.getRulesForOasVersion(specMajorVersion);
45
- const types = types_1.normalizeTypes(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : oas_types_1.getTypes(specVersion), specVersion), config);
45
+ const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : (0, oas_types_1.getTypes)(specVersion), specVersion), config);
46
46
  const ctx = {
47
47
  problems: [],
48
48
  oasVersion: specVersion,
49
49
  visitorsData: {},
50
50
  };
51
- const preprocessors = config_1.initRules(rules, config, 'preprocessors', specVersion);
52
- const regularRules = config_1.initRules(rules, config, 'rules', specVersion);
53
- let resolvedRefMap = yield resolve_1.resolveDocument({
51
+ const preprocessors = (0, config_1.initRules)(rules, config, 'preprocessors', specVersion);
52
+ const regularRules = (0, config_1.initRules)(rules, config, 'rules', specVersion);
53
+ let resolvedRefMap = yield (0, resolve_1.resolveDocument)({
54
54
  rootDocument: document,
55
55
  rootType: types.Root,
56
56
  externalRefResolver,
57
57
  });
58
58
  if (preprocessors.length > 0) {
59
59
  // Make additional pass to resolve refs defined in preprocessors.
60
- walk_1.walkDocument({
60
+ (0, walk_1.walkDocument)({
61
61
  document,
62
62
  rootType: types.Root,
63
- normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
63
+ normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
64
64
  resolvedRefMap,
65
65
  ctx,
66
66
  });
67
- resolvedRefMap = yield resolve_1.resolveDocument({
67
+ resolvedRefMap = yield (0, resolve_1.resolveDocument)({
68
68
  rootDocument: document,
69
69
  rootType: types.Root,
70
70
  externalRefResolver,
71
71
  });
72
72
  }
73
- const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
74
- walk_1.walkDocument({
73
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(regularRules, types);
74
+ (0, walk_1.walkDocument)({
75
75
  document,
76
76
  rootType: types.Root,
77
77
  normalizedVisitors,
@@ -90,22 +90,22 @@ function lintConfig(opts) {
90
90
  oasVersion: oas_types_1.SpecVersion.OAS3_0,
91
91
  visitorsData: {},
92
92
  };
93
- const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
93
+ const plugins = (0, config_1.resolvePlugins)([config_1.defaultPlugin]);
94
94
  const config = new config_1.StyleguideConfig({
95
95
  plugins,
96
96
  rules: { spec: 'error' },
97
97
  });
98
- const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
98
+ const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes, config);
99
99
  const rules = [
100
100
  {
101
101
  severity: severity || 'error',
102
102
  ruleId: 'configuration spec',
103
- visitor: spec_1.Spec({ severity: 'error' }),
103
+ visitor: (0, spec_1.Spec)({ severity: 'error' }),
104
104
  },
105
105
  ];
106
106
  // TODO: check why any is needed
107
- const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
108
- walk_1.walkDocument({
107
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(rules, types);
108
+ (0, walk_1.walkDocument)({
109
109
  document,
110
110
  rootType: types.ConfigRoot,
111
111
  normalizedVisitors,
@@ -1,5 +1,6 @@
1
1
  import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule } from './visitors';
2
- export declare type RuleSet<T> = Record<string, T>;
2
+ import { BuiltInAsync2RuleId, BuiltInCommonOASRuleId, BuiltInCommonRuleId, BuiltInOAS2RuleId, BuiltInOAS3RuleId } from './types/redocly-yaml';
3
+ export type RuleSet<T> = Record<string, T>;
3
4
  export declare enum SpecVersion {
4
5
  OAS2 = "oas2",
5
6
  OAS3_0 = "oas3_0",
@@ -11,15 +12,16 @@ export declare enum SpecMajorVersion {
11
12
  OAS3 = "oas3",
12
13
  Async2 = "async2"
13
14
  }
14
- export declare type Oas3RuleSet = Record<string, Oas3Rule>;
15
- export declare type Oas2RuleSet = Record<string, Oas2Rule>;
16
- export declare type Async2RuleSet = Record<string, Async2Rule>;
17
- export declare type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
18
- export declare type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
19
- export declare type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
20
- export declare type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
21
- export declare type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
22
- export declare type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
15
+ export type RuleMap<Key extends string, RuleConfig, T> = Record<T extends 'built-in' ? Key : string, RuleConfig>;
16
+ export type Oas3RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions', Oas3Rule, T>;
17
+ export type Oas2RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions', Oas2Rule, T>;
18
+ export type Async2RuleSet<T = undefined> = RuleMap<BuiltInCommonRuleId | BuiltInAsync2RuleId | 'assertions', Async2Rule, T>;
19
+ export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
20
+ export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
21
+ export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
22
+ export type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
23
+ export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
24
+ export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
23
25
  export declare function detectSpec(root: any): SpecVersion;
24
26
  export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
25
27
  export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType>;
package/lib/oas-types.js CHANGED
@@ -11,13 +11,13 @@ var SpecVersion;
11
11
  SpecVersion["OAS3_0"] = "oas3_0";
12
12
  SpecVersion["OAS3_1"] = "oas3_1";
13
13
  SpecVersion["Async2"] = "async2";
14
- })(SpecVersion = exports.SpecVersion || (exports.SpecVersion = {}));
14
+ })(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
15
15
  var SpecMajorVersion;
16
16
  (function (SpecMajorVersion) {
17
17
  SpecMajorVersion["OAS2"] = "oas2";
18
18
  SpecMajorVersion["OAS3"] = "oas3";
19
19
  SpecMajorVersion["Async2"] = "async2";
20
- })(SpecMajorVersion = exports.SpecMajorVersion || (exports.SpecMajorVersion = {}));
20
+ })(SpecMajorVersion || (exports.SpecMajorVersion = SpecMajorVersion = {}));
21
21
  const typesMap = {
22
22
  [SpecVersion.OAS2]: oas2_1.Oas2Types,
23
23
  [SpecVersion.OAS3_0]: oas3_1.Oas3Types,
@@ -41,7 +41,7 @@ class RedoclyClient {
41
41
  return this.region;
42
42
  }
43
43
  hasTokens() {
44
- return utils_1.isNotEmptyObject(this.accessTokens);
44
+ return (0, utils_1.isNotEmptyObject)(this.accessTokens);
45
45
  }
46
46
  // <backward compatibility: old versions of portal>
47
47
  hasToken() {
@@ -57,9 +57,9 @@ class RedoclyClient {
57
57
  this.accessTokens = accessTokens;
58
58
  }
59
59
  loadTokens() {
60
- const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
60
+ const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
61
61
  const credentials = this.readCredentialsFile(credentialsPath);
62
- if (utils_1.isNotEmptyObject(credentials)) {
62
+ if ((0, utils_1.isNotEmptyObject)(credentials)) {
63
63
  this.setAccessTokens(Object.assign(Object.assign({}, credentials), (credentials.token &&
64
64
  !credentials[this.region] && {
65
65
  [this.region]: credentials.token,
@@ -108,11 +108,11 @@ class RedoclyClient {
108
108
  }
109
109
  isAuthorizedWithRedocly() {
110
110
  return __awaiter(this, void 0, void 0, function* () {
111
- return this.hasTokens() && utils_1.isNotEmptyObject(yield this.getValidTokens());
111
+ return this.hasTokens() && (0, utils_1.isNotEmptyObject)(yield this.getValidTokens());
112
112
  });
113
113
  }
114
114
  readCredentialsFile(credentialsPath) {
115
- return fs_1.existsSync(credentialsPath) ? JSON.parse(fs_1.readFileSync(credentialsPath, 'utf-8')) : {};
115
+ return (0, fs_1.existsSync)(credentialsPath) ? JSON.parse((0, fs_1.readFileSync)(credentialsPath, 'utf-8')) : {};
116
116
  }
117
117
  verifyToken(accessToken, region, verbose = false) {
118
118
  return __awaiter(this, void 0, void 0, function* () {
@@ -121,7 +121,7 @@ class RedoclyClient {
121
121
  }
122
122
  login(accessToken, verbose = false) {
123
123
  return __awaiter(this, void 0, void 0, function* () {
124
- const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
124
+ const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
125
125
  try {
126
126
  yield this.verifyToken(accessToken, this.region, verbose);
127
127
  }
@@ -131,13 +131,13 @@ class RedoclyClient {
131
131
  const credentials = Object.assign(Object.assign({}, this.readCredentialsFile(credentialsPath)), { [this.region]: accessToken, token: accessToken });
132
132
  this.accessTokens = credentials;
133
133
  this.registryApi.setAccessTokens(credentials);
134
- fs_1.writeFileSync(credentialsPath, JSON.stringify(credentials, null, 2));
134
+ (0, fs_1.writeFileSync)(credentialsPath, JSON.stringify(credentials, null, 2));
135
135
  });
136
136
  }
137
137
  logout() {
138
- const credentialsPath = path_1.resolve(os_1.homedir(), TOKEN_FILENAME);
139
- if (fs_1.existsSync(credentialsPath)) {
140
- fs_1.unlinkSync(credentialsPath);
138
+ const credentialsPath = (0, path_1.resolve)((0, os_1.homedir)(), TOKEN_FILENAME);
139
+ if ((0, fs_1.existsSync)(credentialsPath)) {
140
+ (0, fs_1.unlinkSync)(credentialsPath);
141
141
  }
142
142
  }
143
143
  }
@@ -20,7 +20,7 @@ class RegistryApi {
20
20
  this.region = region;
21
21
  }
22
22
  get accessToken() {
23
- return utils_1.isNotEmptyObject(this.accessTokens) && this.accessTokens[this.region];
23
+ return (0, utils_1.isNotEmptyObject)(this.accessTokens) && this.accessTokens[this.region];
24
24
  }
25
25
  getBaseUrl(region = config_1.DEFAULT_REGION) {
26
26
  return `https://api.${config_1.DOMAINS[region]}/registry`;
@@ -41,7 +41,7 @@ class RegistryApi {
41
41
  if (!headers.hasOwnProperty('authorization')) {
42
42
  throw new Error('Unauthorized');
43
43
  }
44
- const response = yield node_fetch_1.default(`${this.getBaseUrl(region)}${path}`, Object.assign({}, options, { headers }));
44
+ const response = yield (0, node_fetch_1.default)(`${this.getBaseUrl(region)}${path}`, Object.assign({}, options, { headers }));
45
45
  if (response.status === 401) {
46
46
  throw new Error('Unauthorized');
47
47
  }
package/lib/resolve.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { YAMLNode, LoadOptions } from 'yaml-ast-parser';
2
2
  import { NormalizedNodeType } from './types';
3
3
  import { ResolveConfig } from './config/types';
4
- export declare type CollectedRefs = Map<string, Document>;
4
+ export type CollectedRefs = Map<string, Document>;
5
5
  export declare class Source {
6
6
  absoluteRef: string;
7
7
  body: string;
@@ -23,7 +23,7 @@ export declare class YamlParseError extends Error {
23
23
  line: number;
24
24
  constructor(originalError: Error, source: Source);
25
25
  }
26
- export declare type Document = {
26
+ export type Document = {
27
27
  source: Source;
28
28
  parsed: any;
29
29
  };
@@ -42,7 +42,7 @@ export declare class BaseResolver {
42
42
  parseDocument(source: Source, isRoot?: boolean): Document;
43
43
  resolveDocument(base: string | null, ref: string, isRoot?: boolean): Promise<Document | ResolveError | YamlParseError>;
44
44
  }
45
- export declare type ResolvedRef = {
45
+ export type ResolvedRef = {
46
46
  resolved: false;
47
47
  isRemote: boolean;
48
48
  nodePointer?: string;
@@ -58,7 +58,7 @@ export declare type ResolvedRef = {
58
58
  isRemote: boolean;
59
59
  error?: undefined;
60
60
  };
61
- export declare type ResolvedRefMap = Map<string, ResolvedRef>;
61
+ export type ResolvedRefMap = Map<string, ResolvedRef>;
62
62
  export declare function resolveDocument(opts: {
63
63
  rootDocument: Document;
64
64
  externalRefResolver: BaseResolver;
package/lib/resolve.js CHANGED
@@ -77,7 +77,7 @@ function makeDocumentFromString(sourceString, absoluteRef) {
77
77
  try {
78
78
  return {
79
79
  source,
80
- parsed: utils_1.parseYaml(sourceString, { filename: absoluteRef }),
80
+ parsed: (0, utils_1.parseYaml)(sourceString, { filename: absoluteRef }),
81
81
  };
82
82
  }
83
83
  catch (e) {
@@ -94,10 +94,10 @@ class BaseResolver {
94
94
  return new Set(Array.from(this.cache.keys()));
95
95
  }
96
96
  resolveExternalRef(base, ref) {
97
- if (ref_utils_1.isAbsoluteUrl(ref)) {
97
+ if ((0, ref_utils_1.isAbsoluteUrl)(ref)) {
98
98
  return ref;
99
99
  }
100
- if (base && ref_utils_1.isAbsoluteUrl(base)) {
100
+ if (base && (0, ref_utils_1.isAbsoluteUrl)(base)) {
101
101
  return new URL(ref, base).href;
102
102
  }
103
103
  return path.resolve(base ? path.dirname(base) : process.cwd(), ref);
@@ -105,8 +105,8 @@ class BaseResolver {
105
105
  loadExternalRef(absoluteRef) {
106
106
  return __awaiter(this, void 0, void 0, function* () {
107
107
  try {
108
- if (ref_utils_1.isAbsoluteUrl(absoluteRef)) {
109
- const { body, mimeType } = yield utils_1.readFileFromUrl(absoluteRef, this.config.http);
108
+ if ((0, ref_utils_1.isAbsoluteUrl)(absoluteRef)) {
109
+ const { body, mimeType } = yield (0, utils_1.readFileFromUrl)(absoluteRef, this.config.http);
110
110
  return new Source(absoluteRef, body, mimeType);
111
111
  }
112
112
  else {
@@ -136,7 +136,7 @@ class BaseResolver {
136
136
  try {
137
137
  return {
138
138
  source,
139
- parsed: utils_1.parseYaml(source.body, { filename: source.absoluteRef }),
139
+ parsed: (0, utils_1.parseYaml)(source.body, { filename: source.absoluteRef }),
140
140
  };
141
141
  }
142
142
  catch (e) {
@@ -212,7 +212,7 @@ function resolveDocument(opts) {
212
212
  return;
213
213
  }
214
214
  for (let i = 0; i < node.length; i++) {
215
- walk(node[i], itemsType || unknownType, ref_utils_1.joinPointer(nodeAbsoluteRef, i));
215
+ walk(node[i], itemsType || unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
216
216
  }
217
217
  return;
218
218
  }
@@ -230,19 +230,19 @@ function resolveDocument(opts) {
230
230
  propType === unknownType) {
231
231
  propType = types_1.SpecExtension;
232
232
  }
233
- if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
233
+ if (!(0, types_1.isNamedType)(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
234
234
  propType = propType.directResolveAs;
235
235
  propValue = { $ref: propValue };
236
236
  }
237
237
  if (propType && propType.name === undefined && propType.resolvable !== false) {
238
238
  propType = resolvableScalarType;
239
239
  }
240
- if (!types_1.isNamedType(propType) || typeof propValue !== 'object') {
240
+ if (!(0, types_1.isNamedType)(propType) || typeof propValue !== 'object') {
241
241
  continue;
242
242
  }
243
- walk(propValue, propType, ref_utils_1.joinPointer(nodeAbsoluteRef, ref_utils_1.escapePointer(propName)));
243
+ walk(propValue, propType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, (0, ref_utils_1.escapePointer)(propName)));
244
244
  }
245
- if (ref_utils_1.isRef(node)) {
245
+ if ((0, ref_utils_1.isRef)(node)) {
246
246
  const promise = followRef(rootNodeDocument, node, {
247
247
  prev: null,
248
248
  node,
@@ -259,9 +259,9 @@ function resolveDocument(opts) {
259
259
  if (hasRef(refStack.prev, ref)) {
260
260
  throw new Error('Self-referencing circular pointer');
261
261
  }
262
- if (ref_utils_1.isAnchor(ref.$ref)) {
262
+ if ((0, ref_utils_1.isAnchor)(ref.$ref)) {
263
263
  // Wait for all anchors in the document to be collected firstly.
264
- yield utils_1.nextTick();
264
+ yield (0, utils_1.nextTick)();
265
265
  const resolvedRef = {
266
266
  resolved: true,
267
267
  isRemote: false,
@@ -273,7 +273,7 @@ function resolveDocument(opts) {
273
273
  resolvedRefMap.set(refId, resolvedRef);
274
274
  return resolvedRef;
275
275
  }
276
- const { uri, pointer } = ref_utils_1.parseRef(ref.$ref);
276
+ const { uri, pointer } = (0, ref_utils_1.parseRef)(ref.$ref);
277
277
  const isRemote = uri !== null;
278
278
  let targetDoc;
279
279
  try {
@@ -308,9 +308,9 @@ function resolveDocument(opts) {
308
308
  }
309
309
  else if (target[segment] !== undefined) {
310
310
  target = target[segment];
311
- resolvedRef.nodePointer = ref_utils_1.joinPointer(resolvedRef.nodePointer, ref_utils_1.escapePointer(segment));
311
+ resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
312
312
  }
313
- else if (ref_utils_1.isRef(target)) {
313
+ else if ((0, ref_utils_1.isRef)(target)) {
314
314
  resolvedRef = yield followRef(targetDoc, target, pushRef(refStack, target));
315
315
  targetDoc = resolvedRef.document || targetDoc;
316
316
  if (typeof resolvedRef.node !== 'object') {
@@ -318,7 +318,7 @@ function resolveDocument(opts) {
318
318
  break;
319
319
  }
320
320
  target = resolvedRef.node[segment];
321
- resolvedRef.nodePointer = ref_utils_1.joinPointer(resolvedRef.nodePointer, ref_utils_1.escapePointer(segment));
321
+ resolvedRef.nodePointer = (0, ref_utils_1.joinPointer)(resolvedRef.nodePointer, (0, ref_utils_1.escapePointer)(segment));
322
322
  }
323
323
  else {
324
324
  target = undefined;
@@ -328,7 +328,7 @@ function resolveDocument(opts) {
328
328
  resolvedRef.node = target;
329
329
  resolvedRef.document = targetDoc;
330
330
  const refId = makeRefId(document.source.absoluteRef, ref.$ref);
331
- if (resolvedRef.document && ref_utils_1.isRef(target)) {
331
+ if (resolvedRef.document && (0, ref_utils_1.isRef)(target)) {
332
332
  resolvedRef = yield followRef(resolvedRef.document, target, pushRef(refStack, target));
333
333
  }
334
334
  resolvedRefMap.set(refId, resolvedRef);
package/lib/rules/ajv.js CHANGED
@@ -71,7 +71,7 @@ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allo
71
71
  if (error.keyword === 'additionalProperties' || error.keyword === 'unevaluatedProperties') {
72
72
  const property = error.params.additionalProperty || error.params.unevaluatedProperty;
73
73
  message = `${message} \`${property}\``;
74
- error.instancePath += '/' + ref_utils_1.escapePointer(property);
74
+ error.instancePath += '/' + (0, ref_utils_1.escapePointer)(property);
75
75
  }
76
76
  return Object.assign(Object.assign({}, error), { message,
77
77
  suggest });
@@ -1,12 +1,3 @@
1
- import { Async2Rule } from '../../visitors';
2
- export declare const rules: {
3
- spec: Async2Rule;
4
- assertions: (opts: Record<string, import("../common/assertions").Assertion>) => (import("../../visitors").Oas3Visitor | import("../../visitors").Oas2Visitor)[];
5
- 'info-contact': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
6
- 'operation-operationId': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
7
- 'channels-kebab-case': Async2Rule;
8
- 'no-channel-trailing-slash': Async2Rule;
9
- 'tag-description': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
10
- 'tags-alphabetical': import("../../visitors").Oas3Rule | import("../../visitors").Oas2Rule;
11
- };
1
+ import type { Async2RuleSet } from '../../oas-types';
2
+ export declare const rules: Async2RuleSet<'built-in'>;
12
3
  export declare const preprocessors: {};
@@ -1,11 +1,11 @@
1
1
  import { AssertionContext, AssertResult, CustomFunction } from 'core/src/config/types';
2
2
  import { Location } from '../../../ref-utils';
3
- export declare type AssertionFnContext = AssertionContext & {
3
+ export type AssertionFnContext = AssertionContext & {
4
4
  baseLocation: Location;
5
5
  rawValue?: any;
6
6
  };
7
- export declare type AssertionFn = (value: any, condition: any, ctx: AssertionFnContext) => AssertResult[];
8
- export declare type Asserts = {
7
+ export type AssertionFn = (value: any, condition: any, ctx: AssertionFnContext) => AssertResult[];
8
+ export type Asserts = {
9
9
  pattern: AssertionFn;
10
10
  notPattern: AssertionFn;
11
11
  enum: AssertionFn;