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