oas 36.0.3 → 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.
Files changed (38) hide show
  1. package/README.md +0 -5
  2. package/dist/analyzer/index.cjs +83 -28
  3. package/dist/analyzer/index.cjs.map +1 -1
  4. package/dist/analyzer/index.d.cts +3 -10
  5. package/dist/analyzer/index.d.ts +3 -10
  6. package/dist/analyzer/index.js +81 -26
  7. package/dist/analyzer/index.js.map +1 -1
  8. package/dist/analyzer/types.d.cts +0 -1
  9. package/dist/analyzer/types.d.ts +0 -1
  10. package/dist/{chunk-BJCTM2ME.cjs → chunk-GS43VKJH.cjs} +319 -270
  11. package/dist/chunk-GS43VKJH.cjs.map +1 -0
  12. package/dist/{chunk-6MDVLJ3A.js → chunk-IEN4GZPF.js} +9 -23
  13. package/dist/chunk-IEN4GZPF.js.map +1 -0
  14. package/dist/{chunk-SCWW2SNX.cjs → chunk-UKD63LKG.cjs} +10 -24
  15. package/dist/chunk-UKD63LKG.cjs.map +1 -0
  16. package/dist/{chunk-RQZ2BPMU.js → chunk-WIVQX3DA.js} +198 -149
  17. package/dist/chunk-WIVQX3DA.js.map +1 -0
  18. package/dist/index.cjs +634 -7
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +38 -135
  21. package/dist/index.d.ts +38 -135
  22. package/dist/index.js +633 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/operation/index.cjs +3 -3
  25. package/dist/operation/index.js +2 -2
  26. package/dist/reducer/index.cjs +7 -7
  27. package/dist/reducer/index.js +1 -1
  28. package/dist/utils.cjs +2 -2
  29. package/dist/utils.js +1 -1
  30. package/package.json +1 -2
  31. package/dist/chunk-4WJUHXQH.js +0 -866
  32. package/dist/chunk-4WJUHXQH.js.map +0 -1
  33. package/dist/chunk-6MDVLJ3A.js.map +0 -1
  34. package/dist/chunk-BJCTM2ME.cjs.map +0 -1
  35. package/dist/chunk-LJWHPW4H.cjs +0 -866
  36. package/dist/chunk-LJWHPW4H.cjs.map +0 -1
  37. package/dist/chunk-RQZ2BPMU.js.map +0 -1
  38. package/dist/chunk-SCWW2SNX.cjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,13 +1,640 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
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; }
2
2
 
3
- var _chunkLJWHPW4Hcjs = require('./chunk-LJWHPW4H.cjs');
4
- require('./chunk-BJCTM2ME.cjs');
5
- require('./chunk-SCWW2SNX.cjs');
6
- require('./chunk-AYA3UT4L.cjs');
7
- require('./chunk-7PWF3F2W.cjs');
8
3
 
9
4
 
