@redocly/openapi-core 1.0.0-beta.107 → 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 (98) hide show
  1. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  2. package/lib/bundle.js +5 -2
  3. package/lib/config/all.js +2 -2
  4. package/lib/config/config-resolvers.js +31 -13
  5. package/lib/config/config.d.ts +3 -5
  6. package/lib/config/config.js +7 -4
  7. package/lib/config/load.d.ts +7 -0
  8. package/lib/config/load.js +14 -6
  9. package/lib/config/minimal.js +2 -2
  10. package/lib/config/recommended.js +2 -2
  11. package/lib/config/rules.d.ts +1 -1
  12. package/lib/config/utils.js +5 -5
  13. package/lib/decorators/common/registry-dependencies.js +1 -1
  14. package/lib/env.d.ts +3 -0
  15. package/lib/env.js +8 -0
  16. package/lib/format/codeframes.js +16 -10
  17. package/lib/format/format.js +28 -26
  18. package/lib/index.d.ts +5 -5
  19. package/lib/index.js +3 -1
  20. package/lib/js-yaml/index.js +1 -0
  21. package/lib/logger.d.ts +10 -0
  22. package/lib/logger.js +31 -0
  23. package/lib/output.d.ts +3 -0
  24. package/lib/output.js +9 -0
  25. package/lib/redocly/index.js +10 -9
  26. package/lib/redocly/registry-api-types.d.ts +28 -30
  27. package/lib/redocly/registry-api.d.ts +4 -3
  28. package/lib/redocly/registry-api.js +7 -2
  29. package/lib/ref-utils.js +2 -1
  30. package/lib/resolve.d.ts +1 -1
  31. package/lib/resolve.js +1 -1
  32. package/lib/rules/ajv.js +1 -1
  33. package/lib/rules/common/assertions/asserts.js +4 -4
  34. package/lib/rules/common/assertions/index.js +1 -1
  35. package/lib/rules/common/operation-security-defined.js +1 -1
  36. package/lib/rules/common/spec.js +2 -2
  37. package/lib/rules/oas2/remove-unused-components.js +2 -2
  38. package/lib/rules/oas3/index.js +2 -2
  39. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  40. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  41. package/lib/rules/oas3/no-unused-components.js +1 -1
  42. package/lib/rules/oas3/remove-unused-components.js +3 -3
  43. package/lib/rules/utils.d.ts +1 -1
  44. package/lib/rules/utils.js +1 -1
  45. package/lib/types/redocly-yaml.js +1 -1
  46. package/lib/utils.d.ts +3 -0
  47. package/lib/utils.js +15 -7
  48. package/lib/visitors.d.ts +1 -1
  49. package/lib/visitors.js +2 -2
  50. package/package.json +1 -1
  51. package/src/__tests__/logger-browser.test.ts +53 -0
  52. package/src/__tests__/logger.test.ts +47 -0
  53. package/src/__tests__/output-browser.test.ts +18 -0
  54. package/src/__tests__/output.test.ts +15 -0
  55. package/src/__tests__/utils-browser.test.ts +11 -0
  56. package/src/__tests__/utils.test.ts +7 -0
  57. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
  58. package/src/bundle.ts +6 -3
  59. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +4 -4
  60. package/src/config/__tests__/config.test.ts +35 -0
  61. package/src/config/__tests__/load.test.ts +79 -1
  62. package/src/config/all.ts +2 -2
  63. package/src/config/config-resolvers.ts +43 -17
  64. package/src/config/config.ts +10 -8
  65. package/src/config/load.ts +28 -5
  66. package/src/config/minimal.ts +2 -2
  67. package/src/config/recommended.ts +2 -2
  68. package/src/config/utils.ts +6 -5
  69. package/src/decorators/common/registry-dependencies.ts +1 -1
  70. package/src/env.ts +5 -0
  71. package/src/format/codeframes.ts +15 -9
  72. package/src/format/format.ts +28 -33
  73. package/src/index.ts +6 -4
  74. package/src/js-yaml/index.ts +1 -0
  75. package/src/logger.ts +34 -0
  76. package/src/output.ts +7 -0
  77. package/src/redocly/index.ts +7 -4
  78. package/src/redocly/registry-api-types.ts +27 -29
  79. package/src/redocly/registry-api.ts +16 -6
  80. package/src/ref-utils.ts +2 -1
  81. package/src/resolve.ts +4 -4
  82. package/src/rules/ajv.ts +1 -1
  83. package/src/rules/common/assertions/asserts.ts +4 -4
  84. package/src/rules/common/assertions/index.ts +1 -1
  85. package/src/rules/common/operation-security-defined.ts +1 -1
  86. package/src/rules/common/spec.ts +2 -2
  87. package/src/rules/oas2/remove-unused-components.ts +2 -2
  88. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  89. package/src/rules/oas3/index.ts +2 -2
  90. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +2 -2
  91. package/src/rules/oas3/no-unused-components.ts +1 -1
  92. package/src/rules/oas3/remove-unused-components.ts +4 -4
  93. package/src/rules/utils.ts +1 -1
  94. package/src/types/redocly-yaml.ts +1 -1
  95. package/src/utils.ts +16 -6
  96. package/src/visitors.ts +5 -5
  97. package/tsconfig.tsbuildinfo +1 -1
  98. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
