@redocly/openapi-core 1.0.0-beta.105 → 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.
- package/README.md +4 -4
- package/__tests__/utils.ts +5 -5
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +7 -4
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +3 -3
- package/lib/config/builtIn.d.ts +2 -2
- package/lib/config/builtIn.js +2 -2
- package/lib/config/config-resolvers.d.ts +5 -5
- package/lib/config/config-resolvers.js +70 -49
- package/lib/config/config.d.ts +8 -10
- package/lib/config/config.js +10 -7
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +18 -10
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +5 -4
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +5 -4
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +23 -19
- package/lib/config/utils.d.ts +5 -5
- package/lib/config/utils.js +48 -31
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.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.js +29 -27
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- 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 +4 -3
- package/lib/redocly/registry-api.js +9 -4
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- 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/info-license-url.d.ts +1 -1
- package/lib/rules/common/info-license-url.js +5 -10
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- 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-operationId.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +3 -3
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +5 -5
- package/lib/rules/oas3/index.js +6 -6
- 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} +4 -4
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/remove-unused-components.js +5 -5
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +20 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -8
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +22 -5
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -2
- 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 +141 -0
- package/src/__tests__/bundle.test.ts +68 -34
- package/src/__tests__/codeframes.test.ts +13 -14
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +74 -6
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/ref-utils.test.ts +13 -13
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +14 -11
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +48 -56
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
- package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/benchmark/benchmark.js +9 -5
- package/src/benchmark/utils.ts +5 -5
- package/src/bundle.ts +24 -20
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +111 -76
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
- package/src/config/__tests__/load.test.ts +79 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +5 -6
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +161 -96
- package/src/config/config.ts +15 -13
- package/src/config/load.ts +34 -11
- package/src/config/minimal.ts +7 -6
- package/src/config/recommended.ts +7 -6
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +78 -57
- package/src/decorators/__tests__/filter-out.test.ts +8 -4
- package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
- package/src/decorators/common/filters/filter-helper.ts +1 -1
- package/src/decorators/common/info-description-override.ts +1 -1
- package/src/decorators/common/operation-description-override.ts +1 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/decorators/common/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +18 -12
- package/src/format/format.ts +37 -42
- package/src/index.ts +8 -7
- package/src/js-yaml/index.ts +4 -8
- package/src/lint.ts +22 -18
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +1 -6
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +12 -7
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +22 -12
- package/src/ref-utils.ts +4 -3
- package/src/resolve.ts +11 -8
- package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.ts +7 -8
- package/src/rules/common/__tests__/info-description.test.ts +3 -3
- package/src/rules/common/__tests__/info-license.test.ts +2 -2
- package/src/rules/common/__tests__/license-url.test.ts +2 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
- package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
- package/src/rules/common/__tests__/spec.test.ts +2 -2
- package/src/rules/common/__tests__/tag-description.test.ts +2 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
- package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +7 -7
- package/src/rules/common/info-license-url.ts +4 -9
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-enum-type-mismatch.ts +12 -9
- 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-operationId.ts +1 -1
- package/src/rules/common/operation-parameters-unique.ts +2 -2
- package/src/rules/common/operation-security-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/path-params-defined.ts +1 -1
- package/src/rules/common/paths-kebab-case.ts +4 -1
- package/src/rules/common/scalar-property-missing-example.ts +1 -1
- package/src/rules/common/spec.ts +12 -9
- package/src/rules/no-unresolved-refs.ts +1 -1
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
- package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas2/index.ts +3 -3
- package/src/rules/oas2/remove-unused-components.ts +14 -9
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
- package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
- package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
- package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas3/index.ts +5 -5
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +21 -10
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +20 -4
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -8
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +26 -3
- package/src/visitors.ts +9 -9
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/license-url.ts +0 -10
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,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
|
-
|
|
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':
|
|
@@ -100,7 +101,7 @@ function formatProblems(problems, opts) {
|
|
|
100
101
|
break;
|
|
101
102
|
}
|
|
102
103
|
if (totalProblems - ignoredProblems > maxProblems) {
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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 ?
|
|
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,12 +163,12 @@ 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 ${
|
|
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];
|
|
169
170
|
if (!SEVERITY_NAMES[problem.severity]) {
|
|
170
|
-
return 'Error not found severity. Please check your config file. Allowed values:
|
|
171
|
+
return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
|
|
171
172
|
}
|
|
172
173
|
const severityName = color(SEVERITY_NAMES[problem.severity].toLowerCase().padEnd(7));
|
|
173
174
|
const { start } = problem.location[0];
|
|
@@ -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
|
-
|
|
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 ${
|
|
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,
|
|
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.
|
|
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");
|
|
@@ -19,7 +20,7 @@ var stats_1 = require("./rules/other/stats");
|
|
|
19
20
|
Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return stats_1.Stats; } });
|
|
20
21
|
var config_1 = require("./config");
|
|
21
22
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
+
Object.defineProperty(exports, "StyleguideConfig", { enumerable: true, get: function () { return config_1.StyleguideConfig; } });
|
|
23
24
|
Object.defineProperty(exports, "IGNORE_FILE", { enumerable: true, get: function () { return config_1.IGNORE_FILE; } });
|
|
24
25
|
Object.defineProperty(exports, "getMergedConfig", { enumerable: true, get: function () { return config_1.getMergedConfig; } });
|
|
25
26
|
Object.defineProperty(exports, "transformConfig", { enumerable: true, get: function () { return config_1.transformConfig; } });
|
|
@@ -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,16 +2,12 @@
|
|
|
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({
|
|
8
9
|
implicit: [js_yaml_1.types.merge],
|
|
9
|
-
explicit: [
|
|
10
|
-
js_yaml_1.types.binary,
|
|
11
|
-
js_yaml_1.types.omap,
|
|
12
|
-
js_yaml_1.types.pairs,
|
|
13
|
-
js_yaml_1.types.set,
|
|
14
|
-
],
|
|
10
|
+
explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
|
|
15
11
|
});
|
|
16
12
|
const parseYaml = (str, opts) => js_yaml_1.load(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
|
|
17
13
|
exports.parseYaml = parseYaml;
|
package/lib/lint.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseResolver, Document } from './resolve';
|
|
2
2
|
import { NodeType } from './types';
|
|
3
3
|
import { ProblemSeverity } from './walk';
|
|
4
|
-
import {
|
|
4
|
+
import { StyleguideConfig, Config } from './config';
|
|
5
5
|
export declare function lint(opts: {
|
|
6
6
|
ref: string;
|
|
7
7
|
config: Config;
|
|
@@ -15,7 +15,7 @@ export declare function lintFromString(opts: {
|
|
|
15
15
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
|
16
16
|
export declare function lintDocument(opts: {
|
|
17
17
|
document: Document;
|
|
18
|
-
config:
|
|
18
|
+
config: StyleguideConfig;
|
|
19
19
|
customTypes?: Record<string, NodeType>;
|
|
20
20
|
externalRefResolver: BaseResolver;
|
|
21
21
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
package/lib/lint.js
CHANGED
|
@@ -26,7 +26,7 @@ function lint(opts) {
|
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
28
28
|
const document = (yield externalRefResolver.resolveDocument(null, ref, true));
|
|
29
|
-
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.
|
|
29
|
+
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
exports.lint = lint;
|
|
@@ -34,7 +34,7 @@ function lintFromString(opts) {
|
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
36
36
|
const document = resolve_1.makeDocumentFromString(source, absoluteRef || '/');
|
|
37
|
-
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.
|
|
37
|
+
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
exports.lintFromString = lintFromString;
|
|
@@ -45,7 +45,11 @@ function lintDocument(opts) {
|
|
|
45
45
|
const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
|
|
46
46
|
const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
|
|
47
47
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
48
|
-
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
48
|
+
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
49
|
+
? oasVersion === oas_types_1.OasVersion.Version3_1
|
|
50
|
+
? oas3_1_1.Oas3_1Types
|
|
51
|
+
: oas3_1.Oas3Types
|
|
52
|
+
: oas2_1.Oas2Types, oasVersion), config);
|
|
49
53
|
const ctx = {
|
|
50
54
|
problems: [],
|
|
51
55
|
oasVersion: oasVersion,
|
|
@@ -57,7 +61,7 @@ function lintDocument(opts) {
|
|
|
57
61
|
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
58
62
|
rootDocument: document,
|
|
59
63
|
rootType: types.DefinitionRoot,
|
|
60
|
-
externalRefResolver
|
|
64
|
+
externalRefResolver,
|
|
61
65
|
});
|
|
62
66
|
walk_1.walkDocument({
|
|
63
67
|
document,
|
|
@@ -79,12 +83,18 @@ function lintConfig(opts) {
|
|
|
79
83
|
visitorsData: {},
|
|
80
84
|
};
|
|
81
85
|
const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
|
|
82
|
-
const config = new config_1.
|
|
86
|
+
const config = new config_1.StyleguideConfig({
|
|
83
87
|
plugins,
|
|
84
88
|
rules: { spec: 'error' },
|
|
85
89
|
});
|
|
86
90
|
const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
|
|
87
|
-
const rules = [
|
|
91
|
+
const rules = [
|
|
92
|
+
{
|
|
93
|
+
severity: severity || 'error',
|
|
94
|
+
ruleId: 'configuration spec',
|
|
95
|
+
visitor: spec_1.OasSpec({ severity: 'error' }),
|
|
96
|
+
},
|
|
97
|
+
];
|
|
88
98
|
const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
|
|
89
99
|
walk_1.walkDocument({
|
|
90
100
|
document,
|
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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
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, }:
|
|
16
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }:
|
|
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 || {}, {
|
|
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
|
}
|
|
@@ -80,7 +85,7 @@ class RegistryApi {
|
|
|
80
85
|
throw new Error('Could not prepare file upload');
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }) {
|
|
88
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }) {
|
|
84
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
90
|
const response = yield this.request(`/${organizationId}/${name}/${version}`, {
|
|
86
91
|
method: 'PUT',
|
|
@@ -95,7 +100,7 @@ class RegistryApi {
|
|
|
95
100
|
isUpsert,
|
|
96
101
|
isPublic,
|
|
97
102
|
batchId,
|
|
98
|
-
batchSize
|
|
103
|
+
batchSize,
|
|
99
104
|
}),
|
|
100
105
|
}, this.region);
|
|
101
106
|
if (response.ok) {
|
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
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[];
|