@redocly/openapi-core 1.0.0-beta.106 → 1.0.0-beta.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +9 -6
- package/lib/config/all.js +5 -3
- package/lib/config/config-resolvers.js +32 -14
- package/lib/config/config.d.ts +3 -5
- package/lib/config/config.js +7 -4
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +14 -6
- package/lib/config/minimal.js +7 -4
- package/lib/config/recommended.js +7 -4
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +7 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +49 -11
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +49 -26
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -1
- package/lib/js-yaml/index.js +1 -0
- package/lib/lint.js +2 -2
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +3 -3
- package/lib/redocly/registry-api.js +7 -1
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +4 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- package/lib/rules/common/operation-2xx-response.js +1 -1
- package/lib/rules/common/operation-4xx-response.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
- package/lib/rules/common/spec.js +14 -3
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +1 -1
- package/lib/rules/oas2/index.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/index.js +8 -4
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
- package/lib/rules/oas3/no-unused-components.js +2 -2
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/remove-unused-components.js +4 -4
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +2 -2
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +16 -4
- package/lib/types/oas2.js +5 -5
- package/lib/types/oas3.js +27 -20
- package/lib/types/oas3_1.js +3 -3
- package/lib/types/redocly-yaml.js +47 -56
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +24 -7
- package/lib/visitors.d.ts +12 -12
- package/lib/visitors.js +15 -3
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
- package/src/__tests__/fixtures/extension.js +3 -3
- package/src/__tests__/format.test.ts +76 -0
- package/src/__tests__/lint.test.ts +106 -131
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +10 -7
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
- package/src/config/__tests__/config.test.ts +35 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
- package/src/config/__tests__/load.test.ts +76 -1
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +5 -3
- package/src/config/config-resolvers.ts +45 -19
- package/src/config/config.ts +10 -8
- package/src/config/load.ts +31 -7
- package/src/config/minimal.ts +7 -4
- package/src/config/recommended.ts +7 -4
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +11 -0
- package/src/config/utils.ts +115 -25
- package/src/decorators/common/registry-dependencies.ts +2 -2
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +15 -9
- package/src/format/format.ts +59 -34
- package/src/index.ts +6 -4
- package/src/js-yaml/index.ts +1 -0
- package/src/lint.ts +2 -2
- package/src/logger.ts +34 -0
- package/src/output.ts +7 -0
- package/src/redocly/index.ts +7 -4
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +18 -7
- package/src/ref-utils.ts +2 -1
- package/src/resolve.ts +7 -5
- package/src/rules/__tests__/utils.test.ts +39 -1
- package/src/rules/ajv.ts +7 -7
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
- package/src/rules/common/__tests__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec.test.ts +79 -0
- package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +1 -1
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- package/src/rules/common/operation-2xx-response.ts +1 -1
- package/src/rules/common/operation-4xx-response.ts +1 -1
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-tag-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
- package/src/rules/common/spec.ts +17 -3
- package/src/rules/common/tags-alphabetical.ts +1 -1
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +3 -3
- package/src/rules/oas2/request-mime-type.ts +1 -1
- package/src/rules/oas2/response-mime-type.ts +1 -1
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
- package/src/rules/oas3/index.ts +8 -4
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
- package/src/rules/oas3/no-unused-components.ts +2 -2
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +5 -5
- package/src/rules/oas3/request-mime-type.ts +1 -1
- package/src/rules/oas3/response-mime-type.ts +1 -1
- package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
- package/src/rules/other/stats.ts +2 -2
- package/src/rules/utils.ts +17 -3
- package/src/types/index.ts +2 -2
- package/src/types/oas2.ts +5 -5
- package/src/types/oas3.ts +27 -20
- package/src/types/oas3_1.ts +3 -3
- package/src/types/redocly-yaml.ts +53 -41
- package/src/utils.ts +31 -4
- package/src/visitors.ts +34 -18
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RegistryDependencies = void 0;
|
|
4
4
|
const redocly_1 = require("../../redocly");
|
|
5
5
|
const RegistryDependencies = () => {
|
|
6
|
-
|
|
6
|
+
const registryDependencies = new Set();
|
|
7
7
|
return {
|
|
8
|
-
|
|
8
|
+
Root: {
|
|
9
9
|
leave(_, ctx) {
|
|
10
10
|
const data = ctx.getVisitorData();
|
|
11
11
|
data.links = Array.from(registryDependencies);
|
package/lib/env.d.ts
ADDED
package/lib/env.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.env = exports.isBrowser = void 0;
|
|
4
|
+
exports.isBrowser =
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
|
|
8
|
+
exports.env = exports.isBrowser ? {} : process.env || {};
|
package/lib/format/codeframes.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAstNodeByPointer = exports.getLineColLocation = exports.getCodeframe = void 0;
|
|
4
|
-
const colorette_1 = require("colorette");
|
|
5
4
|
const yamlAst = require("yaml-ast-parser");
|
|
6
5
|
const ref_utils_1 = require("../ref-utils");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
7
|
const MAX_LINE_LENGTH = 150;
|
|
8
8
|
const MAX_CODEFRAME_LINES = 3;
|
|
9
9
|
// TODO: temporary
|
|
@@ -11,7 +11,7 @@ function parsePointer(pointer) {
|
|
|
11
11
|
return pointer.substr(2).split('/').map(ref_utils_1.unescapePointer);
|
|
12
12
|
}
|
|
13
13
|
function getCodeframe(location, color) {
|
|
14
|
-
|
|
14
|
+
logger_1.colorOptions.enabled = color;
|
|
15
15
|
const { start, end = { line: start.line, col: start.col + 1 }, source } = location;
|
|
16
16
|
const lines = source.getLines();
|
|
17
17
|
const startLineNum = start.line;
|
|
@@ -28,16 +28,22 @@ function getCodeframe(location, color) {
|
|
|
28
28
|
const line = lines[i - 1] || '';
|
|
29
29
|
if (line !== '')
|
|
30
30
|
currentPad = padSize(line);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx,
|
|
31
|
+
const startIdx = i === startLineNum ? start.col - 1 : currentPad;
|
|
32
|
+
const endIdx = i === endLineNum ? end.col - 1 : line.length;
|
|
33
|
+
prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, logger_1.colorize.red)]);
|
|
34
34
|
if (!color)
|
|
35
35
|
prefixedLines.push(['', underlineLine(line, startIdx, endIdx)]);
|
|
36
36
|
}
|
|
37
37
|
if (skipLines > 0) {
|
|
38
|
-
prefixedLines.push([
|
|
38
|
+
prefixedLines.push([
|
|
39
|
+
`…`,
|
|
40
|
+
`${whitespace(currentPad)}${logger_1.colorize.gray(`< ${skipLines} more lines >`)}`,
|
|
41
|
+
]);
|
|
39
42
|
// print last line
|
|
40
|
-
prefixedLines.push([
|
|
43
|
+
prefixedLines.push([
|
|
44
|
+
`${endLineNum}`,
|
|
45
|
+
markLine(lines[endLineNum - 1], -1, end.col - 1, logger_1.colorize.red),
|
|
46
|
+
]);
|
|
41
47
|
if (!color)
|
|
42
48
|
prefixedLines.push(['', underlineLine(lines[endLineNum - 1], -1, end.col - 1)]);
|
|
43
49
|
}
|
|
@@ -48,7 +54,7 @@ function getCodeframe(location, color) {
|
|
|
48
54
|
[`${endLineNum + 1}`, markLine(lines[endLineNum - 1 + 1])],
|
|
49
55
|
[`${endLineNum + 2}`, markLine(lines[endLineNum - 1 + 2])],
|
|
50
56
|
]);
|
|
51
|
-
function markLine(line, startIdx = -1, endIdx = +Infinity, variant =
|
|
57
|
+
function markLine(line, startIdx = -1, endIdx = +Infinity, variant = logger_1.colorize.gray) {
|
|
52
58
|
if (!color)
|
|
53
59
|
return line;
|
|
54
60
|
if (!line)
|
|
@@ -66,14 +72,14 @@ function printPrefixedLines(lines) {
|
|
|
66
72
|
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
|
|
67
73
|
const dedentLen = Math.min(...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))));
|
|
68
74
|
return existingLines
|
|
69
|
-
.map(([prefix, line]) =>
|
|
75
|
+
.map(([prefix, line]) => logger_1.colorize.gray(leftPad(padLen, prefix) + ' |') +
|
|
70
76
|
(line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''))
|
|
71
77
|
.join('\n');
|
|
72
78
|
}
|
|
73
79
|
function limitLineLength(line, maxLen = MAX_LINE_LENGTH) {
|
|
74
80
|
const overflowLen = line.length - maxLen;
|
|
75
81
|
if (overflowLen > 0) {
|
|
76
|
-
const charsMoreText =
|
|
82
|
+
const charsMoreText = logger_1.colorize.gray(`...<${overflowLen} chars>`);
|
|
77
83
|
return line.substring(0, maxLen - charsMoreText.length) + charsMoreText;
|
|
78
84
|
}
|
|
79
85
|
else {
|
package/lib/format/format.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare type Totals = {
|
|
|
4
4
|
warnings: number;
|
|
5
5
|
ignored: number;
|
|
6
6
|
};
|
|
7
|
-
export declare type OutputFormat = 'codeframe' | 'stylish' | 'json' | 'checkstyle' | 'codeclimate';
|
|
7
|
+
export declare type OutputFormat = 'codeframe' | 'stylish' | 'json' | 'checkstyle' | 'codeclimate' | 'summary';
|
|
8
8
|
export declare function getTotals(problems: (NormalizedProblem & {
|
|
9
9
|
ignored?: boolean;
|
|
10
10
|
})[]): Totals;
|
package/lib/format/format.js
CHANGED
|
@@ -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
|
|
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
|
|
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) =>
|
|
14
|
-
error:
|
|
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:
|
|
18
|
-
error:
|
|
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 =
|
|
55
|
-
|
|
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,39 +69,42 @@ 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
+
logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
logger_1.logger.info('\n');
|
|
83
84
|
}
|
|
84
85
|
break;
|
|
85
86
|
}
|
|
86
87
|
case 'checkstyle': {
|
|
87
88
|
const groupedByFile = groupByFiles(problems);
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
+
output_1.output.write(`<file name="${xmlEscape(path.relative(cwd, file))}">\n`);
|
|
92
93
|
fileProblems.forEach(formatCheckstyle);
|
|
93
|
-
|
|
94
|
+
output_1.output.write(`</file>\n`);
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
+
output_1.output.write(`</checkstyle>\n`);
|
|
96
97
|
break;
|
|
97
98
|
}
|
|
98
99
|
case 'codeclimate':
|
|
99
100
|
outputForCodeClimate();
|
|
100
101
|
break;
|
|
102
|
+
case 'summary':
|
|
103
|
+
formatSummary(problems);
|
|
104
|
+
break;
|
|
101
105
|
}
|
|
102
106
|
if (totalProblems - ignoredProblems > maxProblems) {
|
|
103
|
-
|
|
107
|
+
logger_1.logger.info(`< ... ${totalProblems - maxProblems} more problems hidden > ${logger_1.colorize.gray('increase with `--max-problems N`')}\n`);
|
|
104
108
|
}
|
|
105
109
|
function outputForCodeClimate() {
|
|
106
110
|
const issues = problems.map((p) => {
|
|
@@ -118,7 +122,7 @@ function formatProblems(problems, opts) {
|
|
|
118
122
|
fingerprint: `${p.ruleId}${p.location.length > 0 ? '-' + p.location[0].pointer : ''}`,
|
|
119
123
|
};
|
|
120
124
|
});
|
|
121
|
-
|
|
125
|
+
output_1.output.write(JSON.stringify(issues, null, 2));
|
|
122
126
|
}
|
|
123
127
|
function outputJSON() {
|
|
124
128
|
const resultObject = {
|
|
@@ -126,13 +130,13 @@ function formatProblems(problems, opts) {
|
|
|
126
130
|
version,
|
|
127
131
|
problems: problems.map((p) => {
|
|
128
132
|
var _a;
|
|
129
|
-
|
|
133
|
+
const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
|
|
130
134
|
ref: path.relative(cwd, location.source.absoluteRef),
|
|
131
135
|
} }))), from: p.from
|
|
132
136
|
? Object.assign(Object.assign({}, p.from), { source: {
|
|
133
137
|
ref: path.relative(cwd, ((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef) || cwd),
|
|
134
138
|
} }) : undefined });
|
|
135
|
-
if (
|
|
139
|
+
if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
|
|
136
140
|
const location = p.location[0]; // TODO: support multiple locations
|
|
137
141
|
const loc = codeframes_1.getLineColLocation(location);
|
|
138
142
|
problem.codeframe = codeframes_1.getCodeframe(loc, color);
|
|
@@ -140,7 +144,7 @@ function formatProblems(problems, opts) {
|
|
|
140
144
|
return problem;
|
|
141
145
|
}),
|
|
142
146
|
};
|
|
143
|
-
|
|
147
|
+
output_1.output.write(JSON.stringify(resultObject, null, 2));
|
|
144
148
|
}
|
|
145
149
|
function getBgColor(problem) {
|
|
146
150
|
const { severity } = problem;
|
|
@@ -154,7 +158,7 @@ function formatProblems(problems, opts) {
|
|
|
154
158
|
const location = problem.location[0]; // TODO: support multiple locations
|
|
155
159
|
const relativePath = path.relative(cwd, location.source.absoluteRef);
|
|
156
160
|
const loc = codeframes_1.getLineColLocation(location);
|
|
157
|
-
const atPointer = location.pointer ?
|
|
161
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
158
162
|
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
159
163
|
return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
|
|
160
164
|
`${problem.message}\n\n` +
|
|
@@ -162,7 +166,7 @@ function formatProblems(problems, opts) {
|
|
|
162
166
|
codeframes_1.getCodeframe(loc, color) +
|
|
163
167
|
'\n\n' +
|
|
164
168
|
formatFrom(cwd, problem.from) +
|
|
165
|
-
`${SEVERITY_NAMES[problem.severity]} was generated by the ${
|
|
169
|
+
`${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
|
|
166
170
|
}
|
|
167
171
|
function formatStylish(problem, locationPad, ruleIdPad) {
|
|
168
172
|
const color = COLORS[problem.severity];
|
|
@@ -178,17 +182,35 @@ function formatProblems(problems, opts) {
|
|
|
178
182
|
const severity = problem.severity == 'warn' ? 'warning' : 'error';
|
|
179
183
|
const message = xmlEscape(problem.message);
|
|
180
184
|
const source = xmlEscape(problem.ruleId);
|
|
181
|
-
|
|
185
|
+
output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
188
|
exports.formatProblems = formatProblems;
|
|
189
|
+
function formatSummary(problems) {
|
|
190
|
+
const counts = {};
|
|
191
|
+
for (const problem of problems) {
|
|
192
|
+
counts[problem.ruleId] = counts[problem.ruleId] || { count: 0, severity: problem.severity };
|
|
193
|
+
counts[problem.ruleId].count++;
|
|
194
|
+
}
|
|
195
|
+
const sorted = Object.entries(counts).sort(([, a], [, b]) => {
|
|
196
|
+
const severityDiff = severityToNumber(a.severity) - severityToNumber(b.severity);
|
|
197
|
+
return severityDiff || b.count - a.count;
|
|
198
|
+
});
|
|
199
|
+
for (const [ruleId, info] of sorted) {
|
|
200
|
+
const color = COLORS[info.severity];
|
|
201
|
+
const severityName = color(SEVERITY_NAMES[info.severity].toLowerCase().padEnd(7));
|
|
202
|
+
logger_1.logger.info(`${severityName} ${ruleId}: ${info.count}\n`);
|
|
203
|
+
}
|
|
204
|
+
logger_1.logger.info('\n');
|
|
205
|
+
}
|
|
185
206
|
function formatFrom(cwd, location) {
|
|
186
207
|
if (!location)
|
|
187
208
|
return '';
|
|
188
209
|
const relativePath = path.relative(cwd, location.source.absoluteRef);
|
|
189
210
|
const loc = codeframes_1.getLineColLocation(location);
|
|
190
211
|
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
191
|
-
|
|
212
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
213
|
+
return `referenced from ${logger_1.colorize.blue(fileWithLoc)} ${atPointer} \n\n`;
|
|
192
214
|
}
|
|
193
215
|
function formatDidYouMean(problem) {
|
|
194
216
|
if (problem.suggest.length === 0)
|
|
@@ -217,6 +239,7 @@ const groupByFiles = (problems) => {
|
|
|
217
239
|
return fileGroups;
|
|
218
240
|
};
|
|
219
241
|
function xmlEscape(s) {
|
|
242
|
+
// eslint-disable-next-line no-control-regex
|
|
220
243
|
return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
|
|
221
244
|
switch (char) {
|
|
222
245
|
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; } });
|
package/lib/js-yaml/index.js
CHANGED
|
@@ -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({
|
package/lib/lint.js
CHANGED
|
@@ -60,12 +60,12 @@ function lintDocument(opts) {
|
|
|
60
60
|
const normalizedVisitors = visitors_1.normalizeVisitors([...preprocessors, ...regularRules], types);
|
|
61
61
|
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
62
62
|
rootDocument: document,
|
|
63
|
-
rootType: types.
|
|
63
|
+
rootType: types.Root,
|
|
64
64
|
externalRefResolver,
|
|
65
65
|
});
|
|
66
66
|
walk_1.walkDocument({
|
|
67
67
|
document,
|
|
68
|
-
rootType: types.
|
|
68
|
+
rootType: types.Root,
|
|
69
69
|
normalizedVisitors,
|
|
70
70
|
resolvedRefMap,
|
|
71
71
|
ctx,
|
package/lib/logger.d.ts
ADDED
|
@@ -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();
|
package/lib/output.d.ts
ADDED
package/lib/output.js
ADDED
package/lib/redocly/index.js
CHANGED
|
@@ -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] :
|
|
27
|
-
|
|
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: ${
|
|
33
|
+
throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
|
|
33
34
|
}
|
|
34
|
-
if (
|
|
35
|
-
return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[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 (
|
|
68
|
-
this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]:
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PrepareFileuploadOKResponse, PrepareFileuploadParams, PushApiParams } from './registry-api-types';
|
|
2
2
|
import type { AccessTokens, Region } from '../config/types';
|
|
3
3
|
export declare class RegistryApi {
|
|
4
4
|
private accessTokens;
|
|
@@ -12,6 +12,6 @@ export declare class RegistryApi {
|
|
|
12
12
|
viewerId: string;
|
|
13
13
|
organizations: string[];
|
|
14
14
|
}>;
|
|
15
|
-
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }:
|
|
16
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }:
|
|
15
|
+
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: PrepareFileuploadParams): Promise<PrepareFileuploadOKResponse>;
|
|
16
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: PushApiParams): Promise<void>;
|
|
17
17
|
}
|
|
@@ -30,8 +30,14 @@ class RegistryApi {
|
|
|
30
30
|
return this;
|
|
31
31
|
}
|
|
32
32
|
request(path = '', options = {}, region) {
|
|
33
|
+
var _a, _b;
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const
|
|
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
|
+
});
|
|
35
41
|
if (!headers.hasOwnProperty('authorization')) {
|
|
36
42
|
throw new Error('Unauthorized');
|
|
37
43
|
}
|
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(
|
|
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
|
-
|
|
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
|
@@ -110,7 +110,9 @@ class BaseResolver {
|
|
|
110
110
|
return new Source(absoluteRef, body, mimeType);
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
|
|
113
|
+
const content = yield fs.promises.readFile(absoluteRef, 'utf-8');
|
|
114
|
+
// In some cases file have \r\n line delimeters like on windows, we should skip it.
|
|
115
|
+
return new Source(absoluteRef, content.replace(/\r\n/g, '\n'));
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
catch (error) {
|
|
@@ -271,7 +273,7 @@ function resolveDocument(opts) {
|
|
|
271
273
|
};
|
|
272
274
|
let target = targetDoc.parsed;
|
|
273
275
|
const segments = pointer;
|
|
274
|
-
for (
|
|
276
|
+
for (const segment of segments) {
|
|
275
277
|
if (typeof target !== 'object') {
|
|
276
278
|
target = undefined;
|
|
277
279
|
break;
|
package/lib/rules/ajv.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ErrorObject } from '@redocly/ajv';
|
|
|
2
2
|
import { Location } from '../ref-utils';
|
|
3
3
|
import { ResolveFn } from '../walk';
|
|
4
4
|
export declare function releaseAjvInstance(): void;
|
|
5
|
-
export declare function validateJsonSchema(data: any, schema: any, schemaLoc: Location, instancePath: string, resolve: ResolveFn,
|
|
5
|
+
export declare function validateJsonSchema(data: any, schema: any, schemaLoc: Location, instancePath: string, resolve: ResolveFn, allowAdditionalProperties: boolean): {
|
|
6
6
|
valid: boolean;
|
|
7
7
|
errors: (ErrorObject & {
|
|
8
8
|
suggest?: string[];
|