@redocly/openapi-core 1.0.0-beta.68 → 1.0.0-beta.69
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/bundle.d.ts +4 -0
- package/lib/bundle.js +9 -3
- package/lib/lint.js +2 -0
- package/lib/redocly/index.d.ts +3 -14
- package/lib/redocly/index.js +19 -186
- package/lib/redocly/registry-api-types.d.ts +28 -0
- package/lib/redocly/registry-api-types.js +2 -0
- package/lib/redocly/registry-api.d.ts +11 -0
- package/lib/redocly/registry-api.js +94 -0
- package/lib/rules/common/registry-dependencies.js +4 -7
- package/lib/walk.d.ts +2 -0
- package/lib/walk.js +7 -0
- package/package.json +2 -2
- package/src/bundle.ts +25 -3
- package/src/lint.ts +2 -0
- package/src/redocly/index.ts +17 -194
- package/src/redocly/registry-api-types.ts +31 -0
- package/src/redocly/registry-api.ts +106 -0
- package/src/rules/common/registry-dependencies.ts +6 -8
- package/src/walk.ts +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/redocly/query.d.ts +0 -4
- package/lib/redocly/query.js +0 -44
- package/src/redocly/query.ts +0 -38
package/lib/bundle.d.ts
CHANGED
|
@@ -15,12 +15,14 @@ export declare function bundle(opts: {
|
|
|
15
15
|
config: Config;
|
|
16
16
|
dereference?: boolean;
|
|
17
17
|
base?: string;
|
|
18
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
18
19
|
}): Promise<{
|
|
19
20
|
bundle: Document;
|
|
20
21
|
problems: import("./walk").NormalizedProblem[];
|
|
21
22
|
fileDependencies: Set<string>;
|
|
22
23
|
rootType: NormalizedNodeType;
|
|
23
24
|
refTypes: Map<string, NormalizedNodeType> | undefined;
|
|
25
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
24
26
|
}>;
|
|
25
27
|
export declare function bundleDocument(opts: {
|
|
26
28
|
document: Document;
|
|
@@ -28,10 +30,12 @@ export declare function bundleDocument(opts: {
|
|
|
28
30
|
customTypes?: Record<string, NodeType>;
|
|
29
31
|
externalRefResolver: BaseResolver;
|
|
30
32
|
dereference?: boolean;
|
|
33
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
31
34
|
}): Promise<{
|
|
32
35
|
bundle: Document;
|
|
33
36
|
problems: import("./walk").NormalizedProblem[];
|
|
34
37
|
fileDependencies: Set<string>;
|
|
35
38
|
rootType: NormalizedNodeType;
|
|
36
39
|
refTypes: Map<string, NormalizedNodeType> | undefined;
|
|
40
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
37
41
|
}>;
|
package/lib/bundle.js
CHANGED
|
@@ -23,6 +23,7 @@ const ref_utils_1 = require("./ref-utils");
|
|
|
23
23
|
const rules_1 = require("./config/rules");
|
|
24
24
|
const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
|
|
25
25
|
const utils_1 = require("./utils");
|
|
26
|
+
const redocly_1 = require("./redocly");
|
|
26
27
|
var OasVersion;
|
|
27
28
|
(function (OasVersion) {
|
|
28
29
|
OasVersion["Version2"] = "oas2";
|
|
@@ -45,7 +46,7 @@ function bundle(opts) {
|
|
|
45
46
|
exports.bundle = bundle;
|
|
46
47
|
function bundleDocument(opts) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const { document, config, customTypes, externalRefResolver, dereference = false } = opts;
|
|
49
|
+
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, } = opts;
|
|
49
50
|
const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
|
|
50
51
|
const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
|
|
51
52
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
@@ -60,13 +61,14 @@ function bundleDocument(opts) {
|
|
|
60
61
|
problems: [],
|
|
61
62
|
oasVersion: oasVersion,
|
|
62
63
|
refTypes: new Map(),
|
|
64
|
+
visitorsData: {},
|
|
63
65
|
};
|
|
64
66
|
const bundleVisitor = visitors_1.normalizeVisitors([
|
|
65
67
|
...preprocessors,
|
|
66
68
|
{
|
|
67
69
|
severity: 'error',
|
|
68
70
|
ruleId: 'bundler',
|
|
69
|
-
visitor: makeBundleVisitor(oasMajorVersion, dereference, document),
|
|
71
|
+
visitor: makeBundleVisitor(oasMajorVersion, dereference, skipRedoclyRegistryRefs, document),
|
|
70
72
|
},
|
|
71
73
|
...decorators,
|
|
72
74
|
], types);
|
|
@@ -88,6 +90,7 @@ function bundleDocument(opts) {
|
|
|
88
90
|
fileDependencies: externalRefResolver.getFiles(),
|
|
89
91
|
rootType: types.DefinitionRoot,
|
|
90
92
|
refTypes: ctx.refTypes,
|
|
93
|
+
visitorsData: ctx.visitorsData,
|
|
91
94
|
};
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -131,7 +134,7 @@ function mapTypeToComponent(typeName, version) {
|
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
// function oas3Move
|
|
134
|
-
function makeBundleVisitor(version, dereference, rootDocument) {
|
|
137
|
+
function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDocument) {
|
|
135
138
|
let components;
|
|
136
139
|
const visitor = {
|
|
137
140
|
ref: {
|
|
@@ -146,6 +149,9 @@ function makeBundleVisitor(version, dereference, rootDocument) {
|
|
|
146
149
|
!dereference) {
|
|
147
150
|
return;
|
|
148
151
|
}
|
|
152
|
+
if (skipRedoclyRegistryRefs && redocly_1.isRedoclyRegistryURL(node.$ref)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
149
155
|
const componentType = mapTypeToComponent(ctx.type.name, version);
|
|
150
156
|
if (!componentType) {
|
|
151
157
|
replaceRef(node, resolved, ctx);
|
package/lib/lint.js
CHANGED
|
@@ -51,6 +51,7 @@ function lintDocument(opts) {
|
|
|
51
51
|
const ctx = {
|
|
52
52
|
problems: [],
|
|
53
53
|
oasVersion: oasVersion,
|
|
54
|
+
visitorsData: {},
|
|
54
55
|
};
|
|
55
56
|
const preprocessors = rules_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
56
57
|
const regularRules = rules_1.initRules(rules, config, 'rules', oasVersion);
|
|
@@ -77,6 +78,7 @@ function lintConfig(opts) {
|
|
|
77
78
|
const ctx = {
|
|
78
79
|
problems: [],
|
|
79
80
|
oasVersion: oas_types_1.OasVersion.Version3_0,
|
|
81
|
+
visitorsData: {},
|
|
80
82
|
};
|
|
81
83
|
const config = new config_1.LintConfig({
|
|
82
84
|
plugins: [builtIn_1.defaultPlugin],
|
package/lib/redocly/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { RegistryApi } from './registry-api';
|
|
1
2
|
export declare class RedoclyClient {
|
|
2
3
|
private accessToken;
|
|
4
|
+
registryApi: RegistryApi;
|
|
3
5
|
constructor();
|
|
4
6
|
hasToken(): boolean;
|
|
5
7
|
loadToken(): void;
|
|
@@ -8,18 +10,5 @@ export declare class RedoclyClient {
|
|
|
8
10
|
getAuthorizationHeader(): Promise<string | undefined>;
|
|
9
11
|
login(accessToken: string, verbose?: boolean): Promise<void>;
|
|
10
12
|
logout(): void;
|
|
11
|
-
query(queryString: string, parameters?: {}, headers?: {}): Promise<any>;
|
|
12
|
-
static authorize(accessToken: string, options: {
|
|
13
|
-
queryName?: string;
|
|
14
|
-
verbose?: boolean;
|
|
15
|
-
}): Promise<any>;
|
|
16
|
-
updateDependencies(dependencies: string[] | undefined): Promise<void>;
|
|
17
|
-
updateDefinitionVersion(definitionId: number, versionId: number, updatePatch: object): Promise<void>;
|
|
18
|
-
getOrganizationId(organizationId: string): Promise<any>;
|
|
19
|
-
getDefinitionByName(name: string, organizationId: string): Promise<any>;
|
|
20
|
-
createDefinition(organizationId: string, name: string): Promise<any>;
|
|
21
|
-
createDefinitionVersion(definitionId: string, name: string, sourceType: string, source: any): Promise<any>;
|
|
22
|
-
getSignedUrl(organizationId: string, filesHash: string, fileName: string): Promise<any>;
|
|
23
|
-
getDefinitionVersion(organizationId: string, definitionName: string, versionName: string): Promise<any>;
|
|
24
|
-
static isRegistryURL(link: string): boolean;
|
|
25
13
|
}
|
|
14
|
+
export declare function isRedoclyRegistryURL(link: string): boolean;
|
package/lib/redocly/index.js
CHANGED
|
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RedoclyClient = void 0;
|
|
12
|
+
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
16
|
const colorette_1 = require("colorette");
|
|
17
|
-
const
|
|
17
|
+
const registry_api_1 = require("./registry-api");
|
|
18
18
|
const TOKEN_FILENAME = '.redocly-config.json';
|
|
19
19
|
class RedoclyClient {
|
|
20
20
|
constructor() {
|
|
21
21
|
this.loadToken();
|
|
22
|
+
this.registryApi = new registry_api_1.RegistryApi(this.accessToken);
|
|
22
23
|
}
|
|
23
24
|
hasToken() {
|
|
24
25
|
return !!this.accessToken;
|
|
@@ -43,10 +44,7 @@ class RedoclyClient {
|
|
|
43
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
45
|
if (!accessToken)
|
|
45
46
|
return false;
|
|
46
|
-
|
|
47
|
-
if (!authDetails)
|
|
48
|
-
return false;
|
|
49
|
-
return true;
|
|
47
|
+
return this.registryApi.setAccessToken(accessToken).authStatus(verbose);
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
50
|
getAuthorizationHeader() {
|
|
@@ -83,185 +81,20 @@ class RedoclyClient {
|
|
|
83
81
|
}
|
|
84
82
|
process.stdout.write('Logged out from the Redocly account. ✋\n');
|
|
85
83
|
}
|
|
86
|
-
query(queryString, parameters = {}, headers = {}) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
return query_1.query(queryString, parameters, Object.assign({ Authorization: this.accessToken }, headers));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
static authorize(accessToken, options) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const { queryName = '', verbose = false } = options;
|
|
94
|
-
try {
|
|
95
|
-
const queryStr = `query ${queryName}{ viewer { id } }`;
|
|
96
|
-
return yield query_1.query(queryStr, {}, { Authorization: accessToken });
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
if (verbose)
|
|
100
|
-
console.log(e);
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
updateDependencies(dependencies) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
const definitionId = process.env.DEFINITION;
|
|
108
|
-
const versionId = process.env.DEFINITION;
|
|
109
|
-
const branchId = process.env.BRANCH;
|
|
110
|
-
if (!definitionId || !versionId || !branchId)
|
|
111
|
-
return;
|
|
112
|
-
yield this.query(`
|
|
113
|
-
mutation UpdateBranchDependenciesFromURLs(
|
|
114
|
-
$urls: [String!]!
|
|
115
|
-
$definitionId: Int!
|
|
116
|
-
$versionId: Int!
|
|
117
|
-
$branchId: Int!
|
|
118
|
-
) {
|
|
119
|
-
updateBranchDependenciesFromURLs(
|
|
120
|
-
definitionId: $definitionId
|
|
121
|
-
versionId: $versionId
|
|
122
|
-
branchId: $branchId
|
|
123
|
-
urls: $urls
|
|
124
|
-
) {
|
|
125
|
-
branchName
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
`, {
|
|
129
|
-
urls: dependencies || [],
|
|
130
|
-
definitionId: parseInt(definitionId, 10),
|
|
131
|
-
versionId: parseInt(versionId, 10),
|
|
132
|
-
branchId: parseInt(branchId, 10),
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
updateDefinitionVersion(definitionId, versionId, updatePatch) {
|
|
137
|
-
return this.query(`
|
|
138
|
-
mutation UpdateDefinitionVersion($definitionId: Int!, $versionId: Int!, $updatePatch: DefinitionVersionPatch!) {
|
|
139
|
-
updateDefinitionVersionByDefinitionIdAndId(input: {definitionId: $definitionId, id: $versionId, patch: $updatePatch}) {
|
|
140
|
-
definitionVersion {
|
|
141
|
-
...VersionDetails
|
|
142
|
-
__typename
|
|
143
|
-
}
|
|
144
|
-
__typename
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
fragment VersionDetails on DefinitionVersion {
|
|
149
|
-
id
|
|
150
|
-
nodeId
|
|
151
|
-
uuid
|
|
152
|
-
definitionId
|
|
153
|
-
name
|
|
154
|
-
description
|
|
155
|
-
sourceType
|
|
156
|
-
source
|
|
157
|
-
registryAccess
|
|
158
|
-
__typename
|
|
159
|
-
}
|
|
160
|
-
`, {
|
|
161
|
-
definitionId,
|
|
162
|
-
versionId,
|
|
163
|
-
updatePatch,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
getOrganizationId(organizationId) {
|
|
167
|
-
return this.query(`
|
|
168
|
-
query ($organizationId: String!) {
|
|
169
|
-
organizationById(id: $organizationId) {
|
|
170
|
-
id
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
`, {
|
|
174
|
-
organizationId
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
getDefinitionByName(name, organizationId) {
|
|
178
|
-
return this.query(`
|
|
179
|
-
query ($name: String!, $organizationId: String!) {
|
|
180
|
-
definition: definitionByOrganizationIdAndName(name: $name, organizationId: $organizationId) {
|
|
181
|
-
id
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
`, {
|
|
185
|
-
name,
|
|
186
|
-
organizationId
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
createDefinition(organizationId, name) {
|
|
190
|
-
return this.query(`
|
|
191
|
-
mutation CreateDefinition($organizationId: String!, $name: String!) {
|
|
192
|
-
def: createDefinition(input: {organizationId: $organizationId, name: $name }) {
|
|
193
|
-
definition {
|
|
194
|
-
id
|
|
195
|
-
nodeId
|
|
196
|
-
name
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
`, {
|
|
201
|
-
organizationId,
|
|
202
|
-
name
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
createDefinitionVersion(definitionId, name, sourceType, source) {
|
|
206
|
-
return this.query(`
|
|
207
|
-
mutation CreateVersion($definitionId: Int!, $name: String!, $sourceType: DvSourceType!, $source: JSON) {
|
|
208
|
-
createDefinitionVersion(input: {definitionId: $definitionId, name: $name, sourceType: $sourceType, source: $source }) {
|
|
209
|
-
definitionVersion {
|
|
210
|
-
id
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
`, {
|
|
215
|
-
definitionId,
|
|
216
|
-
name,
|
|
217
|
-
sourceType,
|
|
218
|
-
source
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
getSignedUrl(organizationId, filesHash, fileName) {
|
|
222
|
-
return this.query(`
|
|
223
|
-
query ($organizationId: String!, $filesHash: String!, $fileName: String!) {
|
|
224
|
-
signFileUploadCLI(organizationId: $organizationId, filesHash: $filesHash, fileName: $fileName) {
|
|
225
|
-
signedFileUrl
|
|
226
|
-
uploadedFilePath
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
`, {
|
|
230
|
-
organizationId,
|
|
231
|
-
filesHash,
|
|
232
|
-
fileName
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
getDefinitionVersion(organizationId, definitionName, versionName) {
|
|
236
|
-
return this.query(`
|
|
237
|
-
query ($organizationId: String!, $definitionName: String!, $versionName: String!) {
|
|
238
|
-
version: definitionVersionByOrganizationDefinitionAndName(organizationId: $organizationId, definitionName: $definitionName, versionName: $versionName) {
|
|
239
|
-
id
|
|
240
|
-
definitionId
|
|
241
|
-
defaultBranch {
|
|
242
|
-
name
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
`, {
|
|
247
|
-
organizationId,
|
|
248
|
-
definitionName,
|
|
249
|
-
versionName
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
static isRegistryURL(link) {
|
|
253
|
-
const domain = process.env.REDOCLY_DOMAIN || 'redoc.ly';
|
|
254
|
-
if (!link.startsWith(`https://api.${domain}/registry/`))
|
|
255
|
-
return false;
|
|
256
|
-
const registryPath = link.replace(`https://api.${domain}/registry/`, '');
|
|
257
|
-
const pathParts = registryPath.split('/');
|
|
258
|
-
// we can be sure, that there is job UUID present
|
|
259
|
-
// (org, definition, version, bundle, branch, job, "openapi.yaml" 🤦♂️)
|
|
260
|
-
// so skip this link.
|
|
261
|
-
// FIXME
|
|
262
|
-
if (pathParts.length === 7)
|
|
263
|
-
return false;
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
84
|
}
|
|
267
85
|
exports.RedoclyClient = RedoclyClient;
|
|
86
|
+
function isRedoclyRegistryURL(link) {
|
|
87
|
+
const domain = process.env.REDOCLY_DOMAIN || 'redoc.ly';
|
|
88
|
+
if (!link.startsWith(`https://api.${domain}/registry/`))
|
|
89
|
+
return false;
|
|
90
|
+
const registryPath = link.replace(`https://api.${domain}/registry/`, '');
|
|
91
|
+
const pathParts = registryPath.split('/');
|
|
92
|
+
// we can be sure, that there is job UUID present
|
|
93
|
+
// (org, definition, version, bundle, branch, job, "openapi.yaml" 🤦♂️)
|
|
94
|
+
// so skip this link.
|
|
95
|
+
// FIXME
|
|
96
|
+
if (pathParts.length === 7)
|
|
97
|
+
return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare namespace RegistryApiTypes {
|
|
2
|
+
interface VersionParams {
|
|
3
|
+
organizationId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PrepareFileuploadParams extends VersionParams {
|
|
8
|
+
filesHash: string;
|
|
9
|
+
filename: string;
|
|
10
|
+
isUpsert?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PushApiParams extends VersionParams {
|
|
13
|
+
rootFilePath: string;
|
|
14
|
+
filePaths: string[];
|
|
15
|
+
branch?: string;
|
|
16
|
+
isUpsert?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface PrepareFileuploadOKResponse {
|
|
19
|
+
filePath: string;
|
|
20
|
+
signedUploadUrl: string;
|
|
21
|
+
}
|
|
22
|
+
export interface NotFoundProblemResponse {
|
|
23
|
+
status: 404;
|
|
24
|
+
title: 'Not Found';
|
|
25
|
+
code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RegistryApiTypes } from './registry-api-types';
|
|
2
|
+
export declare class RegistryApi {
|
|
3
|
+
private accessToken?;
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
constructor(accessToken?: string | undefined);
|
|
6
|
+
private request;
|
|
7
|
+
setAccessToken(accessToken: string): this;
|
|
8
|
+
authStatus(verbose?: boolean): Promise<boolean>;
|
|
9
|
+
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>;
|
|
10
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, }: RegistryApiTypes.PushApiParams): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RegistryApi = void 0;
|
|
13
|
+
const node_fetch_1 = require("node-fetch");
|
|
14
|
+
const version = require('../../package.json').version;
|
|
15
|
+
class RegistryApi {
|
|
16
|
+
constructor(accessToken) {
|
|
17
|
+
this.accessToken = accessToken;
|
|
18
|
+
this.baseUrl = `https://api.${process.env.REDOCLY_DOMAIN || 'redoc.ly'}/registry`;
|
|
19
|
+
}
|
|
20
|
+
request(path = '', options = {}) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (!this.accessToken) {
|
|
23
|
+
throw new Error('Unauthorized');
|
|
24
|
+
}
|
|
25
|
+
const headers = Object.assign({}, options.headers || {}, {
|
|
26
|
+
authorization: this.accessToken,
|
|
27
|
+
'x-redocly-cli-version': version,
|
|
28
|
+
});
|
|
29
|
+
const response = yield node_fetch_1.default(`${this.baseUrl}${path}`, Object.assign({}, options, { headers }));
|
|
30
|
+
if (response.status === 401) {
|
|
31
|
+
throw new Error('Unauthorized');
|
|
32
|
+
}
|
|
33
|
+
if (response.status === 404) {
|
|
34
|
+
const body = yield response.json();
|
|
35
|
+
throw new Error(body.code);
|
|
36
|
+
}
|
|
37
|
+
return response;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
setAccessToken(accessToken) {
|
|
41
|
+
this.accessToken = accessToken;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
authStatus(verbose = false) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
const response = yield this.request();
|
|
48
|
+
return response.ok;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (verbose) {
|
|
52
|
+
console.log(error);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const response = yield this.request(`/${organizationId}/${name}/${version}/prepare-file-upload`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'content-type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
filesHash,
|
|
65
|
+
filename,
|
|
66
|
+
isUpsert,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
if (response.ok) {
|
|
70
|
+
return response.json();
|
|
71
|
+
}
|
|
72
|
+
throw new Error('Could not prepare file upload');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, }) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const response = yield this.request(`/${organizationId}/${name}/${version}`, {
|
|
78
|
+
method: 'PUT',
|
|
79
|
+
headers: { 'content-type': 'application/json' },
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
rootFilePath,
|
|
82
|
+
filePaths,
|
|
83
|
+
branch,
|
|
84
|
+
isUpsert,
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
if (response.ok) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
throw new Error('Could not push api');
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.RegistryApi = RegistryApi;
|
|
@@ -3,21 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RegistryDependencies = void 0;
|
|
4
4
|
const redocly_1 = require("../../redocly");
|
|
5
5
|
const RegistryDependencies = () => {
|
|
6
|
-
let redoclyClient;
|
|
7
6
|
let registryDependencies = new Set();
|
|
8
7
|
return {
|
|
9
8
|
DefinitionRoot: {
|
|
10
|
-
leave() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
redoclyClient.updateDependencies(Array.from(registryDependencies.keys()));
|
|
14
|
-
}
|
|
9
|
+
leave(_, ctx) {
|
|
10
|
+
const data = ctx.getVisitorData();
|
|
11
|
+
data.links = Array.from(registryDependencies);
|
|
15
12
|
},
|
|
16
13
|
},
|
|
17
14
|
ref(node) {
|
|
18
15
|
if (node.$ref) {
|
|
19
16
|
const link = node.$ref.split('#/')[0];
|
|
20
|
-
if (redocly_1.
|
|
17
|
+
if (redocly_1.isRedoclyRegistryURL(link)) {
|
|
21
18
|
registryDependencies.add(link);
|
|
22
19
|
}
|
|
23
20
|
}
|
package/lib/walk.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare type UserContext = {
|
|
|
36
36
|
key: string | number;
|
|
37
37
|
parent: any;
|
|
38
38
|
oasVersion: OasVersion;
|
|
39
|
+
getVisitorData: () => Record<string, unknown>;
|
|
39
40
|
};
|
|
40
41
|
export declare type Loc = {
|
|
41
42
|
line: number;
|
|
@@ -72,6 +73,7 @@ export declare type NormalizedProblem = {
|
|
|
72
73
|
export declare type WalkContext = {
|
|
73
74
|
problems: NormalizedProblem[];
|
|
74
75
|
oasVersion: OasVersion;
|
|
76
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
75
77
|
refTypes?: Map<string, NormalizedNodeType>;
|
|
76
78
|
};
|
|
77
79
|
export declare function walkDocument<T>(opts: {
|
package/lib/walk.js
CHANGED
|
@@ -50,6 +50,7 @@ function walkDocument(opts) {
|
|
|
50
50
|
key,
|
|
51
51
|
parentLocations: {},
|
|
52
52
|
oasVersion: ctx.oasVersion,
|
|
53
|
+
getVisitorData: getVisitorDataFn.bind(undefined, ruleId)
|
|
53
54
|
}, { node: resolvedNode, location: resolvedLocation, error });
|
|
54
55
|
if ((resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef) && ctx.refTypes) {
|
|
55
56
|
ctx.refTypes.set(resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef, type);
|
|
@@ -192,6 +193,7 @@ function walkDocument(opts) {
|
|
|
192
193
|
key,
|
|
193
194
|
parentLocations: {},
|
|
194
195
|
oasVersion: ctx.oasVersion,
|
|
196
|
+
getVisitorData: getVisitorDataFn.bind(undefined, ruleId)
|
|
195
197
|
}, { node: resolvedNode, location: resolvedLocation, error });
|
|
196
198
|
}
|
|
197
199
|
}
|
|
@@ -212,6 +214,7 @@ function walkDocument(opts) {
|
|
|
212
214
|
ignoreNextVisitorsOnNode: () => {
|
|
213
215
|
ignoreNextVisitorsOnNode = true;
|
|
214
216
|
},
|
|
217
|
+
getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
|
|
215
218
|
}, collectParents(context), context);
|
|
216
219
|
return ignoreNextVisitorsOnNode;
|
|
217
220
|
}
|
|
@@ -244,6 +247,10 @@ function walkDocument(opts) {
|
|
|
244
247
|
return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
|
|
245
248
|
}) }));
|
|
246
249
|
}
|
|
250
|
+
function getVisitorDataFn(ruleId) {
|
|
251
|
+
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
|
|
252
|
+
return ctx.visitorsData[ruleId];
|
|
253
|
+
}
|
|
247
254
|
}
|
|
248
255
|
}
|
|
249
256
|
exports.walkDocument = walkDocument;
|
package/package.json
CHANGED
package/src/bundle.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { initRules } from './config/rules';
|
|
|
13
13
|
import { reportUnresolvedRef } from './rules/no-unresolved-refs';
|
|
14
14
|
import { isPlainObject } from './utils';
|
|
15
15
|
import { OasRef } from './typings/openapi';
|
|
16
|
+
import { isRedoclyRegistryURL } from './redocly';
|
|
16
17
|
|
|
17
18
|
export type Oas3RuleSet = Record<string, Oas3Rule>;
|
|
18
19
|
|
|
@@ -29,6 +30,7 @@ export async function bundle(opts: {
|
|
|
29
30
|
config: Config;
|
|
30
31
|
dereference?: boolean;
|
|
31
32
|
base?: string;
|
|
33
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
32
34
|
}) {
|
|
33
35
|
const {
|
|
34
36
|
ref,
|
|
@@ -63,8 +65,16 @@ export async function bundleDocument(opts: {
|
|
|
63
65
|
customTypes?: Record<string, NodeType>;
|
|
64
66
|
externalRefResolver: BaseResolver;
|
|
65
67
|
dereference?: boolean;
|
|
68
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
66
69
|
}) {
|
|
67
|
-
const {
|
|
70
|
+
const {
|
|
71
|
+
document,
|
|
72
|
+
config,
|
|
73
|
+
customTypes,
|
|
74
|
+
externalRefResolver,
|
|
75
|
+
dereference = false,
|
|
76
|
+
skipRedoclyRegistryRefs = false,
|
|
77
|
+
} = opts;
|
|
68
78
|
const oasVersion = detectOpenAPI(document.parsed);
|
|
69
79
|
const oasMajorVersion = openAPIMajor(oasVersion);
|
|
70
80
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
@@ -86,6 +96,7 @@ export async function bundleDocument(opts: {
|
|
|
86
96
|
problems: [],
|
|
87
97
|
oasVersion: oasVersion,
|
|
88
98
|
refTypes: new Map<string, NormalizedNodeType>(),
|
|
99
|
+
visitorsData: {},
|
|
89
100
|
};
|
|
90
101
|
|
|
91
102
|
const bundleVisitor = normalizeVisitors(
|
|
@@ -94,7 +105,7 @@ export async function bundleDocument(opts: {
|
|
|
94
105
|
{
|
|
95
106
|
severity: 'error',
|
|
96
107
|
ruleId: 'bundler',
|
|
97
|
-
visitor: makeBundleVisitor(oasMajorVersion, dereference, document),
|
|
108
|
+
visitor: makeBundleVisitor(oasMajorVersion, dereference, skipRedoclyRegistryRefs, document),
|
|
98
109
|
},
|
|
99
110
|
...decorators,
|
|
100
111
|
],
|
|
@@ -121,6 +132,7 @@ export async function bundleDocument(opts: {
|
|
|
121
132
|
fileDependencies: externalRefResolver.getFiles(),
|
|
122
133
|
rootType: types.DefinitionRoot,
|
|
123
134
|
refTypes: ctx.refTypes,
|
|
135
|
+
visitorsData: ctx.visitorsData,
|
|
124
136
|
};
|
|
125
137
|
}
|
|
126
138
|
|
|
@@ -165,7 +177,12 @@ function mapTypeToComponent(typeName: string, version: OasMajorVersion) {
|
|
|
165
177
|
|
|
166
178
|
// function oas3Move
|
|
167
179
|
|
|
168
|
-
function makeBundleVisitor(
|
|
180
|
+
function makeBundleVisitor(
|
|
181
|
+
version: OasMajorVersion,
|
|
182
|
+
dereference: boolean,
|
|
183
|
+
skipRedoclyRegistryRefs: boolean,
|
|
184
|
+
rootDocument: Document,
|
|
185
|
+
) {
|
|
169
186
|
let components: Record<string, Record<string, any>>;
|
|
170
187
|
|
|
171
188
|
const visitor: Oas3Visitor | Oas2Visitor = {
|
|
@@ -183,6 +200,11 @@ function makeBundleVisitor(version: OasMajorVersion, dereference: boolean, rootD
|
|
|
183
200
|
) {
|
|
184
201
|
return;
|
|
185
202
|
}
|
|
203
|
+
|
|
204
|
+
if (skipRedoclyRegistryRefs && isRedoclyRegistryURL(node.$ref)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
186
208
|
const componentType = mapTypeToComponent(ctx.type.name, version);
|
|
187
209
|
if (!componentType) {
|
|
188
210
|
replaceRef(node, resolved, ctx);
|