@@ -2,20 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatProblems = exports.getTotals = void 0;
4
4
  const path = require("path");
5
- const colorette_1 = require("colorette");
5
+ const logger_1 = require("../logger");
6
+ const output_1 = require("../output");
6
7
  const coreVersion = require('../../package.json').version;
7
8
  const codeframes_1 = require("./codeframes");
8
- const config_1 = require("../config");
9
+ const env_1 = require("../env");
9
10
  const ERROR_MESSAGE = {
10
11
  INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn',
11
12
  };
12
13
  const BG_COLORS = {
13
- warn: (str) => colorette_1.bgYellow(colorette_1.black(str)),
14
- error: colorette_1.bgRed,
14
+ warn: (str) => logger_1.colorize.bgYellow(logger_1.colorize.black(str)),
15
+ error: logger_1.colorize.bgRed,
15
16
  };
16
17
  const COLORS = {
17
- warn: colorette_1.yellow,
18
- error: colorette_1.red,
18
+ warn: logger_1.colorize.yellow,
19
+ error: logger_1.colorize.red,
19
20
  };
20
21
  const SEVERITY_NAMES = {
21
22
  warn: 'Warning',
@@ -51,8 +52,8 @@ function getTotals(problems) {
51
52
  }
52
53
  exports.getTotals = getTotals;
53
54
  function formatProblems(problems, opts) {
54
- const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color = colorette_1.options.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
55
- colorette_1.options.enabled = color; // force colors if specified
55
+ const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color = logger_1.colorOptions.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
56
+ logger_1.colorOptions.enabled = color; // force colors if specified
56
57
  const totalProblems = problems.length;
57
58
  problems = problems.filter((m) => !m.ignored);
58
59
  const ignoredProblems = totalProblems - problems.length;
@@ -68,31 +69,31 @@ function formatProblems(problems, opts) {
68
69
  case 'codeframe':
69
70
  for (let i = 0; i < problems.length; i++) {
70
71
  const problem = problems[i];
71
- process.stderr.write(`${formatCodeframe(problem, i)}\n`);
72
+ logger_1.logger.info(`${formatCodeframe(problem, i)}\n`);
72
73
  }
73
74
  break;
74
75
  case 'stylish': {
75
76
  const groupedByFile = groupByFiles(problems);
76
77
  for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(groupedByFile)) {
77
- process.stderr.write(`${colorette_1.blue(path.relative(cwd, file))}:\n`);
78
+ logger_1.logger.info(`${logger_1.colorize.blue(path.relative(cwd, file))}:\n`);
78
79
  for (let i = 0; i < fileProblems.length; i++) {
79
80
  const problem = fileProblems[i];
80
- process.stderr.write(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
81
+ logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
81
82
  }
82
- process.stderr.write('\n');
83
+ logger_1.logger.info('\n');
83
84
  }
84
85
  break;
85
86
  }
86
87
  case 'checkstyle': {
87
88
  const groupedByFile = groupByFiles(problems);
88
- process.stdout.write('<?xml version="1.0" encoding="UTF-8"?>\n');
89
- process.stdout.write('<checkstyle version="4.3">\n');
89
+ output_1.output.write('<?xml version="1.0" encoding="UTF-8"?>\n');
90
+ output_1.output.write('<checkstyle version="4.3">\n');
90
91
  for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
91
- process.stdout.write(`<file name="${xmlEscape(path.relative(cwd, file))}">\n`);
92
+ output_1.output.write(`<file name="${xmlEscape(path.relative(cwd, file))}">\n`);
92
93
  fileProblems.forEach(formatCheckstyle);
93
- process.stdout.write(`</file>\n`);
94
+ output_1.output.write(`</file>\n`);
94
95
  }
95
- process.stdout.write(`</checkstyle>\n`);
96
+ output_1.output.write(`</checkstyle>\n`);
96
97
  break;
97
98
  }
98
99
  case 'codeclimate':
@@ -100,7 +101,7 @@ function formatProblems(problems, opts) {
100
101
  break;
101
102
  }
102
103
  if (totalProblems - ignoredProblems > maxProblems) {
103
- process.stderr.write(`< ... ${totalProblems - maxProblems} more problems hidden > ${colorette_1.gray('increase with `--max-problems N`')}\n`);
104
+ logger_1.logger.info(`< ... ${totalProblems - maxProblems} more problems hidden > ${logger_1.colorize.gray('increase with `--max-problems N`')}\n`);
104
105
  }
105
106
  function outputForCodeClimate() {
106
107
  const issues = problems.map((p) => {
@@ -118,7 +119,7 @@ function formatProblems(problems, opts) {
118
119
  fingerprint: `${p.ruleId}${p.location.length > 0 ? '-' + p.location[0].pointer : ''}`,
119
120
  };
120
121
  });
121
- process.stdout.write(JSON.stringify(issues, null, 2));
122
+ output_1.output.write(JSON.stringify(issues, null, 2));
122
123
  }
123
124
  function outputJSON() {
124
125
  const resultObject = {
@@ -126,13 +127,13 @@ function formatProblems(problems, opts) {
126
127
  version,
127
128
  problems: problems.map((p) => {
128
129
  var _a;
129
- let problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
130
+ const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
130
131
  ref: path.relative(cwd, location.source.absoluteRef),
131
132
  } }))), from: p.from
132
133
  ? Object.assign(Object.assign({}, p.from), { source: {
133
134
  ref: path.relative(cwd, ((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef) || cwd),
134
135
  } }) : undefined });
135
- if (config_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
136
+ if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
136
137
  const location = p.location[0]; // TODO: support multiple locations
137
138
  const loc = codeframes_1.getLineColLocation(location);
138
139
  problem.codeframe = codeframes_1.getCodeframe(loc, color);
@@ -140,7 +141,7 @@ function formatProblems(problems, opts) {
140
141
  return problem;
141
142
  }),
142
143
  };
