@xyd-js/openapi 0.1.0-build.168

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 (64) hide show
  1. package/CHANGELOG.md +1517 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/__fixtures__/-2.complex.openai/input.yaml +39848 -0
  5. package/__fixtures__/-2.complex.openai/output.json +321646 -0
  6. package/__fixtures__/-2.complex.openai/pluginOasOpenai.ts +553 -0
  7. package/__fixtures__/-3.random/input.yaml +234 -0
  8. package/__fixtures__/-3.random/output.json +1140 -0
  9. package/__fixtures__/1.basic/input.yaml +226 -0
  10. package/__fixtures__/1.basic/output.json +1919 -0
  11. package/__fixtures__/2.more/input.yaml +76 -0
  12. package/__fixtures__/2.more/output.json +327 -0
  13. package/__fixtures__/3.multiple-responses/input.yaml +48 -0
  14. package/__fixtures__/3.multiple-responses/output.json +311 -0
  15. package/__fixtures__/5.xdocs.codeLanguages/input.yaml +231 -0
  16. package/__fixtures__/5.xdocs.codeLanguages/output.json +1879 -0
  17. package/__fixtures__/5.xdocs.sidebar/input.yaml +256 -0
  18. package/__fixtures__/5.xdocs.sidebar/output.json +843 -0
  19. package/__fixtures__/6.codeSamples/input.yaml +75 -0
  20. package/__fixtures__/6.codeSamples/output.json +293 -0
  21. package/__tests__/oapSchemaToReferences.test.ts +82 -0
  22. package/__tests__/utils.ts +81 -0
  23. package/dist/index.cjs +2154 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +40 -0
  26. package/dist/index.d.ts +40 -0
  27. package/dist/index.js +2119 -0
  28. package/dist/index.js.map +1 -0
  29. package/examples/basic/index.ts +20 -0
  30. package/examples/basic/index2.ts +36 -0
  31. package/examples/basic/openapi.yaml +124 -0
  32. package/examples/dist/index.cjs +2 -0
  33. package/examples/dist/index.cjs.map +1 -0
  34. package/examples/dist/index.d.cts +2 -0
  35. package/examples/dist/index.d.ts +2 -0
  36. package/examples/dist/index.js +2 -0
  37. package/examples/dist/index.js.map +1 -0
  38. package/examples/semi/index.ts +16 -0
  39. package/examples/semi/openapi.yaml +365 -0
  40. package/examples/semi/references.json +500 -0
  41. package/examples/webhooks/index.ts +16 -0
  42. package/examples/webhooks/openapi.yaml +248 -0
  43. package/examples/webhooks/references.json +895 -0
  44. package/index.ts +12 -0
  45. package/package.json +31 -0
  46. package/src/const.ts +14 -0
  47. package/src/converters/oas-componentSchemas.ts +205 -0
  48. package/src/converters/oas-examples.ts +530 -0
  49. package/src/converters/oas-parameters.ts +41 -0
  50. package/src/converters/oas-paths.ts +354 -0
  51. package/src/converters/oas-requestBody.ts +57 -0
  52. package/src/converters/oas-responses.ts +76 -0
  53. package/src/converters/oas-schema.ts +141 -0
  54. package/src/index.ts +21 -0
  55. package/src/oas-core.ts +579 -0
  56. package/src/types.ts +18 -0
  57. package/src/utils.ts +157 -0
  58. package/src/xdocs/index.ts +18 -0
  59. package/src/xdocs/pluginSidebar.ts +580 -0
  60. package/src/xdocs/types.ts +26 -0
  61. package/tsconfig.json +18 -0
  62. package/tsup.config.ts +19 -0
  63. package/tsup.examples-config.ts +30 -0
  64. package/vitest.config.ts +7 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,2154 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ deferencedOpenAPI: () => deferencedOpenAPI,
