oas 36.0.2 → 37.0.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/README.md +0 -5
- package/dist/analyzer/index.cjs +83 -28
- package/dist/analyzer/index.cjs.map +1 -1
- package/dist/analyzer/index.d.cts +3 -10
- package/dist/analyzer/index.d.ts +3 -10
- package/dist/analyzer/index.js +81 -26
- package/dist/analyzer/index.js.map +1 -1
- package/dist/analyzer/types.d.cts +0 -1
- package/dist/analyzer/types.d.ts +0 -1
- package/dist/{chunk-UDN4U5TL.cjs → chunk-GS43VKJH.cjs} +320 -274
- package/dist/chunk-GS43VKJH.cjs.map +1 -0
- package/dist/{chunk-6MDVLJ3A.js → chunk-IEN4GZPF.js} +9 -23
- package/dist/chunk-IEN4GZPF.js.map +1 -0
- package/dist/{chunk-SCWW2SNX.cjs → chunk-UKD63LKG.cjs} +10 -24
- package/dist/chunk-UKD63LKG.cjs.map +1 -0
- package/dist/{chunk-35LEYZEY.js → chunk-WIVQX3DA.js} +199 -153
- package/dist/chunk-WIVQX3DA.js.map +1 -0
- package/dist/index.cjs +634 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -135
- package/dist/index.d.ts +38 -135
- package/dist/index.js +633 -6
- package/dist/index.js.map +1 -1
- package/dist/operation/index.cjs +3 -3
- package/dist/operation/index.js +2 -2
- package/dist/reducer/index.cjs +7 -7
- package/dist/reducer/index.js +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/package.json +1 -4
- package/dist/chunk-35LEYZEY.js.map +0 -1
- package/dist/chunk-6MDVLJ3A.js.map +0 -1
- package/dist/chunk-IXQKQM3K.js +0 -866
- package/dist/chunk-IXQKQM3K.js.map +0 -1
- package/dist/chunk-SCWW2SNX.cjs.map +0 -1
- package/dist/chunk-UDN4U5TL.cjs.map +0 -1
- package/dist/chunk-YKV73CBG.cjs +0 -866
- package/dist/chunk-YKV73CBG.cjs.map +0 -1
package/dist/chunk-YKV73CBG.cjs
DELETED
|
@@ -1,866 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkUDN4U5TLcjs = require('./chunk-UDN4U5TL.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunkSCWW2SNXcjs = require('./chunk-SCWW2SNX.cjs');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var _chunkAYA3UT4Lcjs = require('./chunk-AYA3UT4L.cjs');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var _chunk7PWF3F2Wcjs = require('./chunk-7PWF3F2W.cjs');
|
|
27
|
-
|
|
28
|
-
// src/index.ts
|
|
29
|
-
var _openapiparser = require('@readme/openapi-parser');
|
|
30
|
-
|
|
31
|
-
// src/lib/get-auth.ts
|
|
32
|
-
function getPrimitiveDefaultAuth(scheme) {
|
|
33
|
-
return typeof scheme["x-default"] === "number" || typeof scheme["x-default"] === "string" ? scheme["x-default"] : null;
|
|
34
|
-
}
|
|
35
|
-
function getKey(user, scheme) {
|
|
36
|
-
switch (scheme.type) {
|
|
37
|
-
case "oauth2":
|
|
38
|
-
return user[scheme._key] || user.apiKey || getPrimitiveDefaultAuth(scheme) || null;
|
|
39
|
-
case "apiKey":
|
|
40
|
-
return user[scheme._key] || user.apiKey || scheme["x-default"] || null;
|
|
41
|
-
case "http":
|
|
42
|
-
if (scheme.scheme === "basic") {
|
|
43
|
-
return user[scheme._key] || (user.user || user.pass ? { user: user.user || null, pass: user.pass || null } : scheme["x-default"]) || {
|
|
44
|
-
user: null,
|
|
45
|
-
pass: null
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (scheme.scheme === "bearer") {
|
|
49
|
-
return user[scheme._key] || user.apiKey || scheme["x-default"] || null;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
default:
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function getByScheme(user, scheme = {}, selectedApp) {
|
|
57
|
-
if (_optionalChain([user, 'optionalAccess', _ => _.keys, 'optionalAccess', _2 => _2.length])) {
|
|
58
|
-
if (selectedApp) {
|
|
59
|
-
const userKey = user.keys.find((k) => k.name === selectedApp);
|
|
60
|
-
if (!userKey) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return getKey(userKey, scheme);
|
|
64
|
-
}
|
|
65
|
-
return getKey(user.keys[0], scheme);
|
|
66
|
-
}
|
|
67
|
-
return getKey(user, scheme);
|
|
68
|
-
}
|
|
69
|
-
function getAuth(api, user, selectedApp) {
|
|
70
|
-
return Object.keys(_optionalChain([api, 'optionalAccess', _3 => _3.components, 'optionalAccess', _4 => _4.securitySchemes]) || {}).map((scheme) => {
|
|
71
|
-
const securityScheme = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, _optionalChain([api, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.securitySchemes, 'optionalAccess', _7 => _7[scheme]]), api);
|
|
72
|
-
if (!securityScheme || _chunk7PWF3F2Wcjs.isRef.call(void 0, securityScheme)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
[scheme]: getByScheme(
|
|
77
|
-
user,
|
|
78
|
-
{
|
|
79
|
-
...securityScheme,
|
|
80
|
-
_key: scheme
|
|
81
|
-
},
|
|
82
|
-
selectedApp
|
|
83
|
-
)
|
|
84
|
-
};
|
|
85
|
-
}).filter((item) => item !== void 0).reduce((prev, next) => Object.assign(prev, next), {});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/lib/get-user-variable.ts
|
|
89
|
-
function getUserVariable(user, property, selectedApp) {
|
|
90
|
-
let key = user;
|
|
91
|
-
if ("keys" in user && Array.isArray(user.keys) && user.keys.length) {
|
|
92
|
-
if (selectedApp) {
|
|
93
|
-
key = user.keys.find((k) => k.name === selectedApp);
|
|
94
|
-
} else {
|
|
95
|
-
key = user.keys[0];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return _optionalChain([key, 'optionalAccess', _8 => _8[property]]) || user[property] || null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// src/lib/urls.ts
|
|
102
|
-
var _pathtoregexp = require('path-to-regexp');
|
|
103
|
-
function stripTrailingSlash(url) {
|
|
104
|
-
if (url[url.length - 1] === "/") {
|
|
105
|
-
return url.slice(0, -1);
|
|
106
|
-
}
|
|
107
|
-
return url;
|
|
108
|
-
}
|
|
109
|
-
function ensureProtocol(url) {
|
|
110
|
-
if (url.match(/^\/\//)) {
|
|
111
|
-
return `https:${url}`;
|
|
112
|
-
}
|
|
113
|
-
if (!url.match(/\/\//)) {
|
|
114
|
-
return `https://${url}`;
|
|
115
|
-
}
|
|
116
|
-
return url;
|
|
117
|
-
}
|
|
118
|
-
function normalizedURL(api, selected) {
|
|
119
|
-
const exampleDotCom = "https://example.com";
|
|
120
|
-
let url;
|
|
121
|
-
try {
|
|
122
|
-
url = _optionalChain([api, 'access', _9 => _9.servers, 'optionalAccess', _10 => _10[selected], 'access', _11 => _11.url]);
|
|
123
|
-
if (!url) throw new Error("no url");
|
|
124
|
-
url = stripTrailingSlash(url);
|
|
125
|
-
if (url.startsWith("/") && !url.startsWith("//")) {
|
|
126
|
-
const urlWithOrigin = new URL(exampleDotCom);
|
|
127
|
-
urlWithOrigin.pathname = url;
|
|
128
|
-
url = urlWithOrigin.href;
|
|
129
|
-
}
|
|
130
|
-
} catch (e) {
|
|
131
|
-
url = exampleDotCom;
|
|
132
|
-
}
|
|
133
|
-
return ensureProtocol(url);
|
|
134
|
-
}
|
|
135
|
-
function transformURLIntoRegex(url) {
|
|
136
|
-
return stripTrailingSlash(url.replace(_chunkSCWW2SNXcjs.SERVER_VARIABLE_REGEX, "([-_a-zA-Z0-9:.[\\]]+)"));
|
|
137
|
-
}
|
|
138
|
-
function normalizePath(path) {
|
|
139
|
-
return path.replace(/({?){(.*?)}(}?)/g, (str, ...args) => {
|
|
140
|
-
return `:${args[1].replace("-", "")}`;
|
|
141
|
-
}).replace(/::/, "\\::").split("?")[0];
|
|
142
|
-
}
|
|
143
|
-
function generatePathMatches(paths, pathName, origin) {
|
|
144
|
-
const prunedPathName = pathName.split("?")[0];
|
|
145
|
-
const matches = Object.keys(paths).map((path) => {
|
|
146
|
-
const cleanedPath = normalizePath(path);
|
|
147
|
-
let matchResult;
|
|
148
|
-
try {
|
|
149
|
-
const matchStatement = _pathtoregexp.match.call(void 0, cleanedPath, { decode: decodeURIComponent });
|
|
150
|
-
matchResult = matchStatement(prunedPathName);
|
|
151
|
-
} catch (e2) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
const slugs = {};
|
|
155
|
-
if (matchResult && Object.keys(matchResult.params).length) {
|
|
156
|
-
Object.keys(matchResult.params).forEach((param) => {
|
|
157
|
-
slugs[`:${param}`] = matchResult.params[param];
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
url: {
|
|
162
|
-
origin,
|
|
163
|
-
path: cleanedPath.replace(/\\::/, "::"),
|
|
164
|
-
nonNormalizedPath: path,
|
|
165
|
-
slugs
|
|
166
|
-
},
|
|
167
|
-
operation: paths[path],
|
|
168
|
-
match: matchResult
|
|
169
|
-
};
|
|
170
|
-
}).filter((item) => item !== false);
|
|
171
|
-
return matches.filter((p) => p.match);
|
|
172
|
-
}
|
|
173
|
-
function filterPathMethods(pathMatches, targetMethod) {
|
|
174
|
-
const regExp = _pathtoregexp.pathToRegexp.call(void 0, targetMethod);
|
|
175
|
-
return pathMatches.map((p) => {
|
|
176
|
-
const captures = Object.keys(p.operation).filter((r) => regExp.regexp.exec(r));
|
|
177
|
-
if (captures.length) {
|
|
178
|
-
const method = captures[0];
|
|
179
|
-
p.url.method = method.toUpperCase();
|
|
180
|
-
return {
|
|
181
|
-
url: p.url,
|
|
182
|
-
operation: p.operation[method]
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
}).filter((item) => Boolean(item));
|
|
187
|
-
}
|
|
188
|
-
function findTargetPath(pathMatches) {
|
|
189
|
-
if (!pathMatches.length) {
|
|
190
|
-
return void 0;
|
|
191
|
-
}
|
|
192
|
-
let minCount = Object.keys(pathMatches[0].url.slugs).length;
|
|
193
|
-
let found;
|
|
194
|
-
for (let m = 0; m < pathMatches.length; m += 1) {
|
|
195
|
-
const selection = pathMatches[m];
|
|
196
|
-
const paramCount = Object.keys(selection.url.slugs).length;
|
|
197
|
-
if (paramCount <= minCount) {
|
|
198
|
-
minCount = paramCount;
|
|
199
|
-
found = selection;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return found;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/index.ts
|
|
206
|
-
var Oas = (_class = class _Oas {
|
|
207
|
-
/**
|
|
208
|
-
* The current OpenAPI definition.
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* The current user that we should use when pulling auth tokens from security schemes.
|
|
213
|
-
*/
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Internal storage array that the library utilizes to keep track of the times the
|
|
217
|
-
* {@see Oas.dereference} has been called so that if you initiate multiple promises they'll all
|
|
218
|
-
* end up returning the same data set once the initial dereference call completed.
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Internal storage array that the library utilizes to keep track of its `dereferencing` state so
|
|
223
|
-
* it doesn't initiate multiple dereferencing processes.
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Have the component schemas within this API definition been decorated with our
|
|
228
|
-
* `x-readme-ref-name` extension?
|
|
229
|
-
*
|
|
230
|
-
* @see {@link decorateComponentSchemas}
|
|
231
|
-
*/
|
|
232
|
-
__init() {this.schemasDecorated = false}
|
|
233
|
-
/**
|
|
234
|
-
* @param oas An OpenAPI definition.
|
|
235
|
-
* @param user The information about a user that we should use when pulling auth tokens from
|
|
236
|
-
* security schemes.
|
|
237
|
-
*/
|
|
238
|
-
constructor(oas, user) {;_class.prototype.__init.call(this);
|
|
239
|
-
if (typeof oas === "string") {
|
|
240
|
-
this.api = JSON.parse(oas) || {};
|
|
241
|
-
} else {
|
|
242
|
-
this.api = oas || {};
|
|
243
|
-
}
|
|
244
|
-
this.user = user || {};
|
|
245
|
-
this.promises = [];
|
|
246
|
-
this.dereferencing = {
|
|
247
|
-
processing: false,
|
|
248
|
-
complete: false,
|
|
249
|
-
circularRefs: []
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* This will initialize a new instance of the `Oas` class. This method is useful if you're using
|
|
254
|
-
* Typescript and are attempting to supply an untyped JSON object into `Oas` as it will force-type
|
|
255
|
-
* that object to an `OASDocument` for you.
|
|
256
|
-
*
|
|
257
|
-
* @param oas An OpenAPI definition.
|
|
258
|
-
* @param user The information about a user that we should use when pulling auth tokens from
|
|
259
|
-
* security schemes.
|
|
260
|
-
*/
|
|
261
|
-
static init(oas, user) {
|
|
262
|
-
return new _Oas(oas, user);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Retrieve the OpenAPI version that this API definition is targeted for.
|
|
266
|
-
*/
|
|
267
|
-
getVersion() {
|
|
268
|
-
if (this.api.openapi) {
|
|
269
|
-
return this.api.openapi;
|
|
270
|
-
}
|
|
271
|
-
throw new Error("Unable to recognize what specification version this API definition conforms to.");
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Retrieve the current OpenAPI API Definition.
|
|
275
|
-
*
|
|
276
|
-
*/
|
|
277
|
-
getDefinition() {
|
|
278
|
-
return this.api;
|
|
279
|
-
}
|
|
280
|
-
url(selected = 0, variables) {
|
|
281
|
-
const url = normalizedURL(this.api, selected);
|
|
282
|
-
return this.replaceUrl(url, variables || this.defaultVariables(selected)).trim();
|
|
283
|
-
}
|
|
284
|
-
variables(selected = 0) {
|
|
285
|
-
return _optionalChain([this, 'access', _12 => _12.api, 'access', _13 => _13.servers, 'optionalAccess', _14 => _14[selected], 'optionalAccess', _15 => _15.variables]) || {};
|
|
286
|
-
}
|
|
287
|
-
defaultVariables(selected = 0) {
|
|
288
|
-
const variables = this.variables(selected);
|
|
289
|
-
const defaults = {};
|
|
290
|
-
Object.keys(variables).forEach((key) => {
|
|
291
|
-
defaults[key] = getUserVariable(this.user, key) || variables[key].default || "";
|
|
292
|
-
});
|
|
293
|
-
return defaults;
|
|
294
|
-
}
|
|
295
|
-
splitUrl(selected = 0) {
|
|
296
|
-
const url = normalizedURL(this.api, selected);
|
|
297
|
-
const variables = this.variables(selected);
|
|
298
|
-
return url.split(/({.+?})/).filter(Boolean).map((part, i) => {
|
|
299
|
-
const isVariable = part.match(/[{}]/);
|
|
300
|
-
const value = part.replace(/[{}]/g, "");
|
|
301
|
-
const key = `${value}-${i}`;
|
|
302
|
-
if (!isVariable) {
|
|
303
|
-
return {
|
|
304
|
-
type: "text",
|
|
305
|
-
value,
|
|
306
|
-
key
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
const variable = _optionalChain([variables, 'optionalAccess', _16 => _16[value]]);
|
|
310
|
-
return {
|
|
311
|
-
type: "variable",
|
|
312
|
-
value,
|
|
313
|
-
key,
|
|
314
|
-
description: _optionalChain([variable, 'optionalAccess', _17 => _17.description]),
|
|
315
|
-
enum: _optionalChain([variable, 'optionalAccess', _18 => _18.enum])
|
|
316
|
-
};
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* With a fully composed server URL, run through our list of known OAS servers and return back
|
|
321
|
-
* which server URL was selected along with any contained server variables split out.
|
|
322
|
-
*
|
|
323
|
-
* For example, if you have an OAS server URL of `https://{name}.example.com:{port}/{basePath}`,
|
|
324
|
-
* and pass in `https://buster.example.com:3000/pet` to this function, you'll get back the
|
|
325
|
-
* following:
|
|
326
|
-
*
|
|
327
|
-
* { selected: 0, variables: { name: 'buster', port: 3000, basePath: 'pet' } }
|
|
328
|
-
*
|
|
329
|
-
* Re-supplying this data to `oas.url()` should return the same URL you passed into this method.
|
|
330
|
-
*
|
|
331
|
-
* @param baseUrl A given URL to extract server variables out of.
|
|
332
|
-
*/
|
|
333
|
-
splitVariables(baseUrl) {
|
|
334
|
-
const matchedServer = (this.api.servers || []).map((server, i) => {
|
|
335
|
-
const rgx = transformURLIntoRegex(server.url);
|
|
336
|
-
const found = new RegExp(rgx).exec(baseUrl);
|
|
337
|
-
if (!found) {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
const variables = {};
|
|
341
|
-
Array.from(server.url.matchAll(_chunkSCWW2SNXcjs.SERVER_VARIABLE_REGEX)).forEach((variable, y) => {
|
|
342
|
-
variables[variable[1]] = found[y + 1];
|
|
343
|
-
});
|
|
344
|
-
return {
|
|
345
|
-
selected: i,
|
|
346
|
-
variables
|
|
347
|
-
};
|
|
348
|
-
}).filter((item) => item !== false);
|
|
349
|
-
return matchedServer.length ? matchedServer[0] : false;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Replace templated variables with supplied data in a given URL.
|
|
353
|
-
*
|
|
354
|
-
* There are a couple ways that this will utilize variable data:
|
|
355
|
-
*
|
|
356
|
-
* - Supplying a `variables` object. If this is supplied, this data will always take priority.
|
|
357
|
-
* This incoming `variables` object can be two formats:
|
|
358
|
-
* `{ variableName: { default: 'value' } }` and `{ variableName: 'value' }`. If the former is
|
|
359
|
-
* present, that will take precedence over the latter.
|
|
360
|
-
* - If the supplied `variables` object is empty or does not match the current template name,
|
|
361
|
-
* we fallback to the data stored in `this.user` and attempt to match against that.
|
|
362
|
-
* See `getUserVariable` for some more information on how this data is pulled from `this.user`.
|
|
363
|
-
*
|
|
364
|
-
* If no variables supplied match up with the template name, the template name will instead be
|
|
365
|
-
* used as the variable data.
|
|
366
|
-
*
|
|
367
|
-
* @param url A URL to swap variables into.
|
|
368
|
-
* @param variables An object containing variables to swap into the URL.
|
|
369
|
-
*/
|
|
370
|
-
replaceUrl(url, variables = {}) {
|
|
371
|
-
return stripTrailingSlash(
|
|
372
|
-
url.replace(_chunkSCWW2SNXcjs.SERVER_VARIABLE_REGEX, (original, key) => {
|
|
373
|
-
if (key in variables) {
|
|
374
|
-
const data = variables[key];
|
|
375
|
-
if (typeof data === "object") {
|
|
376
|
-
if (!Array.isArray(data) && data !== null && "default" in data) {
|
|
377
|
-
return String(data.default);
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
return String(data);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const userVariable = getUserVariable(this.user, key);
|
|
384
|
-
if (userVariable) {
|
|
385
|
-
return String(userVariable);
|
|
386
|
-
}
|
|
387
|
-
return original;
|
|
388
|
-
})
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Retrieve an Operation of Webhook class instance for a given path and method.
|
|
393
|
-
*
|
|
394
|
-
* @param path Path to lookup and retrieve.
|
|
395
|
-
* @param method HTTP Method to retrieve on the path.
|
|
396
|
-
*/
|
|
397
|
-
operation(path, method, opts = {}) {
|
|
398
|
-
let operation = {
|
|
399
|
-
parameters: []
|
|
400
|
-
};
|
|
401
|
-
if (opts.isWebhook) {
|
|
402
|
-
if (_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.api)) {
|
|
403
|
-
const webhookPath = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _19 => _19.api, 'optionalAccess', _20 => _20.webhooks, 'optionalAccess', _21 => _21[path]]), this.api);
|
|
404
|
-
if (webhookPath && !_chunk7PWF3F2Wcjs.isRef.call(void 0, webhookPath)) {
|
|
405
|
-
if (_optionalChain([webhookPath, 'optionalAccess', _22 => _22[method]])) {
|
|
406
|
-
operation = webhookPath[method];
|
|
407
|
-
return new (0, _chunkUDN4U5TLcjs.Webhook)(this, path, method, operation);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (_optionalChain([this, 'optionalAccess', _23 => _23.api, 'optionalAccess', _24 => _24.paths, 'optionalAccess', _25 => _25[path]])) {
|
|
413
|
-
const pathItem = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, this.api.paths[path], this.api);
|
|
414
|
-
if (_optionalChain([pathItem, 'optionalAccess', _26 => _26[method]])) {
|
|
415
|
-
operation = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, pathItem[method], this.api);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return new (0, _chunkUDN4U5TLcjs.Operation)(this, path, method, operation);
|
|
419
|
-
}
|
|
420
|
-
findOperationMatches(url) {
|
|
421
|
-
const { origin, hostname } = new URL(url);
|
|
422
|
-
const originRegExp = new RegExp(origin, "i");
|
|
423
|
-
const { servers, paths } = this.api;
|
|
424
|
-
let pathName;
|
|
425
|
-
let targetServer;
|
|
426
|
-
let matchedServer;
|
|
427
|
-
if (!servers || !servers.length) {
|
|
428
|
-
matchedServer = {
|
|
429
|
-
url: "https://example.com"
|
|
430
|
-
};
|
|
431
|
-
} else {
|
|
432
|
-
matchedServer = servers.find((s) => originRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
|
|
433
|
-
if (!matchedServer) {
|
|
434
|
-
const hostnameRegExp = new RegExp(hostname);
|
|
435
|
-
matchedServer = servers.find((s) => hostnameRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (matchedServer) {
|
|
439
|
-
targetServer = {
|
|
440
|
-
...matchedServer,
|
|
441
|
-
url: this.replaceUrl(matchedServer.url, matchedServer.variables || {})
|
|
442
|
-
};
|
|
443
|
-
[, pathName] = url.split(new RegExp(targetServer.url, "i"));
|
|
444
|
-
}
|
|
445
|
-
if (!matchedServer || !pathName) {
|
|
446
|
-
const matchedServerAndPath = (servers || []).map((server) => {
|
|
447
|
-
const rgx = transformURLIntoRegex(server.url);
|
|
448
|
-
const found = new RegExp(rgx).exec(url);
|
|
449
|
-
if (!found) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
matchedServer: server,
|
|
454
|
-
pathName: url.split(new RegExp(rgx)).slice(-1).pop()
|
|
455
|
-
};
|
|
456
|
-
}).filter((item) => item !== void 0);
|
|
457
|
-
if (!matchedServerAndPath.length) {
|
|
458
|
-
return void 0;
|
|
459
|
-
}
|
|
460
|
-
pathName = matchedServerAndPath[0].pathName;
|
|
461
|
-
targetServer = {
|
|
462
|
-
...matchedServerAndPath[0].matchedServer
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
if (pathName === void 0) return void 0;
|
|
466
|
-
if (pathName === "") pathName = "/";
|
|
467
|
-
if (!paths || !targetServer) return void 0;
|
|
468
|
-
const annotatedPaths = generatePathMatches(paths, pathName, targetServer.url);
|
|
469
|
-
if (!annotatedPaths.length) return void 0;
|
|
470
|
-
return annotatedPaths;
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Discover an operation in an OAS from a fully-formed URL and HTTP method. Will return an object
|
|
474
|
-
* containing a `url` object and another one for `operation`. This differs from `getOperation()`
|
|
475
|
-
* in that it does not return an instance of the `Operation` class.
|
|
476
|
-
*
|
|
477
|
-
* @param url A full URL to look up.
|
|
478
|
-
* @param method The cooresponding HTTP method to look up.
|
|
479
|
-
*/
|
|
480
|
-
findOperation(url, method) {
|
|
481
|
-
const annotatedPaths = this.findOperationMatches(url);
|
|
482
|
-
if (!annotatedPaths) {
|
|
483
|
-
return void 0;
|
|
484
|
-
}
|
|
485
|
-
const matches = filterPathMethods(annotatedPaths, method);
|
|
486
|
-
if (!matches.length) return void 0;
|
|
487
|
-
return findTargetPath(matches);
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an
|
|
491
|
-
* object containing a `url` object and another one for `operation`.
|
|
492
|
-
*
|
|
493
|
-
* @param url A full URL to look up.
|
|
494
|
-
*/
|
|
495
|
-
findOperationWithoutMethod(url) {
|
|
496
|
-
const annotatedPaths = this.findOperationMatches(url);
|
|
497
|
-
if (!annotatedPaths) {
|
|
498
|
-
return void 0;
|
|
499
|
-
}
|
|
500
|
-
return findTargetPath(annotatedPaths);
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Retrieve an operation in an OAS from a fully-formed URL and HTTP method. Differs from
|
|
504
|
-
* `findOperation` in that while this method will return an `Operation` instance,
|
|
505
|
-
* `findOperation()` does not.
|
|
506
|
-
*
|
|
507
|
-
* @param url A full URL to look up.
|
|
508
|
-
* @param method The cooresponding HTTP method to look up.
|
|
509
|
-
*/
|
|
510
|
-
getOperation(url, method) {
|
|
511
|
-
const op = this.findOperation(url, method);
|
|
512
|
-
if (op === void 0) {
|
|
513
|
-
return void 0;
|
|
514
|
-
}
|
|
515
|
-
return this.operation(op.url.nonNormalizedPath, method);
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Retrieve an operation in an OAS by an `operationId`.
|
|
519
|
-
*
|
|
520
|
-
* If an operation does not have an `operationId` one will be generated in place, using the
|
|
521
|
-
* default behavior of `Operation.getOperationId()`, and then asserted against your query.
|
|
522
|
-
*
|
|
523
|
-
* Note that because `operationId`s are unique that uniqueness does include casing so the ID
|
|
524
|
-
* you are looking for will be asserted as an exact match.
|
|
525
|
-
*
|
|
526
|
-
* @see {Operation.getOperationId()}
|
|
527
|
-
* @param id The `operationId` to look up.
|
|
528
|
-
*/
|
|
529
|
-
getOperationById(id) {
|
|
530
|
-
let found;
|
|
531
|
-
Object.values(this.getPaths()).forEach((operations) => {
|
|
532
|
-
if (found) return;
|
|
533
|
-
found = Object.values(operations).find((operation) => operation.getOperationId() === id);
|
|
534
|
-
});
|
|
535
|
-
if (found) {
|
|
536
|
-
return found;
|
|
537
|
-
}
|
|
538
|
-
Object.entries(this.getWebhooks()).forEach(([, webhooks]) => {
|
|
539
|
-
if (found) return;
|
|
540
|
-
found = Object.values(webhooks).find((webhook) => webhook.getOperationId() === id);
|
|
541
|
-
});
|
|
542
|
-
return found;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* With an object of user information, retrieve the appropriate API auth keys from the current
|
|
546
|
-
* OAS definition.
|
|
547
|
-
*
|
|
548
|
-
* @see {@link https://docs.readme.com/docs/passing-data-to-jwt}
|
|
549
|
-
* @param user User
|
|
550
|
-
* @param selectedApp The user app to retrieve an auth key for.
|
|
551
|
-
*/
|
|
552
|
-
getAuth(user, selectedApp) {
|
|
553
|
-
if (!_optionalChain([this, 'access', _27 => _27.api, 'optionalAccess', _28 => _28.components, 'optionalAccess', _29 => _29.securitySchemes])) {
|
|
554
|
-
return {};
|
|
555
|
-
}
|
|
556
|
-
return getAuth(this.api, user, selectedApp);
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Determine if a security scheme exists within the API definition.
|
|
560
|
-
*
|
|
561
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}
|
|
562
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}
|
|
563
|
-
* @param name The name of the security scheme to check for.
|
|
564
|
-
*/
|
|
565
|
-
hasSecurityScheme(name) {
|
|
566
|
-
return Boolean(_optionalChain([this, 'access', _30 => _30.api, 'optionalAccess', _31 => _31.components, 'optionalAccess', _32 => _32.securitySchemes, 'optionalAccess', _33 => _33[name]]));
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Retrieve a security scheme from the API definition.
|
|
570
|
-
*
|
|
571
|
-
* If the found security scheme is a `$ref` pointer it will be lazily dereferenced; if the scheme
|
|
572
|
-
* cannot be resolved after that process (eg. it's circular or is an invalid `$ref`) then
|
|
573
|
-
* `undefined` will be returned.
|
|
574
|
-
*
|
|
575
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}
|
|
576
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}
|
|
577
|
-
* @param name The name of the security scheme to retrieve.
|
|
578
|
-
*/
|
|
579
|
-
getSecurityScheme(name) {
|
|
580
|
-
if (!this.hasSecurityScheme(name)) {
|
|
581
|
-
return void 0;
|
|
582
|
-
}
|
|
583
|
-
let scheme = _optionalChain([this, 'access', _34 => _34.api, 'optionalAccess', _35 => _35.components, 'optionalAccess', _36 => _36.securitySchemes, 'optionalAccess', _37 => _37[name]]);
|
|
584
|
-
if (!scheme) return void 0;
|
|
585
|
-
if (_chunk7PWF3F2Wcjs.isRef.call(void 0, scheme)) {
|
|
586
|
-
scheme = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, scheme, this.api);
|
|
587
|
-
if (!scheme || _chunk7PWF3F2Wcjs.isRef.call(void 0, scheme)) return void 0;
|
|
588
|
-
}
|
|
589
|
-
return scheme;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Returns the `paths` object that exists in this API definition but with every `method` mapped
|
|
593
|
-
* to an instance of the `Operation` class.
|
|
594
|
-
*
|
|
595
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
|
|
596
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
597
|
-
*/
|
|
598
|
-
getPaths() {
|
|
599
|
-
const paths = {};
|
|
600
|
-
if (!this.api.paths) {
|
|
601
|
-
return paths;
|
|
602
|
-
}
|
|
603
|
-
Object.keys(this.api.paths).forEach((path) => {
|
|
604
|
-
if (path.startsWith("x-")) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
paths[path] = {};
|
|
608
|
-
let pathItem = this.api.paths[path];
|
|
609
|
-
if (!pathItem) {
|
|
610
|
-
return;
|
|
611
|
-
} else if (_chunk7PWF3F2Wcjs.isRef.call(void 0, pathItem)) {
|
|
612
|
-
this.api.paths[path] = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, pathItem, this.api);
|
|
613
|
-
pathItem = this.api.paths[path];
|
|
614
|
-
if (!pathItem || _chunk7PWF3F2Wcjs.isRef.call(void 0, pathItem)) {
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
Object.keys(pathItem).forEach((method) => {
|
|
619
|
-
if (!_chunkSCWW2SNXcjs.supportedMethods.includes(method)) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
paths[path][method] = this.operation(path, method);
|
|
623
|
-
});
|
|
624
|
-
});
|
|
625
|
-
return paths;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Returns the `webhooks` object that exists in this API definition but with every `method`
|
|
629
|
-
* mapped to an instance of the `Webhook` class.
|
|
630
|
-
*
|
|
631
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
|
|
632
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
633
|
-
*/
|
|
634
|
-
getWebhooks() {
|
|
635
|
-
const webhooks = {};
|
|
636
|
-
if (!_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.api) || !this.api.webhooks) {
|
|
637
|
-
return webhooks;
|
|
638
|
-
}
|
|
639
|
-
Object.keys(this.api.webhooks).forEach((id) => {
|
|
640
|
-
webhooks[id] = {};
|
|
641
|
-
const webhookPath = _chunkSCWW2SNXcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _38 => _38.api, 'access', _39 => _39.webhooks, 'optionalAccess', _40 => _40[id]]), this.api);
|
|
642
|
-
if (webhookPath) {
|
|
643
|
-
Object.keys(webhookPath).forEach((method) => {
|
|
644
|
-
if (!_chunkSCWW2SNXcjs.supportedMethods.includes(method)) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
webhooks[id][method] = this.operation(id, method, {
|
|
648
|
-
isWebhook: true
|
|
649
|
-
});
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
return webhooks;
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Return an array of all tag names that exist on this API definition.
|
|
657
|
-
*
|
|
658
|
-
* If the API definition uses the `x-disable-tag-sorting` extension then tags will be returned in
|
|
659
|
-
* the order they're defined.
|
|
660
|
-
*
|
|
661
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
|
|
662
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
|
|
663
|
-
* @param setIfMissing If a tag is not present on an operation that operations path will be added
|
|
664
|
-
* into the list of tags returned.
|
|
665
|
-
*/
|
|
666
|
-
getTags(setIfMissing = false) {
|
|
667
|
-
const allTags = /* @__PURE__ */ new Set();
|
|
668
|
-
const oasTags = _optionalChain([this, 'access', _41 => _41.api, 'access', _42 => _42.tags, 'optionalAccess', _43 => _43.map, 'call', _44 => _44((tag) => tag.name)]) || [];
|
|
669
|
-
const disableTagSorting = _chunkAYA3UT4Lcjs.getExtension.call(void 0, "disable-tag-sorting", this.api);
|
|
670
|
-
Object.entries(this.getPaths()).forEach(([path, operations]) => {
|
|
671
|
-
Object.values(operations).forEach((operation) => {
|
|
672
|
-
const tags = operation.getTags();
|
|
673
|
-
if (setIfMissing && !tags.length) {
|
|
674
|
-
allTags.add(path);
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
tags.forEach((tag) => {
|
|
678
|
-
allTags.add(tag.name);
|
|
679
|
-
});
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
Object.entries(this.getWebhooks()).forEach(([path, webhooks]) => {
|
|
683
|
-
Object.values(webhooks).forEach((webhook) => {
|
|
684
|
-
const tags = webhook.getTags();
|
|
685
|
-
if (setIfMissing && !tags.length) {
|
|
686
|
-
allTags.add(path);
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
tags.forEach((tag) => {
|
|
690
|
-
allTags.add(tag.name);
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
const endpointTags = [];
|
|
695
|
-
const tagsArray = [];
|
|
696
|
-
if (disableTagSorting) {
|
|
697
|
-
return Array.from(allTags);
|
|
698
|
-
}
|
|
699
|
-
Array.from(allTags).forEach((tag) => {
|
|
700
|
-
if (oasTags.includes(tag)) {
|
|
701
|
-
tagsArray.push(tag);
|
|
702
|
-
} else {
|
|
703
|
-
endpointTags.push(tag);
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
let sortedTags = tagsArray.toSorted((a, b) => {
|
|
707
|
-
return oasTags.indexOf(a) - oasTags.indexOf(b);
|
|
708
|
-
});
|
|
709
|
-
sortedTags = sortedTags.concat(endpointTags);
|
|
710
|
-
return sortedTags;
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Determine if a given a custom specification extension exists within the API definition.
|
|
714
|
-
*
|
|
715
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
|
|
716
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
|
|
717
|
-
* @param extension Specification extension to lookup.
|
|
718
|
-
*/
|
|
719
|
-
hasExtension(extension) {
|
|
720
|
-
return _chunkAYA3UT4Lcjs.hasRootExtension.call(void 0, extension, this.api);
|
|
721
|
-
}
|
|
722
|
-
/**
|
|
723
|
-
* Retrieve a custom specification extension off of the API definition.
|
|
724
|
-
*
|
|
725
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
|
|
726
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
|
|
727
|
-
* @param extension Specification extension to lookup.
|
|
728
|
-
*/
|
|
729
|
-
getExtension(extension, operation) {
|
|
730
|
-
return _chunkAYA3UT4Lcjs.getExtension.call(void 0, extension, this.api, operation);
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* Determine if a given OpenAPI custom extension is valid or not.
|
|
734
|
-
*
|
|
735
|
-
* @see {@link https://docs.readme.com/docs/openapi-extensions}
|
|
736
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
|
|
737
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
|
|
738
|
-
* @param extension Specification extension to validate.
|
|
739
|
-
* @throws
|
|
740
|
-
*/
|
|
741
|
-
validateExtension(extension) {
|
|
742
|
-
if (this.hasExtension("x-readme")) {
|
|
743
|
-
const data = this.getExtension("x-readme");
|
|
744
|
-
if (typeof data !== "object" || Array.isArray(data) || data === null) {
|
|
745
|
-
throw new TypeError('"x-readme" must be of type "Object"');
|
|
746
|
-
}
|
|
747
|
-
if (extension in data) {
|
|
748
|
-
if ([_chunkAYA3UT4Lcjs.CODE_SAMPLES, _chunkAYA3UT4Lcjs.HEADERS, _chunkAYA3UT4Lcjs.PARAMETER_ORDERING, _chunkAYA3UT4Lcjs.SAMPLES_LANGUAGES].includes(extension)) {
|
|
749
|
-
if (data[extension] !== void 0) {
|
|
750
|
-
if (!Array.isArray(data[extension])) {
|
|
751
|
-
throw new TypeError(`"x-readme.${extension}" must be of type "Array"`);
|
|
752
|
-
}
|
|
753
|
-
if (extension === _chunkAYA3UT4Lcjs.PARAMETER_ORDERING) {
|
|
754
|
-
_chunkAYA3UT4Lcjs.validateParameterOrdering.call(void 0, data[extension], `x-readme.${extension}`);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
} else if (extension === _chunkAYA3UT4Lcjs.OAUTH_OPTIONS) {
|
|
758
|
-
if (typeof data[extension] !== "object") {
|
|
759
|
-
throw new TypeError(`"x-readme.${extension}" must be of type "Object"`);
|
|
760
|
-
}
|
|
761
|
-
} else if (typeof data[extension] !== "boolean") {
|
|
762
|
-
throw new TypeError(`"x-readme.${extension}" must be of type "Boolean"`);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
if (this.hasExtension(`x-${extension}`)) {
|
|
767
|
-
const data = this.getExtension(`x-${extension}`);
|
|
768
|
-
if ([_chunkAYA3UT4Lcjs.CODE_SAMPLES, _chunkAYA3UT4Lcjs.HEADERS, _chunkAYA3UT4Lcjs.PARAMETER_ORDERING, _chunkAYA3UT4Lcjs.SAMPLES_LANGUAGES].includes(extension)) {
|
|
769
|
-
if (!Array.isArray(data)) {
|
|
770
|
-
throw new TypeError(`"x-${extension}" must be of type "Array"`);
|
|
771
|
-
}
|
|
772
|
-
if (extension === _chunkAYA3UT4Lcjs.PARAMETER_ORDERING) {
|
|
773
|
-
_chunkAYA3UT4Lcjs.validateParameterOrdering.call(void 0, data, `x-${extension}`);
|
|
774
|
-
}
|
|
775
|
-
} else if (extension === _chunkAYA3UT4Lcjs.OAUTH_OPTIONS) {
|
|
776
|
-
if (typeof data !== "object") {
|
|
777
|
-
throw new TypeError(`"x-${extension}" must be of type "Object"`);
|
|
778
|
-
}
|
|
779
|
-
} else if (typeof data !== "boolean") {
|
|
780
|
-
throw new TypeError(`"x-${extension}" must be of type "Boolean"`);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Validate all of our custom or known OpenAPI extensions, throwing exceptions when necessary.
|
|
786
|
-
*
|
|
787
|
-
* @see {@link https://docs.readme.com/docs/openapi-extensions}
|
|
788
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
|
|
789
|
-
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
|
|
790
|
-
*/
|
|
791
|
-
validateExtensions() {
|
|
792
|
-
Object.keys(_chunkAYA3UT4Lcjs.extensionDefaults).forEach((extension) => {
|
|
793
|
-
this.validateExtension(extension);
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Dereference the current API definition so it can be parsed free from the hassle of resolving
|
|
798
|
-
* `$ref` schemas and circular structures.
|
|
799
|
-
*
|
|
800
|
-
*/
|
|
801
|
-
async dereference(opts) {
|
|
802
|
-
if (this.dereferencing.complete) {
|
|
803
|
-
return new Promise((resolve) => {
|
|
804
|
-
resolve(true);
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
if (this.dereferencing.processing) {
|
|
808
|
-
return new Promise((resolve, reject) => {
|
|
809
|
-
this.promises.push({ resolve, reject });
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
this.dereferencing.processing = true;
|
|
813
|
-
if (!this.schemasDecorated) {
|
|
814
|
-
_chunkSCWW2SNXcjs.decorateComponentSchemasWithRefName.call(void 0, this.api);
|
|
815
|
-
this.schemasDecorated = true;
|
|
816
|
-
}
|
|
817
|
-
const { api, promises } = this;
|
|
818
|
-
const circularRefs = /* @__PURE__ */ new Set();
|
|
819
|
-
const dereferencingOptions = _chunkSCWW2SNXcjs.getDereferencingOptions.call(void 0, circularRefs);
|
|
820
|
-
return _openapiparser.dereference.call(void 0, api, dereferencingOptions).then((dereferenced) => {
|
|
821
|
-
this.api = dereferenced;
|
|
822
|
-
this.promises = promises;
|
|
823
|
-
this.dereferencing = {
|
|
824
|
-
processing: false,
|
|
825
|
-
complete: true,
|
|
826
|
-
// We need to convert our `Set` to an array in order to match the typings.
|
|
827
|
-
circularRefs: [...circularRefs]
|
|
828
|
-
};
|
|
829
|
-
if (_optionalChain([opts, 'optionalAccess', _45 => _45.cb])) {
|
|
830
|
-
_optionalChain([opts, 'optionalAccess', _46 => _46.cb, 'call', _47 => _47()]);
|
|
831
|
-
}
|
|
832
|
-
}).then(() => {
|
|
833
|
-
return this.promises.map((deferred) => deferred.resolve());
|
|
834
|
-
}).catch((err) => {
|
|
835
|
-
this.dereferencing.processing = false;
|
|
836
|
-
this.promises.map((deferred) => deferred.reject(err));
|
|
837
|
-
throw err;
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Determine if the current API definition has been dereferenced or not.
|
|
842
|
-
*
|
|
843
|
-
* @see Oas.dereference
|
|
844
|
-
*/
|
|
845
|
-
isDereferenced() {
|
|
846
|
-
return this.dereferencing.processing || this.dereferencing.complete;
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* Retrieve any circular `$ref` pointers that maybe present within the API definition.
|
|
850
|
-
*
|
|
851
|
-
* This method requires that you first dereference the definition.
|
|
852
|
-
*
|
|
853
|
-
* @see Oas.dereference
|
|
854
|
-
*/
|
|
855
|
-
getCircularReferences() {
|
|
856
|
-
if (!this.dereferencing.complete) {
|
|
857
|
-
throw new Error(".dereference() must be called first in order for this method to obtain circular references.");
|
|
858
|
-
}
|
|
859
|
-
return this.dereferencing.circularRefs;
|
|
860
|
-
}
|
|
861
|
-
}, _class);
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
exports.Oas = Oas;
|
|
866
|
-
//# sourceMappingURL=chunk-YKV73CBG.cjs.map
|