143
- process.stdout.write(JSON.stringify(resultObject, null, 2));
144
+ output_1.output.write(JSON.stringify(resultObject, null, 2));
144
145
  }
145
146
  function getBgColor(problem) {
146
147
  const { severity } = problem;
@@ -154,7 +155,7 @@ function formatProblems(problems, opts) {
154
155
  const location = problem.location[0]; // TODO: support multiple locations
155
156
  const relativePath = path.relative(cwd, location.source.absoluteRef);
156
157
  const loc = codeframes_1.getLineColLocation(location);
157
- const atPointer = location.pointer ? colorette_1.gray(`at ${location.pointer}`) : '';
158
+ const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
158
159
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
159
160
  return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
160
161
  `${problem.message}\n\n` +
@@ -162,7 +163,7 @@ function formatProblems(problems, opts) {
162
163
  codeframes_1.getCodeframe(loc, color) +
163
164
  '\n\n' +
164
165
  formatFrom(cwd, problem.from) +
165
- `${SEVERITY_NAMES[problem.severity]} was generated by the ${colorette_1.blue(problem.ruleId)} rule.\n\n`);
166
+ `${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
166
167
  }
167
168
  function formatStylish(problem, locationPad, ruleIdPad) {
168
169
  const color = COLORS[problem.severity];
@@ -178,7 +179,7 @@ function formatProblems(problems, opts) {
178
179
  const severity = problem.severity == 'warn' ? 'warning' : 'error';
179
180
  const message = xmlEscape(problem.message);
180
181
  const source = xmlEscape(problem.ruleId);
181
- process.stdout.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
182
+ output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
182
183
  }
183
184
  }
184
185
  exports.formatProblems = formatProblems;
@@ -188,7 +189,7 @@ function formatFrom(cwd, location) {
188
189
  const relativePath = path.relative(cwd, location.source.absoluteRef);
189
190
  const loc = codeframes_1.getLineColLocation(location);
190
191
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
191
- return `referenced from ${colorette_1.blue(fileWithLoc)}\n\n`;
192
+ return `referenced from ${logger_1.colorize.blue(fileWithLoc)}\n\n`;
192
193
  }
193
194
  function formatDidYouMean(problem) {
194
195
  if (problem.suggest.length === 0)
@@ -217,6 +218,7 @@ const groupByFiles = (problems) => {
217
218
  return fileGroups;
218
219
  };
219
220
  function xmlEscape(s) {
221
+ // eslint-disable-next-line no-control-regex
220
222
  return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
221
223
  switch (char) {
222
224
  case '<':
package/lib/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist } from './utils';
1
+ export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy } from './utils';
2
2
  export { Oas3_1Types } from './types/oas3_1';
3
3
  export { Oas3Types } from './types/oas3';
4
4
  export { Oas2Types } from './types/oas2';
5
5
  export { ConfigTypes } from './types/redocly-yaml';
6
- export { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, } from './typings/openapi';
7
- export { Oas2Definition } from './typings/swagger';
8
- export { StatsAccumulator, StatsName } from './typings/common';
6
+ export type { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, OasRef, } from './typings/openapi';
7
+ export type { Oas2Definition } from './typings/swagger';
8
+ export type { StatsAccumulator, StatsName } from './typings/common';
9
9
  export { normalizeTypes } from './types';
10
10
  export { Stats } from './rules/other/stats';
11
- export { Config, StyleguideConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, } from './config';
11
+ export { Config, StyleguideConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, } from './config';
12
12
  export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
13
13
  export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
14
14
  export { parseYaml, stringifyYaml } from './js-yaml';
package/lib/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
3
+ exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
6
6
  Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
7
7
  Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
8
+ Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
8
9
  var oas3_1_1 = require("./types/oas3_1");
9
10
  Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
10
11
  var oas3_1 = require("./types/oas3");
@@ -27,6 +28,7 @@ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function (
27
28
  Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
28
29
  Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
29
30
  Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAMES; } });
31
+ Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
30
32
  var redocly_1 = require("./redocly");
31
33
  Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
32
34
  Object.defineProperty(exports, "isRedoclyRegistryURL", { enumerable: true, get: function () { return redocly_1.isRedoclyRegistryURL; } });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringifyYaml = exports.parseYaml = void 0;
4
4
  // TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
6
  // @ts-ignore
6
7
  const js_yaml_1 = require("js-yaml");
7
8
  const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
@@ -0,0 +1,10 @@
1
+ import * as colorette from 'colorette';
2
+ export { options as colorOptions } from 'colorette';
3
+ export declare const colorize: typeof colorette;
4
+ declare class Logger {
5
+ protected stderr(str: string): boolean;
6
+ info(str: string): boolean | void;
7
+ warn(str: string): boolean | void;
8
+ error(str: string): boolean | void;
9
+ }
10
+ export declare const logger: Logger;
package/lib/logger.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = exports.colorize = exports.colorOptions = void 0;
4
+ const colorette = require("colorette");
5
+ var colorette_1 = require("colorette");
6
+ Object.defineProperty(exports, "colorOptions", { enumerable: true, get: function () { return colorette_1.options; } });
7
+ const env_1 = require("./env");
8
+ const utils_1 = require("./utils");
9
+ exports.colorize = new Proxy(colorette, {
10
+ get(target, prop) {
11
+ if (env_1.isBrowser) {
12
+ return utils_1.identity;
13
+ }
14
+ return target[prop];
15
+ },
16
+ });
17
+ class Logger {
18
+ stderr(str) {
19
+ return process.stderr.write(str);
20
+ }
21
+ info(str) {
22
+ return env_1.isBrowser ? console.log(str) : this.stderr(str);
23
+ }
24
+ warn(str) {
25
+ return env_1.isBrowser ? console.warn(str) : this.stderr(exports.colorize.yellow(str));
26
+ }
27
+ error(str) {
28
+ return env_1.isBrowser ? console.error(str) : this.stderr(exports.colorize.red(str));
29
+ }
30
+ }
31
+ exports.logger = new Logger();
@@ -0,0 +1,3 @@
1
+ export declare const output: {
2
+ write(str: string): boolean | undefined;
3
+ };
package/lib/output.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = void 0;
4
+ const env_1 = require("./env");
5
+ exports.output = {
6
+ write(str) {
7
+ return env_1.isBrowser ? undefined : process.stdout.write(str);
8
+ },
9
+ };
@@ -13,26 +13,27 @@ exports.isRedoclyRegistryURL = exports.RedoclyClient = void 0;
13
13
  const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
15
  const os_1 = require("os");
16
- const colorette_1 = require("colorette");
17
16
  const registry_api_1 = require("./registry-api");
18
17
  const config_1 = require("../config/config");
18
+ const env_1 = require("../env");
19
19
  const utils_1 = require("../utils");
20
+ const logger_1 = require("../logger");
20
21
  const TOKEN_FILENAME = '.redocly-config.json';
21
22
  class RedoclyClient {
22
23
  constructor(region) {
23
24
  this.accessTokens = {};
24
25
  this.region = this.loadRegion(region);
25
26
  this.loadTokens();
26
- this.domain = region ? config_1.DOMAINS[region] : config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
27
- config_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
27
+ this.domain = region ? config_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
28
+ env_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
28
29
  this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
29
30
  }
30
31
  loadRegion(region) {
31
32
  if (region && !config_1.DOMAINS[region]) {
32
- throw new Error(`Invalid argument: region in config file.\nGiven: ${colorette_1.green(region)}, choices: "us", "eu".`);
33
+ throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
33
34
  }
34
- if (config_1.env.REDOCLY_DOMAIN) {
35
- return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === config_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
35
+ if (env_1.env.REDOCLY_DOMAIN) {
36
+ return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === env_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
36
37
  }
37
38
  return region || config_1.DEFAULT_REGION;
38
39
  }
@@ -64,8 +65,8 @@ class RedoclyClient {
64
65
  [this.region]: credentials.token,
65
66
  })));
66
67
  }
67
- if (config_1.env.REDOCLY_AUTHORIZATION) {
68
- this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: config_1.env.REDOCLY_AUTHORIZATION }));
68
+ if (env_1.env.REDOCLY_AUTHORIZATION) {
69
+ this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: env_1.env.REDOCLY_AUTHORIZATION }));
69
70
  }
70
71
  }
71
72
  getAllTokens() {
@@ -142,7 +143,7 @@ class RedoclyClient {
142
143
  }
143
144
  exports.RedoclyClient = RedoclyClient;
144
145
  function isRedoclyRegistryURL(link) {
145
- const domain = config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
146
+ const domain = env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
146
147
  const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
147
148
  if (!link.startsWith(`https://api.${domain}/registry/`) &&
148
149
  !link.startsWith(`https://api.${legacyDomain}/registry/`)) {
@@ -1,31 +1,29 @@
1
- export declare namespace RegistryApiTypes {
2
- interface VersionParams {
3
- organizationId: string;
4
- name: string;
5
- version: string;
6
- }
7
- export interface PrepareFileuploadParams extends VersionParams {
8
- filesHash: string;
9
- filename: string;
10
- isUpsert?: boolean;
11
- }
12
- export interface PushApiParams extends VersionParams {
13
- rootFilePath: string;
14
- filePaths: string[];
15
- branch?: string;
16
- isUpsert?: boolean;
17
- isPublic?: boolean;
18
- batchId?: string;
19
- batchSize?: number;
20
- }
21
- export interface PrepareFileuploadOKResponse {
22
- filePath: string;
23
- signedUploadUrl: string;
24
- }
25
- export interface NotFoundProblemResponse {
26
- status: 404;
27
- title: 'Not Found';
28
- code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
29
- }
30
- export {};
1
+ interface VersionParams {
2
+ organizationId: string;
3
+ name: string;
4
+ version: string;
31
5
  }
6
+ export interface PrepareFileuploadParams extends VersionParams {
7
+ filesHash: string;
8
+ filename: string;
9
+ isUpsert?: boolean;
10
+ }
11
+ export interface PushApiParams extends VersionParams {
12
+ rootFilePath: string;
13
+ filePaths: string[];
14
+ branch?: string;
15
+ isUpsert?: boolean;
16
+ isPublic?: boolean;
17
+ batchId?: string;
18
+ batchSize?: number;
19
+ }
20
+ export interface PrepareFileuploadOKResponse {
21
+ filePath: string;
22
+ signedUploadUrl: string;
23
+ }
24
+ export interface NotFoundProblemResponse {
25
+ status: 404;
26
+ title: 'Not Found';
27
+ code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
28
+ }
29
+ export {};
@@ -1,5 +1,6 @@
1
- import { RegistryApiTypes } from './registry-api-types';
1
+ import type { PrepareFileuploadOKResponse, PrepareFileuploadParams, PushApiParams } from './registry-api-types';
2
2
  import type { AccessTokens, Region } from '../config/types';
3
+ export declare const currentCommand: string;
3
4
  export declare class RegistryApi {
4
5
  private accessTokens;
5
6
  private region;
@@ -12,6 +13,6 @@ export declare class RegistryApi {
12
13
  viewerId: string;
13
14
  organizations: string[];
14
15
  }>;
15
- prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>;
16
- pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: RegistryApiTypes.PushApiParams): Promise<void>;
16
+ prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: PrepareFileuploadParams): Promise<PrepareFileuploadOKResponse>;
17
+ pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: PushApiParams): Promise<void>;
17
18
  }