34
+ getXDocs: () => getXDocs,
35
+ oapResponseOperationToUniformDefinition: () => oapResponseOperationToUniformDefinition,
36
+ oapSchemaToReferences: () => oapSchemaToReferences,
37
+ uniformPluginXDocsSidebar: () => uniformPluginXDocsSidebar
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/const.ts
42
+ var SUPPORTED_HTTP_METHODS = [
43
+ "get",
44
+ "put",
45
+ "patch",
46
+ "post",
47
+ "delete"
48
+ // 'options',
49
+ // 'head',
50
+ // 'trace'
51
+ ];
52
+ var BUILT_IN_PROPERTIES = {
53
+ "__internal_getRefPath": true
54
+ };
55
+
56
+ // src/oas-core.ts
57
+ var import_uniform = require("@xyd-js/uniform");
58
+ function schemaObjectToUniformDefinitionProperties(schemaObject, rootProperty, visitedRefs) {
59
+ var _a, _b;
60
+ if ("$ref" in schemaObject) {
61
+ console.warn("Reference objects are not supported in schemaObjectToUniformDefinitionProperties");
62
+ return null;
63
+ }
64
+ const properties = [];
65
+ if ("anyOf" in schemaObject && schemaObject.anyOf) {
66
+ const property = schemaObjectToUniformDefinitionProperty("", schemaObject, false, false, visitedRefs);
67
+ if (property) {
68
+ if (rootProperty) {
69
+ return property;
70
+ }
71
+ properties.push(property);
72
+ }
73
+ } else if ("oneOf" in schemaObject && schemaObject.oneOf) {
74
+ const property = schemaObjectToUniformDefinitionProperty("", schemaObject, false, false, visitedRefs);
75
+ if (property) {
76
+ if (rootProperty) {
77
+ return property;
78
+ }
79
+ properties.push(property);
80
+ }
81
+ } else if ("allOf" in schemaObject && schemaObject.allOf) {
82
+ const componentPaths = [];
83
+ for (const schema of schemaObject.allOf) {
84
+ if ("$ref" in schema) {
85
+ console.warn("$ref is not supported in allOf schemas");
86
+ continue;
87
+ }
88
+ const oasSchema2 = schema;
89
+ if (oasSchema2.__internal_getRefPath) {
90
+ const refPath = oasSchema2.__internal_getRefPath();
91
+ if (typeof refPath === "string") {
92
+ componentPaths.push(refPath);
93
+ } else if (Array.isArray(refPath)) {
94
+ componentPaths.push(...refPath);
95
+ } else {
96
+ console.warn("Invalid refPath type in allOf schema", oasSchema2);
97
+ }
98
+ }
99
+ if ("properties" in schema && schema.properties) {
100
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
101
+ if (BUILT_IN_PROPERTIES[propName]) {
102
+ continue;
103
+ }
104
+ if ("$ref" in propSchema) {
105
+ console.warn("$ref is not supported in allOf properties");
106
+ continue;
107
+ }
108
+ const property = schemaObjectToUniformDefinitionProperty(
109
+ propName,
110
+ propSchema,
111
+ (_a = schema.required) == null ? void 0 : _a.includes(propName),
112
+ (propSchema == null ? void 0 : propSchema.type) === "array" ? true : false,
113
+ visitedRefs
114
+ );
115
+ if (property) {
116
+ const existingPropertyIndex = properties.findIndex((p) => p.name === propName);
117
+ if (existingPropertyIndex >= 0) {
118
+ const existingProperty = properties[existingPropertyIndex];
119
+ properties[existingPropertyIndex] = {
120
+ ...existingProperty,
121
+ ...property,
122
+ description: property.description || existingProperty.description || "",
123
+ meta: [...existingProperty.meta || [], ...property.meta || []]
124
+ };
125
+ } else {
126
+ properties.push(property);
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ const oasSchema = schemaObject;
133
+ oasSchema.__internal_getRefPath = () => componentPaths;
134
+ } else if ("properties" in schemaObject && schemaObject.properties) {
135
+ for (const [propName, propSchema] of Object.entries(schemaObject.properties)) {
136
+ if (BUILT_IN_PROPERTIES[propName]) {
137
+ continue;
138
+ }
139
+ if (typeof propSchema === "object" && "$ref" in propSchema) {
140
+ console.warn("$ref is not supported in properties");
141
+ continue;
142
+ }
143
+ const property = schemaObjectToUniformDefinitionProperty(
144
+ propName,
145
+ propSchema,
146
+ (_b = schemaObject.required) == null ? void 0 : _b.includes(propName),
147
+ (propSchema == null ? void 0 : propSchema.type) === "array" ? true : false,
148
+ visitedRefs
149
+ );
150
+ if (property) {
151
+ properties.push(property);
152
+ }
153
+ }
154
+ }
155
+ return properties;
156
+ }
157
+ function schemaObjectToUniformDefinitionProperty(name, schema, required, arrayOf, visitedRefs, parentProperty) {
158
+ var _a, _b, _c, _d;
159
+ if (name === "__UNSAFE_refPath") {
160
+ return null;
161
+ }
162
+ if (!schema) return null;
163
+ if (!visitedRefs) {
164
+ visitedRefs = /* @__PURE__ */ new Map();
165
+ }
166
+ let refPath = "";
167
+ if ("__UNSAFE_refPath" in schema && typeof schema.__UNSAFE_refPath === "function") {
168
+ refPath = schema.__UNSAFE_refPath();
169
+ const defProp = visitedRefs.get(refPath);
170
+ if (defProp) {
171
+ return JSON.parse(JSON.stringify(defProp));
172
+ }
173
+ }
174
+ if (parentProperty) {
175
+ visitedRefs.set(refPath, parentProperty);
176
+ }
177
+ if ("anyOf" in schema && schema.anyOf) {
178
+ const componentPaths = [];
179
+ const properties = [];
180
+ for (const variantSchema of schema.anyOf) {
181
+ if ("$ref" in variantSchema) {
182
+ console.warn("$ref is not supported in anyOf schemas");
183
+ continue;
184
+ }
185
+ const oasSchema2 = variantSchema;
186
+ if (oasSchema2.__internal_getRefPath) {
187
+ const refPath2 = oasSchema2.__internal_getRefPath();
188
+ if (typeof refPath2 === "string") {
189
+ componentPaths.push(refPath2);
190
+ } else if (Array.isArray(refPath2)) {
191
+ componentPaths.push(...refPath2);
192
+ } else {
193
+ console.warn("Invalid refPath type in anyOf schema", oasSchema2);
194
+ }
195
+ }
196
+ const property2 = schemaObjectToUniformDefinitionProperty(name, variantSchema, required, false, visitedRefs);
197
+ if (property2) {
198
+ if (isMergeType(property2.type)) {
199
+ properties.push(...property2.properties || []);
200
+ } else {
201
+ properties.push({
202
+ ...property2,
203
+ name: variantSchema.title || property2.name || ""
204
+ });
205
+ }
206
+ }
207
+ }
208
+ const oasSchema = schema;
209
+ oasSchema.__internal_getRefPath = () => componentPaths;
210
+ const prop = {
211
+ name,
212
+ type: import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.UNION,
213
+ description: schema.description || "",
214
+ properties
215
+ };
216
+ if (refPath) {
217
+ visitedRefs.set(refPath, prop);
218
+ }
219
+ return prop;
220
+ }
221
+ const meta = schemaObjectToUniformDefinitionPropertyMeta({
222
+ ...schema,
223
+ required: required ? [name] : void 0
224
+ }, name);
225
+ if ("oneOf" in schema && schema.oneOf) {
226
+ const componentPaths = [];
227
+ const properties = [];
228
+ for (const variantSchema of schema.oneOf) {
229
+ if ("$ref" in variantSchema) {
230
+ console.warn("$ref is not supported in oneOf schemas");
231
+ continue;
232
+ }
233
+ const oasSchema2 = variantSchema;
234
+ if (oasSchema2.__internal_getRefPath) {
235
+ const refPath2 = oasSchema2.__internal_getRefPath();
236
+ if (typeof refPath2 === "string") {
237
+ componentPaths.push(refPath2);
238
+ } else if (Array.isArray(refPath2)) {
239
+ componentPaths.push(...refPath2);
240
+ } else {
241
+ console.warn("Invalid refPath type in allOf schema", oasSchema2);
242
+ }
243
+ }
244
+ const property2 = schemaObjectToUniformDefinitionProperty(name, variantSchema, required, false, visitedRefs);
245
+ if (property2) {
246
+ properties.push({
247
+ ...property2,
248
+ name: variantSchema.title || property2.name || ""
249
+ });
250
+ }
251
+ }
252
+ const oasSchema = schema;
253
+ oasSchema.__internal_getRefPath = () => componentPaths;
254
+ const prop = {
255
+ name,
256
+ type: import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.XOR,
257
+ description: schema.description || "",
258
+ properties,
259
+ meta
260
+ };
261
+ if (refPath) {
262
+ visitedRefs.set(refPath, prop);
263
+ }
264
+ return prop;
265
+ }
266
+ if ("allOf" in schema && schema.allOf) {
267
+ const componentPaths = [];
268
+ const mergedProperty = {
269
+ name,
270
+ type: schema.type || "",
271
+ description: schema.description || "",
272
+ properties: [],
273
+ meta
274
+ };
275
+ for (const variantSchema of schema.allOf) {
276
+ if ("$ref" in variantSchema) {
277
+ console.warn("$ref is not supported in allOf schemas");
278
+ continue;
279
+ }
280
+ const oasSchema2 = variantSchema;
281
+ if (oasSchema2.__internal_getRefPath) {
282
+ const refPath2 = oasSchema2.__internal_getRefPath();
283
+ if (typeof refPath2 === "string") {
284
+ componentPaths.push(refPath2);
285
+ } else if (Array.isArray(refPath2)) {
286
+ componentPaths.push(...refPath2);
287
+ } else {
288
+ console.warn("Invalid refPath type in allOf schema", oasSchema2);
289
+ }
290
+ }
291
+ if (!mergedProperty.type) {
292
+ if (typeof variantSchema.type === "string") {
293
+ mergedProperty.type = variantSchema.type || "";
294
+ }
295
+ }
296
+ if ("properties" in variantSchema && variantSchema.properties) {
297
+ for (const [propName, propSchema] of Object.entries(variantSchema.properties)) {
298
+ if (BUILT_IN_PROPERTIES[propName]) {
299
+ continue;
300
+ }
301
+ if ("$ref" in propSchema) {
302
+ console.warn("$ref is not supported in allOf properties");
303
+ continue;
304
+ }
305
+ const property2 = schemaObjectToUniformDefinitionProperty(
306
+ propName,
307
+ propSchema,
308
+ (_a = variantSchema.required) == null ? void 0 : _a.includes(propName),
309
+ false,
310
+ visitedRefs
311
+ );
312
+ if (property2 && mergedProperty.properties) {
313
+ const existingPropertyIndex = mergedProperty.properties.findIndex((p) => p.name === propName);
314
+ if (existingPropertyIndex >= 0) {
315
+ const existingProperty = mergedProperty.properties[existingPropertyIndex];
316
+ mergedProperty.properties[existingPropertyIndex] = {
317
+ ...existingProperty,
318
+ ...property2,
319
+ description: property2.description || existingProperty.description || "",
320
+ meta: [...existingProperty.meta || [], ...property2.meta || []]
321
+ };
322
+ } else {
323
+ mergedProperty.properties.push(property2);
324
+ }
325
+ }
326
+ }
327
+ } else {
328
+ const property2 = schemaObjectToUniformDefinitionProperty(
329
+ "",
330
+ variantSchema,
331
+ false,
332
+ false,
333
+ visitedRefs
334
+ );
335
+ if (property2) {
336
+ if (isOfType(property2.type)) {
337
+ mergedProperty.ofProperty = property2;
338
+ } else {
339
+ if (!((_b = mergedProperty.properties) == null ? void 0 : _b.length)) {
340
+ mergedProperty.properties = [];
341
+ }
342
+ if (mergedProperty.ofProperty) {
343
+ mergedProperty.description = property2.description || mergedProperty.ofProperty.description || "";
344
+ } else {
345
+ mergedProperty.properties.push(property2);
346
+ }
347
+ }
348
+ }
349
+ }
350
+ }
351
+ const oasSchema = schema;
352
+ oasSchema.__internal_getRefPath = () => componentPaths;
353
+ if (refPath) {
354
+ visitedRefs.set(refPath, mergedProperty);
355
+ }
356
+ return mergedProperty;
357
+ }
358
+ const property = {
359
+ name,
360
+ type: schema.type || "object",
361
+ description: schema.description || "",
362
+ meta
363
+ };
364
+ if (schema.enum) {
365
+ const enumProperties = schemaObjectToUniformDefinitionProperties({
366
+ properties: schema.enum.reduce((acc, enumName) => ({
367
+ ...acc,
368
+ [enumName]: {
369
+ type: schema.type
370
+ }
371
+ }), {})
372
+ });
373
+ if (!Array.isArray(enumProperties)) {
374
+ return property;
375
+ }
376
+ meta.push({
377
+ name: "enum-type",
378
+ value: schema.type
379
+ });
380
+ const enumProperty = {
381
+ name,
382
+ type: import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.ENUM,
383
+ description: schema.description || "",
384
+ meta,
385
+ properties: enumProperties || []
386
+ };
387
+ if (refPath) {
388
+ visitedRefs.set(refPath, enumProperty);
389
+ }
390
+ return enumProperty;
391
+ } else {
392
+ if ("properties" in schema && schema.properties) {
393
+ property.properties = [];
394
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
395
+ if (BUILT_IN_PROPERTIES[propName]) {
396
+ continue;
397
+ }
398
+ if ("$ref" in propSchema) {
399
+ console.warn("$ref is not supported in properties");
400
+ continue;
401
+ }
402
+ const nestedProperty = schemaObjectToUniformDefinitionProperty(
403
+ propName,
404
+ propSchema,
405
+ (_c = schema.required) == null ? void 0 : _c.includes(propName),
406
+ (propSchema == null ? void 0 : propSchema.type) === "array" ? true : false,
407
+ visitedRefs
408
+ );
409
+ if (nestedProperty) {
410
+ property.properties.push(nestedProperty);
411
+ }
412
+ }
413
+ } else if (schema.type === "array" && schema.items && !("$ref" in schema.items)) {
414
+ const arrayProperty = {
415
+ name,
416
+ type: import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
417
+ description: schema.description || "",
418
+ meta,
419
+ properties: []
420
+ };
421
+ const itemsProperty = schemaObjectToUniformDefinitionProperty("", schema.items, required, true, visitedRefs, arrayProperty);
422
+ if (itemsProperty) {
423
+ if (arrayOf || isOfType(itemsProperty.type) || ((_d = itemsProperty.ofProperty) == null ? void 0 : _d.type)) {
424
+ arrayProperty.ofProperty = {
425
+ name: "",
426
+ type: itemsProperty.type,
427
+ properties: itemsProperty.properties || [],
428
+ description: itemsProperty.description || "",
429
+ meta: itemsProperty.meta || [],
430
+ ofProperty: itemsProperty.ofProperty || void 0
431
+ };
432
+ } else {
433
+ arrayProperty.properties = [itemsProperty];
434
+ }
435
+ }
436
+ if (refPath) {
437
+ visitedRefs.set(refPath, arrayProperty);
438
+ }
439
+ return arrayProperty;
440
+ }
441
+ }
442
+ if (arrayOf) {
443
+ const prop = {
444
+ type: property.type,
445
+ name: "",
446
+ description: "",
447
+ ofProperty: property
448
+ };
449
+ if (refPath) {
450
+ visitedRefs.set(refPath, prop);
451
+ }
452
+ }
453
+ if (refPath) {
454
+ visitedRefs.set(refPath, property);
455
+ }
456
+ return property;
457
+ }
458
+ function schemaObjectToUniformDefinitionPropertyMeta(objProp, name) {
459
+ const meta = [];
460
+ if (!objProp) {
461
+ return meta;
462
+ }
463
+ if (typeof objProp.required === "boolean" && objProp.required) {
464
+ meta.push({
465
+ name: "required",
466
+ value: "true"
467
+ });
468
+ } else if (Array.isArray(objProp.required)) {
469
+ for (const req of objProp.required) {
470
+ if (req === name) {
471
+ meta.push({
472
+ name: "required",
473
+ value: "true"
474
+ });
475
+ }
476
+ }
477
+ }
478
+ if (objProp.deprecated) {
479
+ meta.push({
480
+ name: "deprecated",
481
+ value: "true"
482
+ });
483
+ }
484
+ if ("default" in objProp) {
485
+ meta.push({
486
+ name: "defaults",
487
+ value: objProp.default
488
+ });
489
+ }
490
+ if ("nullable" in objProp) {
491
+ meta.push({
492
+ name: "nullable",
493
+ value: "true"
494
+ });
495
+ }
496
+ if ("example" in objProp) {
497
+ const example = typeof objProp.example === "object" ? JSON.stringify(objProp.example) : objProp.example;
498
+ meta.push({
499
+ name: "example",
500
+ value: example
501
+ });
502
+ }
503
+ if ("examples" in objProp) {
504
+ meta.push({
505
+ name: "examples",
506
+ value: objProp.examples
507
+ });
508
+ }
509
+ if ("maximum" in objProp) {
510
+ meta.push({
511
+ name: "maximum",
512
+ value: objProp.maximum
513
+ });
514
+ }
515
+ if ("minimum" in objProp) {
516
+ meta.push({
517
+ name: "minimum",
518
+ value: objProp.minimum
519
+ });
520
+ }
521
+ return meta;
522
+ }
523
+ function isMergeType(type) {
524
+ return type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.XOR || type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.UNION;
525
+ }
526
+ function isOfType(type) {
527
+ return type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.XOR || type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.UNION || type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY;
528
+ }
529
+
530
+ // src/converters/oas-parameters.ts
531
+ function oapParametersToDefinitionProperties(parameters) {
532
+ const parameterIn = {};
533
+ parameters.forEach((param) => {
534
+ if (!parameterIn[param.in]) {
535
+ parameterIn[param.in] = [];
536
+ }
537
+ const schema = param.schema;
538
+ const meta = [
539
+ ...schemaObjectToUniformDefinitionPropertyMeta(schema, param.name) || [],
540
+ ...schemaObjectToUniformDefinitionPropertyMeta(param, param.name) || []
541
+ ];
542
+ let oapV2Type = "";
543
+ if ("type" in param) {
544
+ oapV2Type = param.type;
545
+ }
546
+ const property = {
547
+ name: param.name,
548
+ type: (schema == null ? void 0 : schema.type) || oapV2Type || "",
549
+ description: param.description || "",
550
+ meta
551
+ };
552
+ parameterIn[param.in].push(property);
553
+ });
554
+ return parameterIn;
555
+ }
556
+
557
+ // src/converters/oas-paths.ts
558
+ var import_uniform5 = require("@xyd-js/uniform");
559
+
560
+ // src/converters/oas-requestBody.ts
561
+ var import_uniform2 = require("@xyd-js/uniform");
562
+ function oapRequestBodyToDefinitionProperties(reqBody, contentType) {
563
+ const schema = reqBody.content[contentType].schema;
564
+ if (!schema) {
565
+ return null;
566
+ }
567
+ let schemaObject;
568
+ if (schema.allOf || schema.anyOf || schema.oneOf) {
569
+ return schemaObjectToUniformDefinitionProperties(schema);
570
+ }
571
+ let array = false;
572
+ switch (schema.type) {
573
+ case "object": {
574
+ schemaObject = schema;
575
+ break;
576
+ }
577
+ case "array": {
578
+ const arrSchema = schema;
579
+ const items = arrSchema.items;
580
+ schemaObject = items;
581
+ array = true;
582
+ break;
583
+ }
584
+ default:
585
+ break;
586
+ }
587
+ if (!schemaObject) {
588
+ return null;
589
+ }
590
+ const properties = schemaObjectToUniformDefinitionProperties(schemaObject);
591
+ if (array) {
592
+ return {
593
+ type: import_uniform2.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
594
+ properties
595
+ };
596
+ }
597
+ return properties;
598
+ }
599
+
600
+ // src/converters/oas-responses.ts
601
+ var import_uniform3 = require("@xyd-js/uniform");
602
+ function oasResponseToDefinitionProperties(responses, code, contentType) {
603
+ var _a;
604
+ let schemaObject;
605
+ let responseObject;
606
+ if (responses[code]) {
607
+ responseObject = responses[code];
608
+ if (!(responseObject == null ? void 0 : responseObject.content)) {
609
+ return null;
610
+ }
611
+ schemaObject = (_a = responseObject == null ? void 0 : responseObject.content[contentType]) == null ? void 0 : _a.schema;
612
+ }
613
+ if (!schemaObject) {
614
+ return {
615
+ properties: [
616
+ {
617
+ description: (responseObject == null ? void 0 : responseObject.description) || "",
618
+ name: "",
619
+ type: ""
620
+ }
621
+ ]
622
+ };
623
+ }
624
+ let array = false;
625
+ switch (schemaObject.type) {
626
+ case "array":
627
+ const arrSchema = schemaObject;
628
+ const items = arrSchema.items;
629
+ schemaObject = items;
630
+ array = true;
631
+ default:
632
+ break;
633
+ }
634
+ const properties = schemaObjectToUniformDefinitionProperties(schemaObject, true);
635
+ let description = "";
636
+ if (schemaObject.allOf) {
637
+ for (const item of schemaObject.allOf) {
638
+ if ("description" in item) {
639
+ description += item.description + "\n";
640
+ }
641
+ }
642
+ }
643
+ if (array) {
644
+ return {
645
+ properties: {
646
+ type: import_uniform3.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
647
+ properties
648
+ }
649
+ };
650
+ }
651
+ return {
652
+ properties: properties || [],
653
+ description: description || ""
654
+ };
655
+ }
656
+
657
+ // src/utils.ts
658
+ var import_path = __toESM(require("path"), 1);
659
+ var import_promises = __toESM(require("fs/promises"), 1);
660
+ var import_js_yaml = __toESM(require("js-yaml"), 1);
661
+
662
+ // ../../node_modules/.pnpm/github-slugger@2.0.0/node_modules/github-slugger/regex.js
663
+ var regex = /[\0-\x1F!-,\.\/:-@\[-\^`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482\u0530\u0557\u0558\u055A-\u055F\u0589-\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05EB-\u05EE\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06DE\u06E9\u06FD\u06FE\u0700-\u070F\u074B\u074C\u07B2-\u07BF\u07F6-\u07F9\u07FB\u07FC\u07FE\u07FF\u082E-\u083F\u085C-\u085F\u086B-\u089F\u08B5\u08C8-\u08D2\u08E2\u0964\u0965\u0970\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09F2-\u09FB\u09FD\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF0-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B70\u0B72-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BF0-\u0BFF\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B-\u0C5F\u0C64\u0C65\u0C70-\u0C7F\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D4F-\u0D53\u0D58-\u0D5E\u0D64\u0D65\u0D70-\u0D79\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF4-\u0E00\u0E3B-\u0E3F\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F17\u0F1A-\u0F1F\u0F2A-\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F48\u0F6D-\u0F70\u0F85\u0F98\u0FBD-\u0FC5\u0FC7-\u0FFF\u104A-\u104F\u109E\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u1360-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u170D\u1715-\u171F\u1735-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17D4-\u17D6\u17D8-\u17DB\u17DE\u17DF\u17EA-\u180A\u180E\u180F\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DA-\u19FF\u1A1C-\u1A1F\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1AAF\u1AC1-\u1AFF\u1B4C-\u1B4F\u1B5A-\u1B6A\u1B74-\u1B7F\u1BF4-\u1BFF\u1C38-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CCF\u1CD3\u1CFB-\u1CFF\u1DFA\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u203E\u2041-\u2053\u2055-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u20CF\u20F1-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u215F\u2189-\u24B5\u24EA-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E00-\u2E2E\u2E30-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u3040\u3097\u3098\u309B\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA673\uA67E\uA6F2-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA828-\uA82B\uA82D-\uA83F\uA874-\uA87F\uA8C6-\uA8CF\uA8DA-\uA8DF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA954-\uA95F\uA97D-\uA97F\uA9C1-\uA9CE\uA9DA-\uA9DF\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A-\uAA5F\uAA77-\uAA79\uAAC3-\uAADA\uAADE\uAADF\uAAF0\uAAF1\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F\uABEB\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uD7FF\uE000-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB29\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBB2-\uFBD2\uFD3E-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFC-\uFDFF\uFE10-\uFE1F\uFE30-\uFE32\uFE35-\uFE4C\uFE50-\uFE6F\uFE75\uFEFD-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF3E\uFF40\uFF5B-\uFF65\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFFF]|\uD800[\uDC0C\uDC27\uDC3B\uDC3E\uDC4E\uDC4F\uDC5E-\uDC7F\uDCFB-\uDD3F\uDD75-\uDDFC\uDDFE-\uDE7F\uDE9D-\uDE9F\uDED1-\uDEDF\uDEE1-\uDEFF\uDF20-\uDF2C\uDF4B-\uDF4F\uDF7B-\uDF7F\uDF9E\uDF9F\uDFC4-\uDFC7\uDFD0\uDFD6-\uDFFF]|\uD801[\uDC9E\uDC9F\uDCAA-\uDCAF\uDCD4-\uDCD7\uDCFC-\uDCFF\uDD28-\uDD2F\uDD64-\uDDFF\uDF37-\uDF3F\uDF56-\uDF5F\uDF68-\uDFFF]|\uD802[\uDC06\uDC07\uDC09\uDC36\uDC39-\uDC3B\uDC3D\uDC3E\uDC56-\uDC5F\uDC77-\uDC7F\uDC9F-\uDCDF\uDCF3\uDCF6-\uDCFF\uDD16-\uDD1F\uDD3A-\uDD7F\uDDB8-\uDDBD\uDDC0-\uDDFF\uDE04\uDE07-\uDE0B\uDE14\uDE18\uDE36\uDE37\uDE3B-\uDE3E\uDE40-\uDE5F\uDE7D-\uDE7F\uDE9D-\uDEBF\uDEC8\uDEE7-\uDEFF\uDF36-\uDF3F\uDF56-\uDF5F\uDF73-\uDF7F\uDF92-\uDFFF]|\uD803[\uDC49-\uDC7F\uDCB3-\uDCBF\uDCF3-\uDCFF\uDD28-\uDD2F\uDD3A-\uDE7F\uDEAA\uDEAD-\uDEAF\uDEB2-\uDEFF\uDF1D-\uDF26\uDF28-\uDF2F\uDF51-\uDFAF\uDFC5-\uDFDF\uDFF7-\uDFFF]|\uD804[\uDC47-\uDC65\uDC70-\uDC7E\uDCBB-\uDCCF\uDCE9-\uDCEF\uDCFA-\uDCFF\uDD35\uDD40-\uDD43\uDD48-\uDD4F\uDD74\uDD75\uDD77-\uDD7F\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDFF\uDE12\uDE38-\uDE3D\uDE3F-\uDE7F\uDE87\uDE89\uDE8E\uDE9E\uDEA9-\uDEAF\uDEEB-\uDEEF\uDEFA-\uDEFF\uDF04\uDF0D\uDF0E\uDF11\uDF12\uDF29\uDF31\uDF34\uDF3A\uDF45\uDF46\uDF49\uDF4A\uDF4E\uDF4F\uDF51-\uDF56\uDF58-\uDF5C\uDF64\uDF65\uDF6D-\uDF6F\uDF75-\uDFFF]|\uD805[\uDC4B-\uDC4F\uDC5A-\uDC5D\uDC62-\uDC7F\uDCC6\uDCC8-\uDCCF\uDCDA-\uDD7F\uDDB6\uDDB7\uDDC1-\uDDD7\uDDDE-\uDDFF\uDE41-\uDE43\uDE45-\uDE4F\uDE5A-\uDE7F\uDEB9-\uDEBF\uDECA-\uDEFF\uDF1B\uDF1C\uDF2C-\uDF2F\uDF3A-\uDFFF]|\uD806[\uDC3B-\uDC9F\uDCEA-\uDCFE\uDD07\uDD08\uDD0A\uDD0B\uDD14\uDD17\uDD36\uDD39\uDD3A\uDD44-\uDD4F\uDD5A-\uDD9F\uDDA8\uDDA9\uDDD8\uDDD9\uDDE2\uDDE5-\uDDFF\uDE3F-\uDE46\uDE48-\uDE4F\uDE9A-\uDE9C\uDE9E-\uDEBF\uDEF9-\uDFFF]|\uD807[\uDC09\uDC37\uDC41-\uDC4F\uDC5A-\uDC71\uDC90\uDC91\uDCA8\uDCB7-\uDCFF\uDD07\uDD0A\uDD37-\uDD39\uDD3B\uDD3E\uDD48-\uDD4F\uDD5A-\uDD5F\uDD66\uDD69\uDD8F\uDD92\uDD99-\uDD9F\uDDAA-\uDEDF\uDEF7-\uDFAF\uDFB1-\uDFFF]|\uD808[\uDF9A-\uDFFF]|\uD809[\uDC6F-\uDC7F\uDD44-\uDFFF]|[\uD80A\uD80B\uD80E-\uD810\uD812-\uD819\uD824-\uD82B\uD82D\uD82E\uD830-\uD833\uD837\uD839\uD83D\uD83F\uD87B-\uD87D\uD87F\uD885-\uDB3F\uDB41-\uDBFF][\uDC00-\uDFFF]|\uD80D[\uDC2F-\uDFFF]|\uD811[\uDE47-\uDFFF]|\uD81A[\uDE39-\uDE3F\uDE5F\uDE6A-\uDECF\uDEEE\uDEEF\uDEF5-\uDEFF\uDF37-\uDF3F\uDF44-\uDF4F\uDF5A-\uDF62\uDF78-\uDF7C\uDF90-\uDFFF]|\uD81B[\uDC00-\uDE3F\uDE80-\uDEFF\uDF4B-\uDF4E\uDF88-\uDF8E\uDFA0-\uDFDF\uDFE2\uDFE5-\uDFEF\uDFF2-\uDFFF]|\uD821[\uDFF8-\uDFFF]|\uD823[\uDCD6-\uDCFF\uDD09-\uDFFF]|\uD82C[\uDD1F-\uDD4F\uDD53-\uDD63\uDD68-\uDD6F\uDEFC-\uDFFF]|\uD82F[\uDC6B-\uDC6F\uDC7D-\uDC7F\uDC89-\uDC8F\uDC9A-\uDC9C\uDC9F-\uDFFF]|\uD834[\uDC00-\uDD64\uDD6A-\uDD6C\uDD73-\uDD7A\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDE41\uDE45-\uDFFF]|\uD835[\uDC55\uDC9D\uDCA0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3\uDFCC\uDFCD]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE9A\uDEA0\uDEB0-\uDFFF]|\uD838[\uDC07\uDC19\uDC1A\uDC22\uDC25\uDC2B-\uDCFF\uDD2D-\uDD2F\uDD3E\uDD3F\uDD4A-\uDD4D\uDD4F-\uDEBF\uDEFA-\uDFFF]|\uD83A[\uDCC5-\uDCCF\uDCD7-\uDCFF\uDD4C-\uDD4F\uDD5A-\uDFFF]|\uD83B[\uDC00-\uDDFF\uDE04\uDE20\uDE23\uDE25\uDE26\uDE28\uDE33\uDE38\uDE3A\uDE3C-\uDE41\uDE43-\uDE46\uDE48\uDE4A\uDE4C\uDE50\uDE53\uDE55\uDE56\uDE58\uDE5A\uDE5C\uDE5E\uDE60\uDE63\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDD2F\uDD4A-\uDD4F\uDD6A-\uDD6F\uDD8A-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEDE-\uDEFF]|\uD86D[\uDF35-\uDF3F]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEA2-\uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|\uDB40[\uDC00-\uDCFF\uDDF0-\uDFFF]/g;
664
+
665
+ // ../../node_modules/.pnpm/github-slugger@2.0.0/node_modules/github-slugger/index.js
666
+ var own = Object.hasOwnProperty;
667
+ var BananaSlug = class {
668
+ /**
669
+ * Create a new slug class.
670
+ */
671
+ constructor() {
672
+ this.occurrences;
673
+ this.reset();
674
+ }
675
+ /**
676
+ * Generate a unique slug.
677
+ *
678
+ * Tracks previously generated slugs: repeated calls with the same value
679
+ * will result in different slugs.
680
+ * Use the `slug` function to get same slugs.
681
+ *
682
+ * @param {string} value
683
+ * String of text to slugify
684
+ * @param {boolean} [maintainCase=false]
685
+ * Keep the current case, otherwise make all lowercase
686
+ * @return {string}
687
+ * A unique slug string
688
+ */
689
+ slug(value, maintainCase) {
690
+ const self = this;
691
+ let result = slug(value, maintainCase === true);
692
+ const originalSlug = result;
693
+ while (own.call(self.occurrences, result)) {
694
+ self.occurrences[originalSlug]++;
695
+ result = originalSlug + "-" + self.occurrences[originalSlug];
696
+ }
697
+ self.occurrences[result] = 0;
698
+ return result;
699
+ }
700
+ /**
701
+ * Reset - Forget all previous slugs
702
+ *
703
+ * @return void
704
+ */
705
+ reset() {
706
+ this.occurrences = /* @__PURE__ */ Object.create(null);
707
+ }
708
+ };
709
+ function slug(value, maintainCase) {
710
+ if (typeof value !== "string") return "";
711
+ if (!maintainCase) value = value.toLowerCase();
712
+ return value.replace(regex, "").replace(/ /g, "-");
713
+ }
714
+
715
+ // src/utils.ts
716
+ var import_json_schema_ref_parser = __toESM(require("@apidevtools/json-schema-ref-parser"), 1);
717
+ var import_uniform4 = require("@xyd-js/uniform");
718
+ function slug2(str) {
719
+ const slugger = new BananaSlug();
720
+ return slugger.slug(str);
721
+ }
722
+ async function deferencedOpenAPI(openApiPath) {
723
+ const openApiSpec = await readOpenApiSpec(openApiPath);
724
+ if (!openApiSpec) {
725
+ return;
726
+ }
727
+ const cwd = process.cwd();
728
+ const remoteOasPath = openApiPath.startsWith("http://") || openApiPath.startsWith("https://") ? true : false;
729
+ const circularRefs = /* @__PURE__ */ new Set();
730
+ const options = {
731
+ dereference: {
732
+ onCircular(defPath) {
733
+ const v = `#${defPath.split("#")[1]}`;
734
+ circularRefs.add(v);
735
+ },
736
+ // circular: true, // ignore circular references,
737
+ // onCi
738
+ onDereference(defPath, value, parent) {
739
+ if (circularRefs.has(defPath) || circularRefs.has(import_path.default.join(defPath, "properties"))) {
740
+ value.__UNSAFE_circular = true;
741
+ }
742
+ if (value && typeof value === "object") {
743
+ value.__UNSAFE_refPath = () => defPath;
744
+ }
745
+ if (parent && typeof parent === "object") {
746
+ parent.__UNSAFE_refPath = () => defPath;
747
+ }
748
+ }
749
+ }
750
+ };
751
+ if (remoteOasPath) {
752
+ if (!options.resolve) {
753
+ options.resolve = {};
754
+ }
755
+ options.resolve.file = {
756
+ read: async (file) => {
757
+ let rel = import_path.default.relative(cwd, file.url);
758
+ rel = rel.split(import_path.default.sep).join("/");
759
+ const absoluteUrl = new URL(rel, openApiPath).href;
760
+ const res = await fetch(absoluteUrl);
761
+ if (!res.ok) {
762
+ throw new Error(`Failed to fetch ${absoluteUrl}: ${res.status}`);
763
+ }
764
+ let content;
765
+ if (file.extension === ".json" || file.extension === ".yaml" || file.extension === ".yml") {
766
+ if (file.extension === ".json") {
767
+ content = await res.json();
768
+ } else {
769
+ content = import_js_yaml.default.load(await res.text());
770
+ }
771
+ } else {
772
+ content = await res.text();
773
+ }
774
+ return content;
775
+ }
776
+ };
777
+ }
778
+ await import_json_schema_ref_parser.default.dereference(openApiSpec, options);
779
+ return openApiSpec;
780
+ }
781
+ async function readOpenApiSpec(filePath) {
782
+ let content;
783
+ let fromUrl = false;
784
+ if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
785
+ const response = await fetch(filePath);
786
+ if (!response.ok) {
787
+ throw new Error(`Failed to fetch OpenAPI spec from URL: ${response.statusText}`);
788
+ }
789
+ content = await response.text();
790
+ fromUrl = true;
791
+ } else {
792
+ try {
793
+ await import_promises.default.access(filePath);
794
+ } catch (error) {
795
+ console.log(`\u26A0\uFE0F "(openapi): ${filePath}" is defined in the docs.json navigation but the file does not exist.`);
796
+ return;
797
+ }
798
+ content = await import_promises.default.readFile(filePath, "utf-8");
799
+ }
800
+ const ext = import_path.default.extname(filePath).toLowerCase();
801
+ if (ext === ".yaml" || ext === ".yml") {
802
+ return import_js_yaml.default.load(content);
803
+ } else if (ext === ".json") {
804
+ return JSON.parse(content);
805
+ } else if (fromUrl && content.startsWith("{")) {
806
+ try {
807
+ return JSON.parse(content);
808
+ } catch (error) {
809
+ throw new Error(`Failed to parse JSON from URL: ${error}`);
810
+ }
811
+ } else {
812
+ throw new Error("Unsupported file format. Use JSON or YAML.");
813
+ }
814
+ }
815
+ function httpMethodToUniformMethod(method) {
816
+ switch (method) {
817
+ case "get":
818
+ return import_uniform4.ReferenceType.REST_HTTP_GET;
819
+ case "put":
820
+ return import_uniform4.ReferenceType.REST_HTTP_PUT;
821
+ case "patch":
822
+ return import_uniform4.ReferenceType.REST_HTTP_PATCH;
823
+ case "post":
824
+ return import_uniform4.ReferenceType.REST_HTTP_POST;
825
+ case "delete":
826
+ return import_uniform4.ReferenceType.REST_HTTP_DELETE;
827
+ case "options":
828
+ return import_uniform4.ReferenceType.REST_HTTP_OPTIONS;
829
+ case "head":
830
+ return import_uniform4.ReferenceType.REST_HTTP_HEAD;
831
+ case "trace":
832
+ return import_uniform4.ReferenceType.REST_HTTP_TRACE;
833
+ default:
834
+ return null;
835
+ }
836
+ }
837
+
838
+ // src/converters/oas-paths.ts
839
+ var import_node_path = __toESM(require("path"), 1);
840
+ function oapPathToReference(schema, httpMethod, path4, oapPath) {
841
+ const mType = httpMethodToUniformMethod(httpMethod);
842
+ if (!mType) {
843
+ console.error(`Unsupported method: ${httpMethod}`);
844
+ return null;
845
+ }
846
+ const definitions = [];
847
+ const exampleGroups = [];
848
+ const oapMethod = oapPath == null ? void 0 : oapPath[httpMethod];
849
+ if (!oapMethod) {
850
+ return null;
851
+ }
852
+ const tag = getFirstTag(oapMethod);
853
+ const group = [tag];
854
+ const endpointRef = {
855
+ title: title(oapMethod, httpMethod, path4),
856
+ canonical: canonical(oapMethod, httpMethod, path4),
857
+ description: (oapMethod == null ? void 0 : oapMethod.description) || (oapMethod == null ? void 0 : oapMethod.summary),
858
+ type: mType,
859
+ category: import_uniform5.ReferenceCategory.REST,
860
+ context: {
861
+ method: httpMethod,
862
+ path: `${encodeURIComponent(path4)}`,
863
+ fullPath: path4,
864
+ group
865
+ },
866
+ examples: {
867
+ groups: exampleGroups
868
+ },
869
+ definitions
870
+ };
871
+ if (oapMethod.parameters) {
872
+ const parameters = oapMethod.parameters;
873
+ const paramtersMap = oapParametersToDefinitionProperties(parameters);
874
+ Object.entries(paramtersMap).forEach(([key, definitionProperties]) => {
875
+ let title2;
876
+ switch (key) {
877
+ case "path":
878
+ title2 = "Path parameters";
879
+ break;
880
+ case "query":
881
+ title2 = "Query parameters";
882
+ break;
883
+ case "header":
884
+ title2 = "Headers";
885
+ break;
886
+ default:
887
+ console.error(`Unsupported parameter type: ${key} for ${httpMethod} ${path4}`);
888
+ return;
889
+ }
890
+ definitions.push({
891
+ title: title2,
892
+ properties: definitionProperties
893
+ });
894
+ });
895
+ }
896
+ definitions.push(...oapOperationToDefinitions(oapMethod));
897
+ endpointRef.__UNSAFE_selector = function __UNSAFE_selector(selector) {
898
+ switch (selector) {
899
+ case "[schema]": {
900
+ return schema;
901
+ }
902
+ case "[method]": {
903
+ return {
904
+ oapPath,
905
+ httpMethod,
906
+ path: path4
907
+ };
908
+ }
909
+ case "[method] [path]": {
910
+ return oapMethod;
911
+ }
912
+ default:
913
+ return null;
914
+ }
915
+ };
916
+ return endpointRef;
917
+ }
918
+ function oapOperationToDefinitions(oapMethod) {
919
+ const definitions = [];
920
+ if (oapMethod.requestBody) {
921
+ const definition = oapRequestOperationToUniformDefinition(oapMethod);
922
+ definitions.push(definition);
923
+ }
924
+ if (oapMethod.responses) {
925
+ const definition = oapResponseOperationToUniformDefinition(oapMethod);
926
+ definitions.push(definition);
927
+ }
928
+ return definitions;
929
+ }
930
+ function oapRequestOperationToUniformDefinition(oapOperation) {
931
+ var _a;
932
+ const reqBody = oapOperation.requestBody;
933
+ const variants = [];
934
+ for (const contentType of Object.keys(reqBody.content)) {
935
+ const schema = (_a = reqBody.content[contentType]) == null ? void 0 : _a.schema;
936
+ let properties = [];
937
+ let rootProperty;
938
+ let propertiesResp = oapRequestBodyToDefinitionProperties(reqBody, contentType) || [];
939
+ if (Array.isArray(propertiesResp)) {
940
+ properties = propertiesResp;
941
+ } else {
942
+ rootProperty = propertiesResp;
943
+ }
944
+ const meta2 = [
945
+ {
946
+ name: "contentType",
947
+ value: contentType || ""
948
+ }
949
+ ];
950
+ if (schema == null ? void 0 : schema.required) {
951
+ meta2.push({
952
+ name: "required",
953
+ value: schema.required ? "true" : "false"
954
+ });
955
+ }
956
+ variants.push({
957
+ title: contentType,
958
+ description: schema.description || "",
959
+ properties,
960
+ rootProperty,
961
+ meta: meta2,
962
+ symbolDef: definitionPropertyTypeDef(schema)
963
+ });
964
+ }
965
+ const meta = [];
966
+ if (reqBody.required) {
967
+ meta.push({
968
+ name: "required",
969
+ value: "true"
970
+ });
971
+ }
972
+ return {
973
+ title: "Request body",
974
+ variants,
975
+ properties: [],
976
+ meta
977
+ };
978
+ }
979
+ function oapResponseOperationToUniformDefinition(oapOperation) {
980
+ const responses = oapOperation.responses;
981
+ const variants = [];
982
+ Object.keys(responses).forEach((code) => {
983
+ var _a;
984
+ const responseObject = responses[code];
985
+ if (!(responseObject == null ? void 0 : responseObject.content)) {
986
+ variants.push({
987
+ title: code,
988
+ description: responseObject.description,
989
+ properties: [],
990
+ meta: [
991
+ {
992
+ name: "status",
993
+ value: code || ""
994
+ }
995
+ ]
996
+ });
997
+ return null;
998
+ }
999
+ const contentTypes = Object.keys(responseObject.content);
1000
+ for (const contentType of contentTypes) {
1001
+ let properties = [];
1002
+ let rootProperty;
1003
+ const schema = (_a = responseObject.content[contentType]) == null ? void 0 : _a.schema;
1004
+ const respProperties = oasResponseToDefinitionProperties(responses, code, contentType) || [];
1005
+ if (respProperties && "properties" in respProperties && (respProperties == null ? void 0 : respProperties.properties)) {
1006
+ if (Array.isArray(respProperties.properties)) {
1007
+ properties = respProperties.properties;
1008
+ } else {
1009
+ rootProperty = respProperties.properties;
1010
+ }
1011
+ }
1012
+ let definitionDescription = "";
1013
+ if ("description" in respProperties) {
1014
+ definitionDescription = respProperties.description || "";
1015
+ }
1016
+ variants.push({
1017
+ title: code,
1018
+ description: responseObject.description,
1019
+ properties,
1020
+ rootProperty,
1021
+ meta: [
1022
+ {
1023
+ name: "status",
1024
+ value: code || ""
1025
+ },
1026
+ {
1027
+ name: "contentType",
1028
+ value: contentType || ""
1029
+ },
1030
+ {
1031
+ name: "definitionDescription",
1032
+ value: definitionDescription
1033
+ }
1034
+ ],
1035
+ symbolDef: definitionPropertyTypeDef(schema)
1036
+ });
1037
+ }
1038
+ });
1039
+ return {
1040
+ title: "Response",
1041
+ variants,
1042
+ properties: []
1043
+ };
1044
+ }
1045
+ function definitionPropertyTypeDef(schema) {
1046
+ if (!schema) {
1047
+ return;
1048
+ }
1049
+ let typeDef;
1050
+ let oasSchema = schema;
1051
+ if (oasSchema.type === "array") {
1052
+ oasSchema = oasSchema.items;
1053
+ }
1054
+ if (oasSchema == null ? void 0 : oasSchema.__internal_getRefPath) {
1055
+ const symbolId = oasSchema.__internal_getRefPath();
1056
+ typeDef = {
1057
+ id: symbolId
1058
+ };
1059
+ }
1060
+ return typeDef;
1061
+ }
1062
+ function title(oapMethod, httpMethod, httpPath) {
1063
+ const tit = (oapMethod == null ? void 0 : oapMethod.summary) || oapMethod.operationId || "";
1064
+ if (tit) {
1065
+ return tit;
1066
+ }
1067
+ if (!httpMethod || !httpPath) {
1068
+ throw new Error("httpMethod and path are required to generate title");
1069
+ }
1070
+ return import_node_path.default.join(httpMethod, cleanPath(httpPath));
1071
+ }
1072
+ function canonical(oapMethod, httpMethod, httpPath) {
1073
+ let canon = oapMethod.operationId || slug2((oapMethod == null ? void 0 : oapMethod.summary) || "");
1074
+ if (canon) {
1075
+ return canon;
1076
+ }
1077
+ if (!httpMethod || !httpPath) {
1078
+ throw new Error("httpMethod and path are required to generate canonical");
1079
+ }
1080
+ return import_node_path.default.join(httpMethod, cleanPath(httpPath));
1081
+ }
1082
+ function getFirstTag(oapMethod) {
1083
+ for (const tag of (oapMethod == null ? void 0 : oapMethod.tags) || []) {
1084
+ return tag;
1085
+ }
1086
+ return "";
1087
+ }
1088
+ function cleanPath(httpPath) {
1089
+ return httpPath.replace(/\{([^}]+)\}/g, "$1");
1090
+ }
1091
+
1092
+ // src/converters/oas-schema.ts
1093
+ var import_node_path2 = __toESM(require("path"), 1);
1094
+ var import_oas = __toESM(require("oas"), 1);
1095
+
1096
+ // src/converters/oas-examples.ts
1097
+ var import_oas_to_snippet = __toESM(require("@readme/oas-to-snippet"), 1);
1098
+ var import_openapi_sampler = require("@xyd-js/openapi-sampler");
1099
+
1100
+ // src/xdocs/index.ts
1101
+ function xDocsLanguages(oasDoc) {
1102
+ const xDocs = getXDocs(oasDoc);
1103
+ if (!xDocs) {
1104
+ return null;
1105
+ }
1106
+ return (xDocs == null ? void 0 : xDocs.codeLanguages) ?? null;
1107
+ }
1108
+ function getXDocs(oasDoc) {
1109
+ if (!("x-docs" in oasDoc)) {
1110
+ return null;
1111
+ }
1112
+ return oasDoc["x-docs"];
1113
+ }
1114
+
1115
+ // src/converters/oas-examples.ts
1116
+ var DEFAULT_CODE_LANGUAGES = ["shell", "javascript", "python", "go"];
1117
+ function oapExamples(oas, operation, visitedExamples) {
1118
+ const exampleGroups = [
1119
+ ...reqExamples(operation, oas, visitedExamples),
1120
+ ...resBodyExmaples(operation, oas, visitedExamples)
1121
+ ];
1122
+ return exampleGroups;
1123
+ }
1124
+ function langFallback(lang) {
1125
+ const langLower = lang.toLowerCase();
1126
+ switch (langLower) {
1127
+ case "curl": {
1128
+ return "shell";
1129
+ }
1130
+ }
1131
+ return langLower;
1132
+ }
1133
+ function reqExamples(operation, oas, vistedExamples) {
1134
+ const exampleGroups = [];
1135
+ const examples = [];
1136
+ const tabs = [];
1137
+ if (operation.schema["x-codeSamples"]) {
1138
+ const codeSamples = operation.schema["x-codeSamples"];
1139
+ const groupedByLabel = /* @__PURE__ */ new Map();
1140
+ codeSamples.forEach((sample) => {
1141
+ const label = sample.label || "default";
1142
+ if (!groupedByLabel.has(label)) {
1143
+ groupedByLabel.set(label, []);
1144
+ }
1145
+ groupedByLabel.get(label).push(sample);
1146
+ });
1147
+ groupedByLabel.forEach((samples, label) => {
1148
+ const codeSampleTabs = samples.map((sample) => ({
1149
+ title: sample.lang,
1150
+ language: langFallback(sample.lang),
1151
+ code: sample.source
1152
+ }));
1153
+ if (codeSampleTabs.length > 0) {
1154
+ examples.push({
1155
+ codeblock: {
1156
+ title: label === "default" ? "Example request" : label,
1157
+ tabs: codeSampleTabs
1158
+ }
1159
+ });
1160
+ }
1161
+ });
1162
+ if (examples.length > 0) {
1163
+ exampleGroups.push({
1164
+ description: "Example request",
1165
+ examples
1166
+ });
1167
+ return exampleGroups;
1168
+ }
1169
+ }
1170
+ const paramData = operation.schema.parameters ? operation.schema.parameters.reduce((acc, param) => {
1171
+ const location = param.in || "query";
1172
+ if (!acc[location]) {
1173
+ acc[location] = {};
1174
+ }
1175
+ let value = param.example;
1176
+ if (!value && param.schema) {
1177
+ value = (0, import_openapi_sampler.sample)(sanitizeSchema(param.schema));
1178
+ }
1179
+ if (value !== void 0) {
1180
+ acc[location][param.name] = value;
1181
+ }
1182
+ return acc;
1183
+ }, {}) : {};
1184
+ let bodyData = {};
1185
+ if (operation.schema.requestBody) {
1186
+ const body = operation.schema.requestBody;
1187
+ const contentTypes = Object.keys(body.content);
1188
+ if (contentTypes.length > 0) {
1189
+ const contentType = contentTypes[contentTypes.length - 1];
1190
+ const content = body.content[contentType];
1191
+ let schema = content == null ? void 0 : content.schema;
1192
+ if (schema) {
1193
+ schema = fixAllOfBug(schema);
1194
+ schema = sanitizeSchema(schema);
1195
+ let requestData;
1196
+ if (content.examples) {
1197
+ const requestExample = content.examples["request"];
1198
+ if (requestExample && "value" in requestExample) {
1199
+ requestData = requestExample.value;
1200
+ }
1201
+ }
1202
+ if (!requestData) {
1203
+ requestData = sampleFromSchema(schema);
1204
+ }
1205
+ if (contentType === "application/x-www-form-urlencoded") {
1206
+ bodyData = { formData: requestData };
1207
+ } else {
1208
+ bodyData = { body: requestData };
1209
+ }
1210
+ }
1211
+ }
1212
+ }
1213
+ const hasRequestBody = operation.schema.requestBody !== void 0;
1214
+ const hasParameters = Object.keys(paramData).length > 0;
1215
+ if (hasParameters || hasRequestBody || !hasRequestBody && !hasParameters) {
1216
+ const langs = xDocsLanguages(operation.api) || DEFAULT_CODE_LANGUAGES;
1217
+ langs.forEach((lang) => {
1218
+ var _a, _b, _c;
1219
+ let snippetOperation = operation;
1220
+ const v = (_c = (_b = (_a = operation == null ? void 0 : operation.api) == null ? void 0 : _a.paths) == null ? void 0 : _b[operation == null ? void 0 : operation.path]) == null ? void 0 : _c[operation == null ? void 0 : operation.method];
1221
+ if (v) {
1222
+ snippetOperation = fixCircularReferences(v);
1223
+ }
1224
+ const { code } = (0, import_oas_to_snippet.default)(oas, snippetOperation, {
1225
+ ...paramData,
1226
+ ...bodyData
1227
+ }, null, lang);
1228
+ tabs.push({
1229
+ title: lang,
1230
+ language: lang,
1231
+ code: code || ""
1232
+ });
1233
+ });
1234
+ if (tabs.length > 0) {
1235
+ examples.push({
1236
+ codeblock: {
1237
+ tabs
1238
+ }
1239
+ });
1240
+ }
1241
+ if (examples.length > 0) {
1242
+ exampleGroups.push({
1243
+ description: "Example request",
1244
+ examples
1245
+ });
1246
+ }
1247
+ }
1248
+ return exampleGroups;
1249
+ }
1250
+ function resBodyExmaples(operation, oas, vistedExamples) {
1251
+ const exampleGroups = [];
1252
+ if (operation.schema.responses) {
1253
+ const responses = operation.schema.responses;
1254
+ const examples = [];
1255
+ Object.entries(responses).forEach(([status, r]) => {
1256
+ const response = r;
1257
+ if (!response.content) {
1258
+ return;
1259
+ }
1260
+ const contentTypes = Object.keys(response.content);
1261
+ if (contentTypes.length === 0) {
1262
+ return;
1263
+ }
1264
+ const tabs = [];
1265
+ for (const contentType of contentTypes) {
1266
+ const content = response.content[contentType];
1267
+ const schema = content == null ? void 0 : content.schema;
1268
+ if (!schema) {
1269
+ continue;
1270
+ }
1271
+ let responseData;
1272
+ if (content.examples) {
1273
+ const responseExample = content.examples["response"];
1274
+ if (responseExample && "value" in responseExample) {
1275
+ responseData = responseExample.value;
1276
+ } else {
1277
+ const namedExamples = [];
1278
+ const exampleNames = Object.keys(content.examples);
1279
+ exampleNames.forEach((exampleName) => {
1280
+ var _a;
1281
+ const data = (_a = content == null ? void 0 : content.examples) == null ? void 0 : _a[exampleName];
1282
+ if (!data || !("value" in data) || typeof data.value != "object") {
1283
+ return;
1284
+ }
1285
+ namedExamples.push({
1286
+ description: "",
1287
+ codeblock: {
1288
+ title: exampleName,
1289
+ tabs: [
1290
+ {
1291
+ title: "application/json",
1292
+ // TODO: support multiple types
1293
+ language: "json",
1294
+ code: JSON.stringify(data.value, null, 2) || ""
1295
+ }
1296
+ ]
1297
+ }
1298
+ });
1299
+ });
1300
+ if (namedExamples.length === 1) {
1301
+ const firstCodeblock = namedExamples[0].codeblock;
1302
+ tabs.push(
1303
+ ...firstCodeblock.tabs.map((tab) => ({
1304
+ ...tab,
1305
+ title: contentType
1306
+ }))
1307
+ );
1308
+ } else {
1309
+ exampleGroups.push({
1310
+ description: "",
1311
+ examples: namedExamples
1312
+ });
1313
+ }
1314
+ continue;
1315
+ }
1316
+ } else if (content.example) {
1317
+ responseData = content.example;
1318
+ }
1319
+ if (!responseData) {
1320
+ responseData = sampleFromSchema(schema);
1321
+ }
1322
+ let extension = "text";
1323
+ switch (contentType) {
1324
+ case "application/json":
1325
+ case "application/problem+json":
1326
+ case "application/vnd.api+json": {
1327
+ extension = "json";
1328
+ break;
1329
+ }
1330
+ case "application/xml":
1331
+ case "text/xml":
1332
+ case "application/problem+xml": {
1333
+ extension = "xml";
1334
+ break;
1335
+ }
1336
+ }
1337
+ tabs.push({
1338
+ title: contentType,
1339
+ language: extension,
1340
+ code: JSON.stringify(responseData, null, 2) || ""
1341
+ });
1342
+ }
1343
+ if (tabs.length > 0) {
1344
+ examples.push({
1345
+ codeblock: {
1346
+ title: status,
1347
+ tabs
1348
+ }
1349
+ });
1350
+ }
1351
+ });
1352
+ if (examples.length > 0) {
1353
+ exampleGroups.push({
1354
+ description: "Example response",
1355
+ examples
1356
+ });
1357
+ }
1358
+ }
1359
+ return exampleGroups;
1360
+ }
1361
+ function fixAllOfBug(schema) {
1362
+ const modifiedSchema = { ...schema };
1363
+ if (schema == null ? void 0 : schema.allOf) {
1364
+ schema.allOf.forEach((prop, i) => {
1365
+ var _a;
1366
+ const propObj = prop;
1367
+ if ("properties" in propObj && !propObj["properties"]) {
1368
+ (_a = modifiedSchema.allOf) == null ? true : delete _a[i];
1369
+ }
1370
+ });
1371
+ }
1372
+ return modifiedSchema;
1373
+ }
1374
+ function sanitizeSchema(schema, vistedExamples = /* @__PURE__ */ new Map(), parent) {
1375
+ if (vistedExamples.has(schema)) {
1376
+ const cached = vistedExamples.get(schema);
1377
+ if (typeof cached === "object") {
1378
+ return JSON.parse(JSON.stringify(cached));
1379
+ }
1380
+ return cached;
1381
+ }
1382
+ if (parent) {
1383
+ vistedExamples.set(schema, parent);
1384
+ }
1385
+ if (!schema || typeof schema !== "object") {
1386
+ vistedExamples.set(schema, schema);
1387
+ return schema;
1388
+ }
1389
+ if (Array.isArray(schema)) {
1390
+ const v = schema.map((item) => sanitizeSchema(item, vistedExamples));
1391
+ vistedExamples.set(schema, v);
1392
+ return v;
1393
+ }
1394
+ const cleaned = {};
1395
+ for (const [key, value] of Object.entries(schema)) {
1396
+ if (key === "__UNSAFE_refPath") {
1397
+ continue;
1398
+ }
1399
+ if (!BUILT_IN_PROPERTIES[key]) {
1400
+ cleaned[key] = sanitizeSchema(value, vistedExamples, cleaned);
1401
+ }
1402
+ }
1403
+ vistedExamples.set(schema, cleaned);
1404
+ return cleaned;
1405
+ }
1406
+ function sampleFromSchema(schema) {
1407
+ var _a, _b;
1408
+ let jsonSchema = null;
1409
+ let multiSpec = null;
1410
+ if ((_a = schema.oneOf) == null ? void 0 : _a.length) {
1411
+ multiSpec = schema.oneOf;
1412
+ } else if ((_b = schema.anyOf) == null ? void 0 : _b.length) {
1413
+ multiSpec = schema.anyOf;
1414
+ }
1415
+ if (multiSpec == null ? void 0 : multiSpec.length) {
1416
+ for (let i = multiSpec.length - 1; i >= 0; i--) {
1417
+ const spec = multiSpec[i];
1418
+ const sanitized = sanitizeSchema(spec);
1419
+ if (!sanitized) {
1420
+ continue;
1421
+ }
1422
+ jsonSchema = sanitized;
1423
+ if (!(jsonSchema == null ? void 0 : jsonSchema.properties)) {
1424
+ continue;
1425
+ }
1426
+ break;
1427
+ }
1428
+ } else {
1429
+ jsonSchema = sanitizeSchema(schema);
1430
+ }
1431
+ if (jsonSchema) {
1432
+ return (0, import_openapi_sampler.sample)(jsonSchema);
1433
+ }
1434
+ return null;
1435
+ }
1436
+ function fixCircularReferences(schema, visited = /* @__PURE__ */ new WeakMap()) {
1437
+ if (!schema || typeof schema !== "object") {
1438
+ return schema;
1439
+ }
1440
+ if (visited.has(schema)) {
1441
+ return visited.get(schema);
1442
+ }
1443
+ if (schema.__UNSAFE_circular) {
1444
+ const simplified = {
1445
+ type: "object",
1446
+ description: "Circular reference detected - schema simplified"
1447
+ };
1448
+ visited.set(schema, simplified);
1449
+ return simplified;
1450
+ }
1451
+ if (Array.isArray(schema)) {
1452
+ const result = schema.map((item) => fixCircularReferences(item, visited));
1453
+ visited.set(schema, result);
1454
+ return result;
1455
+ }
1456
+ const fixedSchema = {};
1457
+ visited.set(schema, fixedSchema);
1458
+ for (const [key, value] of Object.entries(schema)) {
1459
+ if (key === "__UNSAFE_circular" || key === "__UNSAFE_refPath") {
1460
+ continue;
1461
+ }
1462
+ if (typeof value === "object" && value !== null) {
1463
+ fixedSchema[key] = fixCircularReferences(value, visited);
1464
+ } else {
1465
+ fixedSchema[key] = value;
1466
+ }
1467
+ }
1468
+ return fixedSchema;
1469
+ }
1470
+
1471
+ // src/converters/oas-componentSchemas.ts
1472
+ var import_uniform6 = require("@xyd-js/uniform");
1473
+ function schemaComponentsToUniformReferences(openapi, options) {
1474
+ var _a;
1475
+ const references = [];
1476
+ if (!((_a = openapi.components) == null ? void 0 : _a.schemas)) {
1477
+ return references;
1478
+ }
1479
+ for (const [componentSchemaName, componentSchema] of Object.entries(openapi.components.schemas)) {
1480
+ if ((options == null ? void 0 : options.regions) && options.regions.length > 0) {
1481
+ if (!options.regions.some((region) => region === "/components/schemas/" + componentSchemaName)) {
1482
+ continue;
1483
+ }
1484
+ }
1485
+ if ("$ref" in componentSchema) {
1486
+ console.warn(`Skipping reference object: ${componentSchemaName}`);
1487
+ continue;
1488
+ }
1489
+ let properties = [];
1490
+ let rootProperty = void 0;
1491
+ const respProperties = schemaObjectToUniformDefinitionProperties(componentSchema, false) || [];
1492
+ if (Array.isArray(respProperties)) {
1493
+ properties = respProperties;
1494
+ } else {
1495
+ rootProperty = respProperties;
1496
+ }
1497
+ const symbolDef = definitionPropertyTypeDef2(componentSchema);
1498
+ const definition = {
1499
+ title: componentSchemaName,
1500
+ properties,
1501
+ rootProperty,
1502
+ meta: [],
1503
+ symbolDef
1504
+ };
1505
+ const reference = {
1506
+ title: componentSchemaName,
1507
+ description: componentSchema.description || "",
1508
+ canonical: `objects/${componentSchemaName}`,
1509
+ definitions: [definition],
1510
+ examples: {
1511
+ groups: createSchemaExampleGroup(componentSchema)
1512
+ },
1513
+ type: import_uniform6.ReferenceType.REST_COMPONENT_SCHEMA,
1514
+ context: {
1515
+ componentSchema: componentSchemaName,
1516
+ group: ["Objects"]
1517
+ }
1518
+ };
1519
+ reference.__UNSAFE_selector = function __UNSAFE_selector(selector) {
1520
+ switch (selector) {
1521
+ case "[schema]": {
1522
+ return openapi;
1523
+ }
1524
+ case "[component]": {
1525
+ return componentSchema;
1526
+ }
1527
+ default:
1528
+ return null;
1529
+ }
1530
+ };
1531
+ references.push(reference);
1532
+ }
1533
+ return references;
1534
+ }
1535
+ function createSchemaExampleGroup(schema, map) {
1536
+ const example = generateSchemaExample(schema);
1537
+ if (!example) {
1538
+ return [];
1539
+ }
1540
+ const tabs = [{
1541
+ title: "json",
1542
+ language: "json",
1543
+ code: JSON.stringify(example, null, 2)
1544
+ }];
1545
+ return [{
1546
+ description: "Example",
1547
+ examples: [{
1548
+ codeblock: {
1549
+ tabs
1550
+ }
1551
+ }]
1552
+ }];
1553
+ }
1554
+ function definitionPropertyTypeDef2(schema) {
1555
+ if (!schema) {
1556
+ return;
1557
+ }
1558
+ let typeDef;
1559
+ let oasSchema = schema;
1560
+ if (oasSchema.type === "array") {
1561
+ oasSchema = oasSchema.items;
1562
+ }
1563
+ if (oasSchema == null ? void 0 : oasSchema.__internal_getRefPath) {
1564
+ const symbolId = oasSchema.__internal_getRefPath();
1565
+ typeDef = {
1566
+ id: symbolId
1567
+ };
1568
+ }
1569
+ return typeDef;
1570
+ }
1571
+ function generateSchemaExample(schema, visitedExample, parent) {
1572
+ if (!schema) {
1573
+ return null;
1574
+ }
1575
+ if (!visitedExample) {
1576
+ visitedExample = /* @__PURE__ */ new Map();
1577
+ }
1578
+ const cached = visitedExample.get(schema);
1579
+ if (cached) {
1580
+ return JSON.parse(JSON.stringify(cached));
1581
+ }
1582
+ if (parent) {
1583
+ visitedExample.set(schema, parent);
1584
+ }
1585
+ if ("examples" in schema && Array.isArray(schema.examples)) {
1586
+ const v = schema.examples[0];
1587
+ visitedExample.set(schema, v);
1588
+ return v;
1589
+ }
1590
+ if ("example" in schema && schema.example !== void 0) {
1591
+ const v = schema.example;
1592
+ visitedExample.set(schema, v);
1593
+ return v;
1594
+ }
1595
+ if (schema.type === "object" && schema.properties) {
1596
+ const result = {};
1597
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
1598
+ result[propName] = generateSchemaExample(propSchema, visitedExample, result);
1599
+ }
1600
+ visitedExample.set(schema, result);
1601
+ return result;
1602
+ }
1603
+ if (schema.type === "array" && schema.items) {
1604
+ const itemExample = generateSchemaExample(schema.items, visitedExample);
1605
+ const v = itemExample ? [itemExample] : [];
1606
+ visitedExample.set(schema, v);
1607
+ return v;
1608
+ }
1609
+ switch (schema.type) {
1610
+ case "string":
1611
+ return "";
1612
+ case "number":
1613
+ case "integer":
1614
+ return 0;
1615
+ case "boolean":
1616
+ return false;
1617
+ default:
1618
+ return null;
1619
+ }
1620
+ }
1621
+
1622
+ // src/converters/oas-schema.ts
1623
+ function oapSchemaToReferences(schema, options) {
1624
+ var _a, _b;
1625
+ if (!schema) {
1626
+ return [];
1627
+ }
1628
+ const references = [];
1629
+ const oas = new import_oas.default(schema);
1630
+ const server = ((_b = (_a = schema.servers) == null ? void 0 : _a[0]) == null ? void 0 : _b.url) || "";
1631
+ Object.entries(schema.paths).forEach(([endpointPath, oapPath]) => {
1632
+ SUPPORTED_HTTP_METHODS.forEach((eachMethod) => {
1633
+ var _a2, _b2, _c, _d;
1634
+ const httpMethod = eachMethod.toLowerCase();
1635
+ const found = httpMethodToUniformMethod(httpMethod);
1636
+ if (!found) {
1637
+ console.warn(`Unsupported method: ${httpMethod} for path: ${endpointPath}`);
1638
+ return;
1639
+ }
1640
+ if ((options == null ? void 0 : options.regions) && options.regions.length > 0) {
1641
+ const regionKey = `${eachMethod.toUpperCase()} ${endpointPath}`;
1642
+ if (!options.regions.some((region) => region === regionKey)) {
1643
+ return;
1644
+ }
1645
+ }
1646
+ const reference = oapPathToReference(
1647
+ schema,
1648
+ httpMethod,
1649
+ endpointPath,
1650
+ oapPath
1651
+ );
1652
+ if (reference) {
1653
+ const ctx = reference.context;
1654
+ ctx.path = endpointPath;
1655
+ ctx.fullPath = import_node_path2.default.join(server, endpointPath);
1656
+ const operation = oas.operation(endpointPath, httpMethod);
1657
+ reference.examples.groups = oapExamples(oas, operation);
1658
+ const scopes = [];
1659
+ const oapMethod = oapPath == null ? void 0 : oapPath[httpMethod];
1660
+ if ((_a2 = schema == null ? void 0 : schema.security) == null ? void 0 : _a2.length) {
1661
+ for (const security of schema.security) {
1662
+ for (const securityKey of Object.keys(security)) {
1663
+ if (securityKey === "oauth2" || securityKey === "OAuth2") {
1664
+ const securityScopes = security[securityKey];
1665
+ if (Array.isArray(securityScopes)) {
1666
+ scopes.push(...securityScopes);
1667
+ }
1668
+ }
1669
+ }
1670
+ }
1671
+ }
1672
+ if (oapMethod == null ? void 0 : oapMethod.security) {
1673
+ if (!((_b2 = oapMethod == null ? void 0 : oapMethod.security) == null ? void 0 : _b2.length)) {
1674
+ scopes.length = 0;
1675
+ }
1676
+ for (const security of oapMethod.security) {
1677
+ for (const securityKey of Object.keys(security)) {
1678
+ const securityScheme = (_d = (_c = schema == null ? void 0 : schema.components) == null ? void 0 : _c.securitySchemes) == null ? void 0 : _d[securityKey];
1679
+ if (securityScheme && "type" in securityScheme && securityScheme.type === "oauth2") {
1680
+ const methodScopes = security[securityKey];
1681
+ if (Array.isArray(methodScopes)) {
1682
+ scopes.push(...methodScopes);
1683
+ }
1684
+ }
1685
+ }
1686
+ }
1687
+ }
1688
+ ctx.scopes = scopes;
1689
+ references.push(reference);
1690
+ }
1691
+ });
1692
+ });
1693
+ const schemas = schemaComponentsToUniformReferences(
1694
+ schema,
1695
+ options
1696
+ );
1697
+ references.push(...schemas);
1698
+ const tags = oas.getTags();
1699
+ sortReferencesByTags(references, tags);
1700
+ references.__internal_options = () => options;
1701
+ return references;
1702
+ }
1703
+ function sortReferencesByTags(references, tags) {
1704
+ return references.sort((prev, next) => {
1705
+ var _a, _b;
1706
+ const aTags = ((_a = prev.context) == null ? void 0 : _a.group) || [];
1707
+ const bTags = ((_b = next.context) == null ? void 0 : _b.group) || [];
1708
+ for (const tag of tags) {
1709
+ const aIndex = aTags.indexOf(tag);
1710
+ const bIndex = bTags.indexOf(tag);
1711
+ if (aIndex !== -1 && bIndex !== -1) {
1712
+ return aIndex - bIndex;
1713
+ }
1714
+ if (aIndex !== -1) return -1;
1715
+ if (bIndex !== -1) return 1;
1716
+ }
1717
+ return (aTags[0] || "").localeCompare(bTags[0] || "");
1718
+ });
1719
+ }
1720
+
1721
+ // src/xdocs/pluginSidebar.ts
1722
+ function uniformPluginXDocsSidebar({
1723
+ references,
1724
+ defer
1725
+ }) {
1726
+ let schema;
1727
+ const refByOperationId = {};
1728
+ const refByComponentSchema = {};
1729
+ defer(() => {
1730
+ var _a;
1731
+ if (typeof references.__internal_options === "function") {
1732
+ const options = references.__internal_options();
1733
+ if ((_a = options == null ? void 0 : options.regions) == null ? void 0 : _a.length) {
1734
+ return {};
1735
+ }
1736
+ }
1737
+ const output = [];
1738
+ if (!schema) {
1739
+ return {};
1740
+ }
1741
+ const xDocs = schema["x-docs"];
1742
+ if (!(xDocs == null ? void 0 : xDocs.sidebar)) {
1743
+ return {};
1744
+ }
1745
+ const navigationMap = {};
1746
+ for (let i = 0; i < xDocs.sidebar.length; i++) {
1747
+ const navGroup = xDocs.sidebar[i];
1748
+ if (!navGroup) {
1749
+ continue;
1750
+ }
1751
+ const uniqueKey = `${navGroup.group}-${i}`;
1752
+ navigationMap[uniqueKey] = {
1753
+ id: navGroup.group,
1754
+ title: navGroup.group,
1755
+ beta: false,
1756
+ index: i
1757
+ };
1758
+ }
1759
+ for (let i = 0; i < xDocs.sidebar.length; i++) {
1760
+ const group = xDocs.sidebar[i];
1761
+ const uniqueKey = `${group.group}-${i}`;
1762
+ const navGroup = navigationMap[uniqueKey];
1763
+ if (!navGroup) {
1764
+ console.warn(`No navigation group found for group: ${group.group}`);
1765
+ continue;
1766
+ }
1767
+ if (!Array.isArray(group.pages)) {
1768
+ continue;
1769
+ }
1770
+ processGroupPages(xDocs, group.pages, [group.group], navGroup, output);
1771
+ }
1772
+ if (Array.isArray(references)) {
1773
+ references.length = 0;
1774
+ references.push(...output);
1775
+ } else {
1776
+ references = output[0] || references;
1777
+ }
1778
+ return {};
1779
+ });
1780
+ function processGroupPages(xDocs, pages, groupPath, navGroup, output, parentPath) {
1781
+ for (const page of pages) {
1782
+ if ("pages" in page && Array.isArray(page.pages)) {
1783
+ processGroupPages(xDocs, page.pages, [...groupPath, page.group], navGroup, output, page.path);
1784
+ } else if ("type" in page && "key" in page) {
1785
+ processPage(xDocs, page, groupPath, navGroup, output, parentPath);
1786
+ }
1787
+ }
1788
+ }
1789
+ function processPage(xDocs, page, groupPath, navGroup, output, parentPath) {
1790
+ let uniformRef;
1791
+ switch (page.type) {
1792
+ case "endpoint": {
1793
+ const operationRef = refByOperationId[page.key];
1794
+ if (!operationRef) {
1795
+ console.warn(`No operation found for key: ${page.key} in group ${groupPath.join("/")}`);
1796
+ return;
1797
+ }
1798
+ uniformRef = operationRef;
1799
+ break;
1800
+ }
1801
+ case "object": {
1802
+ const componentRef = refByComponentSchema[page.key];
1803
+ if (!componentRef) {
1804
+ console.warn(`No component schema found for key: ${page.key} in group ${groupPath.join("/")}`);
1805
+ return;
1806
+ }
1807
+ const selector = componentRef.__UNSAFE_selector;
1808
+ if (!selector || typeof selector !== "function") {
1809
+ return;
1810
+ }
1811
+ const component = selector("[component]");
1812
+ if (!component) {
1813
+ console.warn(`No component schema found for key: ${page.key} in group ${groupPath.join("/")}`);
1814
+ return;
1815
+ }
1816
+ let componentMeta;
1817
+ if (component.allOf) {
1818
+ let found = false;
1819
+ for (const item of component.allOf) {
1820
+ const docsMeta = item["x-docs"];
1821
+ if (docsMeta && found) {
1822
+ console.warn(`Multiple x-docs found in allOf for component schema: ${page.key} in group ${groupPath.join("/")}`);
1823
+ }
1824
+ if (docsMeta) {
1825
+ found = true;
1826
+ componentMeta = docsMeta;
1827
+ break;
1828
+ }
1829
+ }
1830
+ if (!found) {
1831
+ console.warn(`No x-docs found in allOf for component schema: ${page.key} in group ${groupPath.join("/")}`);
1832
+ return;
1833
+ }
1834
+ } else {
1835
+ const docsMeta = component["x-docs"];
1836
+ if (docsMeta) {
1837
+ componentMeta = docsMeta;
1838
+ }
1839
+ }
1840
+ uniformRef = componentRef;
1841
+ if (!componentMeta) {
1842
+ break;
1843
+ }
1844
+ componentRef.title = componentMeta.name || componentRef.title;
1845
+ if (componentMeta.example) {
1846
+ const exampleGroups = oasXDocsExamples(componentMeta.example);
1847
+ uniformRef.examples = {
1848
+ groups: exampleGroups
1849
+ };
1850
+ }
1851
+ break;
1852
+ }
1853
+ default: {
1854
+ console.warn(`Unknown page type: ${page.type} in group ${groupPath.join("/")}`);
1855
+ return;
1856
+ }
1857
+ }
1858
+ if (!uniformRef) {
1859
+ return;
1860
+ }
1861
+ if (xDocs.sidebarPathStrategy === "inherit") {
1862
+ const ctx = uniformRef.context;
1863
+ let firstPart = "";
1864
+ if (parentPath) {
1865
+ firstPart = parentPath;
1866
+ } else {
1867
+ firstPart = (ctx == null ? void 0 : ctx.path) || "";
1868
+ }
1869
+ const canonical2 = joinPaths(firstPart || "", page.path);
1870
+ if (canonical2) {
1871
+ uniformRef.canonical = canonical2;
1872
+ }
1873
+ } else if (page.path) {
1874
+ uniformRef.canonical = joinPaths(parentPath, page.path);
1875
+ } else if (parentPath) {
1876
+ uniformRef.canonical = parentPath;
1877
+ }
1878
+ if (!uniformRef.context) {
1879
+ uniformRef.context = {};
1880
+ }
1881
+ uniformRef.context.group = groupPath;
1882
+ output.push(uniformRef);
1883
+ }
1884
+ return function pluginXDocsSidebarInner(ref) {
1885
+ var _a, _b;
1886
+ const selector = ref.__UNSAFE_selector;
1887
+ if (!selector || typeof selector !== "function") {
1888
+ return;
1889
+ }
1890
+ const oapSchema = selector("[schema]");
1891
+ if (!oapSchema) {
1892
+ return;
1893
+ }
1894
+ schema = oapSchema;
1895
+ const ctx = ref.context;
1896
+ if (ctx == null ? void 0 : ctx.componentSchema) {
1897
+ refByComponentSchema[ctx.componentSchema] = ref;
1898
+ }
1899
+ const methodPath = selector("[method] [path]");
1900
+ if (!methodPath) {
1901
+ return;
1902
+ }
1903
+ const oapMethod = selector("[method]");
1904
+ if (!oapMethod) {
1905
+ return;
1906
+ }
1907
+ const operationId = methodPath.operationId;
1908
+ if (operationId) {
1909
+ refByOperationId[operationId] = ref;
1910
+ }
1911
+ const methodId = (((_a = oapMethod == null ? void 0 : oapMethod.httpMethod) == null ? void 0 : _a.toUpperCase()) + " " + (oapMethod == null ? void 0 : oapMethod.path) || "").trim();
1912
+ if (methodId) {
1913
+ refByOperationId[methodId] = ref;
1914
+ }
1915
+ const meta = methodPath["x-docs"];
1916
+ if (!meta) {
1917
+ return;
1918
+ }
1919
+ if (meta.name) {
1920
+ ref.title = meta.name;
1921
+ }
1922
+ if (meta.group) {
1923
+ if (ref.context) {
1924
+ ref.context.group = [meta.group];
1925
+ }
1926
+ }
1927
+ if (!ref.description) {
1928
+ ref.description = methodPath.summary || "";
1929
+ }
1930
+ if (meta.examples) {
1931
+ const exampleGroups = oasXDocsExamples(meta.examples);
1932
+ ref.examples = {
1933
+ groups: exampleGroups
1934
+ };
1935
+ }
1936
+ if (meta.returns) {
1937
+ if ((_b = ref.definitions) == null ? void 0 : _b.length) {
1938
+ ref.definitions[ref.definitions.length - 1] = {
1939
+ title: ref.definitions[ref.definitions.length - 1].title,
1940
+ description: meta.returns,
1941
+ properties: []
1942
+ };
1943
+ } else {
1944
+ ref.definitions = [
1945
+ {
1946
+ title: "Response",
1947
+ description: meta.returns,
1948
+ properties: []
1949
+ }
1950
+ ];
1951
+ }
1952
+ }
1953
+ };
1954
+ }
1955
+ function oasXDocsExamples(examples) {
1956
+ const groups = [];
1957
+ if (examples) {
1958
+ if (Array.isArray(examples)) {
1959
+ const requestExamples = [];
1960
+ examples.forEach((example) => {
1961
+ if (example.request) {
1962
+ const tabs = [];
1963
+ if (typeof example.request === "string") {
1964
+ tabs.push({
1965
+ title: "",
1966
+ language: "json",
1967
+ code: example.request
1968
+ });
1969
+ } else {
1970
+ for (let lang of Object.keys(example.request)) {
1971
+ const code = example.request[lang] || "";
1972
+ const language = lang === "curl" ? "bash" : lang === "node.js" ? "js" : lang;
1973
+ tabs.push({
1974
+ title: lang,
1975
+ language,
1976
+ code
1977
+ });
1978
+ }
1979
+ }
1980
+ if (tabs.length > 0) {
1981
+ requestExamples.push({
1982
+ description: example.title || "",
1983
+ codeblock: {
1984
+ title: example.title || "",
1985
+ tabs
1986
+ }
1987
+ });
1988
+ }
1989
+ }
1990
+ });
1991
+ if (requestExamples.length > 0) {
1992
+ groups.push({
1993
+ description: "Example request",
1994
+ examples: requestExamples
1995
+ });
1996
+ }
1997
+ const responseExamples = [];
1998
+ examples.forEach((example) => {
1999
+ if (example.response) {
2000
+ const tabs = [];
2001
+ if (typeof example.response === "string") {
2002
+ tabs.push({
2003
+ title: "",
2004
+ language: "json",
2005
+ code: example.response
2006
+ });
2007
+ } else {
2008
+ for (let lang of Object.keys(example.response)) {
2009
+ const code = example.response[lang] || "";
2010
+ const language = lang === "curl" ? "bash" : lang === "node.js" ? "js" : lang;
2011
+ tabs.push({
2012
+ title: lang,
2013
+ language,
2014
+ code
2015
+ });
2016
+ }
2017
+ }
2018
+ if (tabs.length > 0) {
2019
+ responseExamples.push({
2020
+ description: example.title || "",
2021
+ codeblock: {
2022
+ title: example.title || "",
2023
+ tabs
2024
+ }
2025
+ });
2026
+ }
2027
+ }
2028
+ });
2029
+ if (responseExamples.length > 0) {
2030
+ groups.push({
2031
+ description: "Example response",
2032
+ examples: responseExamples
2033
+ });
2034
+ }
2035
+ } else {
2036
+ if (typeof examples === "string") {
2037
+ groups.push({
2038
+ description: "Example",
2039
+ examples: [
2040
+ {
2041
+ description: "",
2042
+ codeblock: {
2043
+ tabs: [
2044
+ {
2045
+ title: "",
2046
+ language: "json",
2047
+ code: examples
2048
+ }
2049
+ ]
2050
+ }
2051
+ }
2052
+ ]
2053
+ });
2054
+ } else {
2055
+ if (examples.request) {
2056
+ const tabs = [];
2057
+ if (typeof examples.request === "string") {
2058
+ tabs.push({
2059
+ title: "",
2060
+ language: "json",
2061
+ code: examples.request || ""
2062
+ });
2063
+ } else {
2064
+ for (let lang of Object.keys(examples.request)) {
2065
+ const code = examples.request[lang] || "";
2066
+ switch (lang) {
2067
+ case "curl":
2068
+ lang = "bash";
2069
+ break;
2070
+ case "node.js":
2071
+ lang = "js";
2072
+ break;
2073
+ default:
2074
+ break;
2075
+ }
2076
+ tabs.push({
2077
+ title: lang,
2078
+ language: lang,
2079
+ code
2080
+ });
2081
+ }
2082
+ }
2083
+ groups.push({
2084
+ description: "Example request",
2085
+ examples: [
2086
+ {
2087
+ description: "",
2088
+ codeblock: {
2089
+ tabs
2090
+ }
2091
+ }
2092
+ ]
2093
+ });
2094
+ }
2095
+ if (examples.response) {
2096
+ const tabs = [];
2097
+ if (typeof examples.response === "string") {
2098
+ tabs.push({
2099
+ title: "",
2100
+ language: "json",
2101
+ code: examples.response || ""
2102
+ });
2103
+ } else {
2104
+ for (let lang of Object.keys(examples.response)) {
2105
+ const code = examples.response[lang] || "";
2106
+ switch (lang) {
2107
+ case "curl":
2108
+ lang = "bash";
2109
+ break;
2110
+ case "node.js":
2111
+ lang = "js";
2112
+ break;
2113
+ default:
2114
+ break;
2115
+ }
2116
+ tabs.push({
2117
+ title: lang,
2118
+ language: lang,
2119
+ code
2120
+ });
2121
+ }
2122
+ }
2123
+ groups.push({
2124
+ description: "Example response",
2125
+ examples: [
2126
+ {
2127
+ description: "",
2128
+ codeblock: {
2129
+ tabs
2130
+ }
2131
+ }
2132
+ ]
2133
+ });
2134
+ }
2135
+ }
2136
+ }
2137
+ }
2138
+ return groups;
2139
+ }
2140
+ function joinPaths(...paths) {
2141
+ return paths.filter(Boolean).map((path4) => {
2142
+ path4 = path4.replace(/^\/+|\/+$/g, "");
2143
+ return path4 ? `/${path4}` : "";
2144
+ }).join("").replace(/\/+/g, "/").replace(/\/\{[^}]+\}/g, "").replace(/\/:[^/]+/g, "");
2145
+ }
2146
+ // Annotate the CommonJS export names for ESM import in node:
2147
+ 0 && (module.exports = {
2148
+ deferencedOpenAPI,
2149
+ getXDocs,
2150
+ oapResponseOperationToUniformDefinition,
2151
+ oapSchemaToReferences,
2152
+ uniformPluginXDocsSidebar
2153
+ });
2154
+ //# sourceMappingURL=index.cjs.map