10
- exports.default = _chunkLJWHPW4Hcjs.Oas;
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _chunkGS43VKJHcjs = require('./chunk-GS43VKJH.cjs');
15
+
16
+
17
+
18
+
19
+ var _chunkUKD63LKGcjs = require('./chunk-UKD63LKG.cjs');
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ var _chunkAYA3UT4Lcjs = require('./chunk-AYA3UT4L.cjs');
31
+
32
+
33
+
34
+ var _chunk7PWF3F2Wcjs = require('./chunk-7PWF3F2W.cjs');
35
+
36
+ // src/lib/get-auth.ts
37
+ function getPrimitiveDefaultAuth(scheme) {
38
+ return typeof scheme["x-default"] === "number" || typeof scheme["x-default"] === "string" ? scheme["x-default"] : null;
39
+ }
40
+ function getKey(user, scheme) {
41
+ switch (scheme.type) {
42
+ case "oauth2":
43
+ return user[scheme._key] || user.apiKey || getPrimitiveDefaultAuth(scheme) || null;
44
+ case "apiKey":
45
+ return user[scheme._key] || user.apiKey || scheme["x-default"] || null;
46
+ case "http":
47
+ if (scheme.scheme === "basic") {
48
+ return user[scheme._key] || (user.user || user.pass ? { user: user.user || null, pass: user.pass || null } : scheme["x-default"]) || {
49
+ user: null,
50
+ pass: null
51
+ };
52
+ }
53
+ if (scheme.scheme === "bearer") {
54
+ return user[scheme._key] || user.apiKey || scheme["x-default"] || null;
55
+ }
56
+ return null;
57
+ default:
58
+ return null;
59
+ }
60
+ }
61
+ function getByScheme(user, scheme = {}, selectedApp) {
62
+ if (_optionalChain([user, 'optionalAccess', _ => _.keys, 'optionalAccess', _2 => _2.length])) {
63
+ if (selectedApp) {
64
+ const userKey = user.keys.find((k) => k.name === selectedApp);
65
+ if (!userKey) {
66
+ return null;
67
+ }
68
+ return getKey(userKey, scheme);
69
+ }
70
+ return getKey(user.keys[0], scheme);
71
+ }
72
+ return getKey(user, scheme);
73
+ }
74
+ function getAuth(api, user, selectedApp) {
75
+ return Object.keys(_optionalChain([api, 'optionalAccess', _3 => _3.components, 'optionalAccess', _4 => _4.securitySchemes]) || {}).map((scheme) => {
76
+ const securityScheme = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, _optionalChain([api, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.securitySchemes, 'optionalAccess', _7 => _7[scheme]]), api);
77
+ if (!securityScheme || _chunk7PWF3F2Wcjs.isRef.call(void 0, securityScheme)) {
78
+ return false;
79
+ }
80
+ return {
81
+ [scheme]: getByScheme(
82
+ user,
83
+ {
84
+ ...securityScheme,
85
+ _key: scheme
86
+ },
87
+ selectedApp
88
+ )
89
+ };
90
+ }).filter((item) => item !== void 0).reduce((prev, next) => Object.assign(prev, next), {});
91
+ }
92
+
93
+ // src/index.ts
94
+ var Oas = class _Oas {
95
+ /**
96
+ * The current OpenAPI definition.
97
+ */
98
+
99
+ /**
100
+ * The current user that we should use when pulling auth tokens from security schemes.
101
+ */
102
+
103
+ /**
104
+ * @param oas An OpenAPI definition.
105
+ * @param user The information about a user that we should use when pulling auth tokens from
106
+ * security schemes.
107
+ */
108
+ constructor(oas, user) {
109
+ if (typeof oas === "string") {
110
+ this.api = JSON.parse(oas) || {};
111
+ } else {
112
+ this.api = oas || {};
113
+ }
114
+ this.user = user || {};
115
+ }
116
+ /**
117
+ * This will initialize a new instance of the `Oas` class. This method is useful if you're using
118
+ * Typescript and are attempting to supply an untyped JSON object into `Oas` as it will force-type
119
+ * that object to an `OASDocument` for you.
120
+ *
121
+ * @param oas An OpenAPI definition.
122
+ * @param user The information about a user that we should use when pulling auth tokens from
123
+ * security schemes.
124
+ */
125
+ static init(oas, user) {
126
+ return new _Oas(oas, user);
127
+ }
128
+ /**
129
+ * Retrieve the OpenAPI version that this API definition is targeted for.
130
+ */
131
+ getVersion() {
132
+ if (this.api.openapi) {
133
+ return this.api.openapi;
134
+ }
135
+ throw new Error("Unable to recognize what specification version this API definition conforms to.");
136
+ }
137
+ /**
138
+ * Retrieve the current OpenAPI API Definition.
139
+ *
140
+ */
141
+ getDefinition() {
142
+ return this.api;
143
+ }
144
+ url(selected = 0, variables) {
145
+ const url = _chunkGS43VKJHcjs.normalizedURLFromServers.call(void 0, this.api.servers, selected);
146
+ return this.replaceUrl(url, variables || this.defaultVariables(selected)).trim();
147
+ }
148
+ variables(selected = 0) {
149
+ return _chunkGS43VKJHcjs.variablesFromServers.call(void 0, this.api.servers, selected);
150
+ }
151
+ defaultVariables(selected = 0) {
152
+ return _chunkGS43VKJHcjs.defaultVariablesFromServers.call(void 0, this.api.servers, selected, this.user);
153
+ }
154
+ splitUrl(selected = 0) {
155
+ return _chunkGS43VKJHcjs.splitUrlFromServers.call(void 0, this.api.servers, selected);
156
+ }
157
+ /**
158
+ * With a fully composed server URL, run through our list of known OAS servers and return back
159
+ * which server URL was selected along with any contained server variables split out.
160
+ *
161
+ * For example, if you have an OAS server URL of `https://{name}.example.com:{port}/{basePath}`,
162
+ * and pass in `https://buster.example.com:3000/pet` to this function, you'll get back the
163
+ * following:
164
+ *
165
+ * { selected: 0, variables: { name: 'buster', port: 3000, basePath: 'pet' } }
166
+ *
167
+ * Re-supplying this data to `oas.url()` should return the same URL you passed into this method.
168
+ *
169
+ * @param baseUrl A given URL to extract server variables out of.
170
+ */
171
+ splitVariables(baseUrl) {
172
+ const matchedServer = (this.api.servers || []).map((server, i) => {
173
+ const rgx = _chunkGS43VKJHcjs.transformURLIntoRegex.call(void 0, server.url);
174
+ const found = new RegExp(rgx).exec(baseUrl);
175
+ if (!found) {
176
+ return false;
177
+ }
178
+ const variables = {};
179
+ Array.from(server.url.matchAll(_chunkUKD63LKGcjs.SERVER_VARIABLE_REGEX)).forEach((variable, y) => {
180
+ variables[variable[1]] = found[y + 1];
181
+ });
182
+ return {
183
+ selected: i,
184
+ variables
185
+ };
186
+ }).filter((item) => item !== false);
187
+ return matchedServer.length ? matchedServer[0] : false;
188
+ }
189
+ /**
190
+ * Replace templated variables with supplied data in a given URL.
191
+ *
192
+ * There are a couple ways that this will utilize variable data:
193
+ *
194
+ * - Supplying a `variables` object. If this is supplied, this data will always take priority.
195
+ * This incoming `variables` object can be two formats:
196
+ * `{ variableName: { default: 'value' } }` and `{ variableName: 'value' }`. If the former is
197
+ * present, that will take precedence over the latter.
198
+ * - If the supplied `variables` object is empty or does not match the current template name,
199
+ * we fallback to the data stored in `this.user` and attempt to match against that.
200
+ * See `getUserVariable` for some more information on how this data is pulled from `this.user`.
201
+ *
202
+ * If no variables supplied match up with the template name, the template name will instead be
203
+ * used as the variable data.
204
+ *
205
+ * @param url A URL to swap variables into.
206
+ * @param variables An object containing variables to swap into the URL.
207
+ */
208
+ replaceUrl(url, variables = {}) {
209
+ return _chunkGS43VKJHcjs.stripTrailingSlash.call(void 0,
210
+ url.replace(_chunkUKD63LKGcjs.SERVER_VARIABLE_REGEX, (original, key) => {
211
+ if (key in variables) {
212
+ const data = variables[key];
213
+ if (typeof data === "object") {
214
+ if (!Array.isArray(data) && data !== null && "default" in data) {
215
+ return String(data.default);
216
+ }
217
+ } else {
218
+ return String(data);
219
+ }
220
+ }
221
+ const userVariable = _chunkGS43VKJHcjs.getUserVariable.call(void 0, this.user, key);
222
+ if (userVariable) {
223
+ return String(userVariable);
224
+ }
225
+ return original;
226
+ })
227
+ );
228
+ }
229
+ /**
230
+ * Retrieve an Operation of Webhook class instance for a given path and method.
231
+ *
232
+ * @param path Path to lookup and retrieve.
233
+ * @param method HTTP Method to retrieve on the path.
234
+ */
235
+ operation(path, method, opts = {}) {
236
+ let operation = {
237
+ parameters: []
238
+ };
239
+ if (opts.isWebhook) {
240
+ if (_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.api)) {
241
+ const webhookPath = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _8 => _8.api, 'optionalAccess', _9 => _9.webhooks, 'optionalAccess', _10 => _10[path]]), this.api);
242
+ if (webhookPath && !_chunk7PWF3F2Wcjs.isRef.call(void 0, webhookPath)) {
243
+ if (_optionalChain([webhookPath, 'optionalAccess', _11 => _11[method]])) {
244
+ operation = webhookPath[method];
245
+ return new (0, _chunkGS43VKJHcjs.Webhook)(this, path, method, operation);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ if (_optionalChain([this, 'optionalAccess', _12 => _12.api, 'optionalAccess', _13 => _13.paths, 'optionalAccess', _14 => _14[path]])) {
251
+ const pathItem = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, this.api.paths[path], this.api);
252
+ if (_optionalChain([pathItem, 'optionalAccess', _15 => _15[method]])) {
253
+ operation = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, pathItem[method], this.api);
254
+ }
255
+ }
256
+ return new (0, _chunkGS43VKJHcjs.Operation)(this, path, method, operation);
257
+ }
258
+ findOperationMatches(url) {
259
+ const { origin, hostname } = new URL(url);
260
+ const originRegExp = new RegExp(origin, "i");
261
+ const { servers, paths } = this.api;
262
+ let pathName;
263
+ let targetServer;
264
+ let matchedServer;
265
+ if (!servers || !servers.length) {
266
+ matchedServer = {
267
+ url: "https://example.com"
268
+ };
269
+ } else {
270
+ matchedServer = servers.find((s) => originRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
271
+ if (!matchedServer) {
272
+ const hostnameRegExp = new RegExp(hostname);
273
+ matchedServer = servers.find((s) => hostnameRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
274
+ }
275
+ }
276
+ if (matchedServer) {
277
+ targetServer = {
278
+ ...matchedServer,
279
+ url: this.replaceUrl(matchedServer.url, matchedServer.variables || {})
280
+ };
281
+ [, pathName] = url.split(new RegExp(targetServer.url, "i"));
282
+ }
283
+ if (!matchedServer || !pathName) {
284
+ const matchedServerAndPath = (servers || []).map((server) => {
285
+ const rgx = _chunkGS43VKJHcjs.transformURLIntoRegex.call(void 0, server.url);
286
+ const found = new RegExp(rgx).exec(url);
287
+ if (!found) {
288
+ return;
289
+ }
290
+ return {
291
+ matchedServer: server,
292
+ pathName: url.split(new RegExp(rgx)).slice(-1).pop()
293
+ };
294
+ }).filter((item) => item !== void 0);
295
+ if (!matchedServerAndPath.length) {
296
+ return void 0;
297
+ }
298
+ pathName = matchedServerAndPath[0].pathName;
299
+ targetServer = {
300
+ ...matchedServerAndPath[0].matchedServer
301
+ };
302
+ }
303
+ if (pathName === void 0) return void 0;
304
+ if (pathName === "") pathName = "/";
305
+ if (!paths || !targetServer) return void 0;
306
+ const annotatedPaths = _chunkGS43VKJHcjs.generatePathMatches.call(void 0, paths, pathName, targetServer.url);
307
+ if (!annotatedPaths.length) return void 0;
308
+ return annotatedPaths;
309
+ }
310
+ /**
311
+ * Discover an operation in an OAS from a fully-formed URL and HTTP method. Will return an object
312
+ * containing a `url` object and another one for `operation`. This differs from `getOperation()`
313
+ * in that it does not return an instance of the `Operation` class.
314
+ *
315
+ * @param url A full URL to look up.
316
+ * @param method The cooresponding HTTP method to look up.
317
+ */
318
+ findOperation(url, method) {
319
+ const annotatedPaths = this.findOperationMatches(url);
320
+ if (!annotatedPaths) {
321
+ return void 0;
322
+ }
323
+ const matches = _chunkGS43VKJHcjs.filterPathMethods.call(void 0, annotatedPaths, method);
324
+ if (!matches.length) return void 0;
325
+ return _chunkGS43VKJHcjs.findTargetPath.call(void 0, matches);
326
+ }
327
+ /**
328
+ * Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an
329
+ * object containing a `url` object and another one for `operation`.
330
+ *
331
+ * @param url A full URL to look up.
332
+ */
333
+ findOperationWithoutMethod(url) {
334
+ const annotatedPaths = this.findOperationMatches(url);
335
+ if (!annotatedPaths) {
336
+ return void 0;
337
+ }
338
+ return _chunkGS43VKJHcjs.findTargetPath.call(void 0, annotatedPaths);
339
+ }
340
+ /**
341
+ * Retrieve an operation in an OAS from a fully-formed URL and HTTP method. Differs from
342
+ * `findOperation` in that while this method will return an `Operation` instance,
343
+ * `findOperation()` does not.
344
+ *
345
+ * @param url A full URL to look up.
346
+ * @param method The cooresponding HTTP method to look up.
347
+ */
348
+ getOperation(url, method) {
349
+ const op = this.findOperation(url, method);
350
+ if (op === void 0) {
351
+ return void 0;
352
+ }
353
+ return this.operation(op.url.nonNormalizedPath, method);
354
+ }
355
+ /**
356
+ * Retrieve an operation in an OAS by an `operationId`.
357
+ *
358
+ * If an operation does not have an `operationId` one will be generated in place, using the
359
+ * default behavior of `Operation.getOperationId()`, and then asserted against your query.
360
+ *
361
+ * Note that because `operationId`s are unique that uniqueness does include casing so the ID
362
+ * you are looking for will be asserted as an exact match.
363
+ *
364
+ * @see {Operation.getOperationId()}
365
+ * @param id The `operationId` to look up.
366
+ */
367
+ getOperationById(id) {
368
+ let found;
369
+ Object.values(this.getPaths()).forEach((operations) => {
370
+ if (found) return;
371
+ found = Object.values(operations).find((operation) => operation.getOperationId() === id);
372
+ });
373
+ if (found) {
374
+ return found;
375
+ }
376
+ Object.entries(this.getWebhooks()).forEach(([, webhooks]) => {
377
+ if (found) return;
378
+ found = Object.values(webhooks).find((webhook) => webhook.getOperationId() === id);
379
+ });
380
+ return found;
381
+ }
382
+ /**
383
+ * With an object of user information, retrieve the appropriate API auth keys from the current
384
+ * OAS definition.
385
+ *
386
+ * @see {@link https://docs.readme.com/docs/passing-data-to-jwt}
387
+ * @param user User
388
+ * @param selectedApp The user app to retrieve an auth key for.
389
+ */
390
+ getAuth(user, selectedApp) {
391
+ if (!_optionalChain([this, 'access', _16 => _16.api, 'optionalAccess', _17 => _17.components, 'optionalAccess', _18 => _18.securitySchemes])) {
392
+ return {};
393
+ }
394
+ return getAuth(this.api, user, selectedApp);
395
+ }
396
+ /**
397
+ * Determine if a security scheme exists within the API definition.
398
+ *
399
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}
400
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}
401
+ * @param name The name of the security scheme to check for.
402
+ */
403
+ hasSecurityScheme(name) {
404
+ return Boolean(_optionalChain([this, 'access', _19 => _19.api, 'optionalAccess', _20 => _20.components, 'optionalAccess', _21 => _21.securitySchemes, 'optionalAccess', _22 => _22[name]]));
405
+ }
406
+ /**
407
+ * Retrieve a security scheme from the API definition.
408
+ *
409
+ * If the found security scheme is a `$ref` pointer it will be lazily dereferenced; if the scheme
410
+ * cannot be resolved after that process (eg. it's circular or is an invalid `$ref`) then
411
+ * `undefined` will be returned.
412
+ *
413
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}
414
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}
415
+ * @param name The name of the security scheme to retrieve.
416
+ */
417
+ getSecurityScheme(name) {
418
+ if (!this.hasSecurityScheme(name)) {
419
+ return void 0;
420
+ }
421
+ let scheme = _optionalChain([this, 'access', _23 => _23.api, 'optionalAccess', _24 => _24.components, 'optionalAccess', _25 => _25.securitySchemes, 'optionalAccess', _26 => _26[name]]);
422
+ if (!scheme) return void 0;
423
+ if (_chunk7PWF3F2Wcjs.isRef.call(void 0, scheme)) {
424
+ scheme = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, scheme, this.api);
425
+ if (!scheme || _chunk7PWF3F2Wcjs.isRef.call(void 0, scheme)) return void 0;
426
+ }
427
+ return scheme;
428
+ }
429
+ /**
430
+ * Returns the `paths` object that exists in this API definition but with every `method` mapped
431
+ * to an instance of the `Operation` class.
432
+ *
433
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
434
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
435
+ */
436
+ getPaths() {
437
+ const paths = {};
438
+ if (!this.api.paths) {
439
+ return paths;
440
+ }
441
+ Object.keys(this.api.paths).forEach((path) => {
442
+ if (path.startsWith("x-")) {
443
+ return;
444
+ }
445
+ paths[path] = {};
446
+ let pathItem = this.api.paths[path];
447
+ if (!pathItem) {
448
+ return;
449
+ } else if (_chunk7PWF3F2Wcjs.isRef.call(void 0, pathItem)) {
450
+ this.api.paths[path] = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, pathItem, this.api);
451
+ pathItem = this.api.paths[path];
452
+ if (!pathItem || _chunk7PWF3F2Wcjs.isRef.call(void 0, pathItem)) {
453
+ return;
454
+ }
455
+ }
456
+ Object.keys(pathItem).forEach((method) => {
457
+ if (!_chunkUKD63LKGcjs.supportedMethods.includes(method)) {
458
+ return;
459
+ }
460
+ paths[path][method] = this.operation(path, method);
461
+ });
462
+ });
463
+ return paths;
464
+ }
465
+ /**
466
+ * Returns the `webhooks` object that exists in this API definition but with every `method`
467
+ * mapped to an instance of the `Webhook` class.
468
+ *
469
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
470
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
471
+ */
472
+ getWebhooks() {
473
+ const webhooks = {};
474
+ if (!_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.api) || !this.api.webhooks) {
475
+ return webhooks;
476
+ }
477
+ Object.keys(this.api.webhooks).forEach((id) => {
478
+ webhooks[id] = {};
479
+ const webhookPath = _chunkUKD63LKGcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _27 => _27.api, 'access', _28 => _28.webhooks, 'optionalAccess', _29 => _29[id]]), this.api);
480
+ if (webhookPath) {
481
+ Object.keys(webhookPath).forEach((method) => {
482
+ if (!_chunkUKD63LKGcjs.supportedMethods.includes(method)) {
483
+ return;
484
+ }
485
+ webhooks[id][method] = this.operation(id, method, {
486
+ isWebhook: true
487
+ });
488
+ });
489
+ }
490
+ });
491
+ return webhooks;
492
+ }
493
+ /**
494
+ * Return an array of all tag names that exist on this API definition.
495
+ *
496
+ * If the API definition uses the `x-disable-tag-sorting` extension then tags will be returned in
497
+ * the order they're defined.
498
+ *
499
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}
500
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
501
+ * @param setIfMissing If a tag is not present on an operation that operations path will be added
502
+ * into the list of tags returned.
503
+ */
504
+ getTags(setIfMissing = false) {
505
+ const allTags = /* @__PURE__ */ new Set();
506
+ const oasTags = _optionalChain([this, 'access', _30 => _30.api, 'access', _31 => _31.tags, 'optionalAccess', _32 => _32.map, 'call', _33 => _33((tag) => tag.name)]) || [];
507
+ const disableTagSorting = _chunkAYA3UT4Lcjs.getExtension.call(void 0, "disable-tag-sorting", this.api);
508
+ Object.entries(this.getPaths()).forEach(([path, operations]) => {
509
+ Object.values(operations).forEach((operation) => {
510
+ const tags = operation.getTags();
511
+ if (setIfMissing && !tags.length) {
512
+ allTags.add(path);
513
+ return;
514
+ }
515
+ tags.forEach((tag) => {
516
+ allTags.add(tag.name);
517
+ });
518
+ });
519
+ });
520
+ Object.entries(this.getWebhooks()).forEach(([path, webhooks]) => {
521
+ Object.values(webhooks).forEach((webhook) => {
522
+ const tags = webhook.getTags();
523
+ if (setIfMissing && !tags.length) {
524
+ allTags.add(path);
525
+ return;
526
+ }
527
+ tags.forEach((tag) => {
528
+ allTags.add(tag.name);
529
+ });
530
+ });
531
+ });
532
+ const endpointTags = [];
533
+ const tagsArray = [];
534
+ if (disableTagSorting) {
535
+ return Array.from(allTags);
536
+ }
537
+ Array.from(allTags).forEach((tag) => {
538
+ if (oasTags.includes(tag)) {
539
+ tagsArray.push(tag);
540
+ } else {
541
+ endpointTags.push(tag);
542
+ }
543
+ });
544
+ let sortedTags = tagsArray.toSorted((a, b) => {
545
+ return oasTags.indexOf(a) - oasTags.indexOf(b);
546
+ });
547
+ sortedTags = sortedTags.concat(endpointTags);
548
+ return sortedTags;
549
+ }
550
+ /**
551
+ * Determine if a given a custom specification extension exists within the API definition.
552
+ *
553
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
554
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
555
+ * @param extension Specification extension to lookup.
556
+ */
557
+ hasExtension(extension) {
558
+ return _chunkAYA3UT4Lcjs.hasRootExtension.call(void 0, extension, this.api);
559
+ }
560
+ /**
561
+ * Retrieve a custom specification extension off of the API definition.
562
+ *
563
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
564
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
565
+ * @param extension Specification extension to lookup.
566
+ */
567
+ getExtension(extension, operation) {
568
+ return _chunkAYA3UT4Lcjs.getExtension.call(void 0, extension, this.api, operation);
569
+ }
570
+ /**
571
+ * Determine if a given OpenAPI custom extension is valid or not.
572
+ *
573
+ * @see {@link https://docs.readme.com/docs/openapi-extensions}
574
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
575
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
576
+ * @param extension Specification extension to validate.
577
+ * @throws
578
+ */
579
+ validateExtension(extension) {
580
+ if (this.hasExtension("x-readme")) {
581
+ const data = this.getExtension("x-readme");
582
+ if (typeof data !== "object" || Array.isArray(data) || data === null) {
583
+ throw new TypeError('"x-readme" must be of type "Object"');
584
+ }
585
+ if (extension in data) {
586
+ if ([_chunkAYA3UT4Lcjs.CODE_SAMPLES, _chunkAYA3UT4Lcjs.HEADERS, _chunkAYA3UT4Lcjs.PARAMETER_ORDERING, _chunkAYA3UT4Lcjs.SAMPLES_LANGUAGES].includes(extension)) {
587
+ if (data[extension] !== void 0) {
588
+ if (!Array.isArray(data[extension])) {
589
+ throw new TypeError(`"x-readme.${extension}" must be of type "Array"`);
590
+ }
591
+ if (extension === _chunkAYA3UT4Lcjs.PARAMETER_ORDERING) {
592
+ _chunkAYA3UT4Lcjs.validateParameterOrdering.call(void 0, data[extension], `x-readme.${extension}`);
593
+ }
594
+ }
595
+ } else if (extension === _chunkAYA3UT4Lcjs.OAUTH_OPTIONS) {
596
+ if (typeof data[extension] !== "object") {
597
+ throw new TypeError(`"x-readme.${extension}" must be of type "Object"`);
598
+ }
599
+ } else if (typeof data[extension] !== "boolean") {
600
+ throw new TypeError(`"x-readme.${extension}" must be of type "Boolean"`);
601
+ }
602
+ }
603
+ }
604
+ if (this.hasExtension(`x-${extension}`)) {
605
+ const data = this.getExtension(`x-${extension}`);
606
+ if ([_chunkAYA3UT4Lcjs.CODE_SAMPLES, _chunkAYA3UT4Lcjs.HEADERS, _chunkAYA3UT4Lcjs.PARAMETER_ORDERING, _chunkAYA3UT4Lcjs.SAMPLES_LANGUAGES].includes(extension)) {
607
+ if (!Array.isArray(data)) {
608
+ throw new TypeError(`"x-${extension}" must be of type "Array"`);
609
+ }
610
+ if (extension === _chunkAYA3UT4Lcjs.PARAMETER_ORDERING) {
611
+ _chunkAYA3UT4Lcjs.validateParameterOrdering.call(void 0, data, `x-${extension}`);
612
+ }
613
+ } else if (extension === _chunkAYA3UT4Lcjs.OAUTH_OPTIONS) {
614
+ if (typeof data !== "object") {
615
+ throw new TypeError(`"x-${extension}" must be of type "Object"`);
616
+ }
617
+ } else if (typeof data !== "boolean") {
618
+ throw new TypeError(`"x-${extension}" must be of type "Boolean"`);
619
+ }
620
+ }
621
+ }
622
+ /**
623
+ * Validate all of our custom or known OpenAPI extensions, throwing exceptions when necessary.
624
+ *
625
+ * @see {@link https://docs.readme.com/docs/openapi-extensions}
626
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}
627
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}
628
+ */
629
+ validateExtensions() {
630
+ Object.keys(_chunkAYA3UT4Lcjs.extensionDefaults).forEach((extension) => {
631
+ this.validateExtension(extension);
632
+ });
633
+ }
634
+ };
635
+
636
+
637
+ exports.default = Oas;
11
638
 
12
639
  module.exports = exports.default;
13
640
  //# sourceMappingURL=index.cjs.map