@@ -8,12 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var _a;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RegistryApi = void 0;
13
+ exports.RegistryApi = exports.currentCommand = void 0;
13
14
  const node_fetch_1 = require("node-fetch");
14
15
  const config_1 = require("../config/config");
15
16
  const utils_1 = require("../utils");
16
17
  const version = require('../../package.json').version;
18
+ exports.currentCommand = typeof process !== 'undefined' ? ((_a = process.env) === null || _a === void 0 ? void 0 : _a.REDOCLY_CLI_COMMAND) || '' : '';
17
19
  class RegistryApi {
18
20
  constructor(accessTokens, region) {
19
21
  this.accessTokens = accessTokens;
@@ -31,7 +33,10 @@ class RegistryApi {
31
33
  }
32
34
  request(path = '', options = {}, region) {
33
35
  return __awaiter(this, void 0, void 0, function* () {
34
- const headers = Object.assign({}, options.headers || {}, { 'x-redocly-cli-version': version });
36
+ const headers = Object.assign({}, options.headers || {}, {
37
+ 'x-redocly-cli-version': version,
38
+ 'user-agent': `redocly-cli / ${version} ${exports.currentCommand}`,
39
+ });
35
40
  if (!headers.hasOwnProperty('authorization')) {
36
41
  throw new Error('Unauthorized');
37
42
  }
package/lib/ref-utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isMappingRef = exports.isAbsoluteUrl = exports.refBaseName = exports.pointerBaseName = exports.parsePointer = exports.parseRef = exports.escapePointer = exports.unescapePointer = exports.Location = exports.isRef = exports.joinPointer = void 0;
4
+ const utils_1 = require("./utils");
4
5
  function joinPointer(base, key) {
5
6
  if (base === '')
6
7
  base = '#/';
@@ -41,7 +42,7 @@ function parseRef(ref) {
41
42
  const [uri, pointer] = ref.split('#/');
42
43
  return {
43
44
  uri: uri || null,
44
- pointer: pointer ? pointer.split('/').map(unescapePointer).filter(Boolean) : [],
45
+ pointer: pointer ? pointer.split('/').map(unescapePointer).filter(utils_1.isTruthy) : [],
45
46
  };
46
47
  }
47
48
  exports.parseRef = parseRef;
package/lib/resolve.d.ts CHANGED
@@ -33,7 +33,7 @@ export declare function makeDocumentFromString(sourceString: string, absoluteRef
33
33
  parsed: unknown;
34
34
  };
35
35
  export declare class BaseResolver {
36
- private config;
36
+ protected config: ResolveConfig;
37
37
  cache: Map<string, Promise<Document | ResolveError>>;
38
38
  constructor(config?: ResolveConfig);
39
39
  getFiles(): Set<string>;
package/lib/resolve.js CHANGED
@@ -271,7 +271,7 @@ function resolveDocument(opts) {
271
271
  };
272
272
  let target = targetDoc.parsed;
273
273
  const segments = pointer;
274
- for (let segment of segments) {
274
+ for (const segment of segments) {
275
275
  if (typeof target !== 'object') {
276
276
  target = undefined;
277
277
  break;
package/lib/rules/ajv.js CHANGED
@@ -56,7 +56,7 @@ function validateJsonSchema(data, schema, schemaLoc, instancePath, resolve, allo
56
56
  };
57
57
  function beatifyErrorMessage(error) {
58
58
  let message = error.message;
59
- let suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
59
+ const suggest = error.keyword === 'enum' ? error.params.allowedValues : undefined;
60
60
  if (suggest) {
61
61
  message += ` ${suggest.map((e) => `"${e}"`).join(', ')}`;
62
62
  }
@@ -35,7 +35,7 @@ exports.asserts = {
35
35
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
36
36
  const values = utils_1.isString(value) ? [value] : value;
37
37
  const regx = utils_2.regexFromString(condition);
38
- for (let _val of values) {
38
+ for (const _val of values) {
39
39
  if (!(regx === null || regx === void 0 ? void 0 : regx.test(_val))) {
40
40
  return { isValid: false, location: utils_1.isString(value) ? baseLocation : baseLocation.key() };
41
41
  }
@@ -46,7 +46,7 @@ exports.asserts = {
46
46
  if (typeof value === 'undefined')
47
47
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
48
48
  const values = utils_1.isString(value) ? [value] : value;
49
- for (let _val of values) {
49
+ for (const _val of values) {
50
50
  if (!condition.includes(_val)) {
51
51
  return {
52
52
  isValid: false,
@@ -72,7 +72,7 @@ exports.asserts = {
72
72
  if (typeof value === 'undefined')
73
73
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
74
74
  const values = utils_1.isString(value) ? [value] : value;
75
- for (let _val of values) {
75
+ for (const _val of values) {
76
76
  if (condition.includes(_val)) {
77
77
  return {
78
78
  isValid: false,
@@ -104,7 +104,7 @@ exports.asserts = {
104
104
  if (typeof value === 'undefined')
105
105
  return { isValid: true }; // property doesn't exist, no need to lint it with this assert
106
106
  const values = utils_1.isString(value) ? [value] : value;
107
- for (let _val of values) {
107
+ for (const _val of values) {
108
108
  let matchCase = false;
109
109
  switch (condition) {
110
110
  case 'camelCase':
@@ -4,7 +4,7 @@ exports.Assertions = void 0;
4
4
  const asserts_1 = require("./asserts");
5
5
  const utils_1 = require("./utils");
6
6
  const Assertions = (opts) => {
7
- let visitors = [];
7
+ const visitors = [];
8
8
  // As 'Assertions' has an array of asserts,
9
9
  // that array spreads into an 'opts' object on init rules phase here
10
10
  // https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/config/config.ts#L311
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OperationSecurityDefined = void 0;
4
4
  const OperationSecurityDefined = () => {
5
- let referencedSchemes = new Map();
5
+ const referencedSchemes = new Map();
6
6
  return {
7
7
  DefinitionRoot: {
8
8
  leave(_, { report }) {
@@ -27,7 +27,7 @@ const OasSpec = () => {
27
27
  return;
28
28
  }
29
29
  const required = typeof type.required === 'function' ? type.required(node, key) : type.required;
30
- for (let propName of required || []) {
30
+ for (const propName of required || []) {
31
31
  if (!node.hasOwnProperty(propName)) {
32
32
  report({
33
33
  message: `The field \`${propName}\` must be present on this level.`,
@@ -52,7 +52,7 @@ const OasSpec = () => {
52
52
  const requiredOneOf = type.requiredOneOf || null;
53
53
  if (requiredOneOf) {
54
54
  let hasProperty = false;
55
- for (let propName of requiredOneOf || []) {
55
+ for (const propName of requiredOneOf || []) {
56
56
  if (node.hasOwnProperty(propName)) {
57
57
  hasProperty = true;
58
58
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoveUnusedComponents = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const RemoveUnusedComponents = () => {
6
- let components = new Map();
6
+ const components = new Map();
7
7
  function registerComponent(location, componentType, name) {
8
8
  var _a;
9
9
  components.set(location.absolutePointer, {
@@ -30,7 +30,7 @@ const RemoveUnusedComponents = () => {
30
30
  leave(root, ctx) {
31
31
  const data = ctx.getVisitorData();
32
32
  data.removedCount = 0;
33
- let rootComponents = new Set();
33
+ const rootComponents = new Set();
34
34
  components.forEach((usageInfo) => {
35
35
  const { used, name, componentType } = usageInfo;
36
36
  if (!used && componentType) {
@@ -39,7 +39,7 @@ const no_undefined_server_variable_1 = require("./no-undefined-server-variable")
39
39
  const operation_operationId_1 = require("../common/operation-operationId");
40
40
  const operation_summary_1 = require("../common/operation-summary");
41
41
  const no_ambiguous_paths_1 = require("../common/no-ambiguous-paths");
42
- const no_servers_empty_enum_1 = require("./no-servers-empty-enum");
42
+ const no_server_variables_empty_enum_1 = require("./no-server-variables-empty-enum");
43
43
  const no_http_verbs_in_paths_1 = require("../common/no-http-verbs-in-paths");
44
44
  const request_mime_type_1 = require("./request-mime-type");
45
45
  const response_mime_type_1 = require("./response-mime-type");
@@ -90,7 +90,7 @@ exports.rules = {
90
90
  'no-identical-paths': no_identical_paths_1.NoIdenticalPaths,
91
91
  'no-ambiguous-paths': no_ambiguous_paths_1.NoAmbiguousPaths,
92
92
  'no-undefined-server-variable': no_undefined_server_variable_1.NoUndefinedServerVariable,
93
- 'no-servers-empty-enum': no_servers_empty_enum_1.NoEmptyEnumServers,
93
+ 'no-server-variables-empty-enum': no_server_variables_empty_enum_1.NoServerVariablesEmptyEnum,
94
94
  'no-http-verbs-in-paths': no_http_verbs_in_paths_1.NoHttpVerbsInPaths,
95
95
  'path-excludes-patterns': path_excludes_patterns_1.PathExcludesPatterns,
96
96
  'request-mime-type': request_mime_type_1.RequestMimeType,
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule } from '../../visitors';
2
+ export declare const NoServerVariablesEmptyEnum: Oas3Rule;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoEmptyEnumServers = void 0;
3
+ exports.NoServerVariablesEmptyEnum = void 0;
4
4
  var enumError;
5
5
  (function (enumError) {
6
6
  enumError["empty"] = "empty";
7
7
  enumError["invalidDefaultValue"] = "invalidDefaultValue";
8
8
  })(enumError || (enumError = {}));
9
- const NoEmptyEnumServers = () => {
9
+ const NoServerVariablesEmptyEnum = () => {
10
10
  return {
11
11
  DefinitionRoot(root, { report, location }) {
12
12
  if (!root.servers || root.servers.length === 0)
@@ -43,13 +43,13 @@ const NoEmptyEnumServers = () => {
43
43
  },
44
44
  };
45
45
  };
46
- exports.NoEmptyEnumServers = NoEmptyEnumServers;
46
+ exports.NoServerVariablesEmptyEnum = NoServerVariablesEmptyEnum;
47
47
  function checkEnumVariables(server) {
48
48
  var _a;
49
49
  if (server.variables && Object.keys(server.variables).length === 0)
50
50
  return;
51
51
  const errors = [];
52
- for (var variable in server.variables) {
52
+ for (const variable in server.variables) {
53
53
  const serverVariable = server.variables[variable];
54
54
  if (!serverVariable.enum)
55
55
  continue;