@xyd-js/openapi 0.1.0-xyd.4 → 0.1.0-xyd.52

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 (51) hide show
  1. package/CHANGELOG.md +410 -0
  2. package/LICENSE +21 -0
  3. package/__fixtures__/-2.complex.openai/input.yaml +39848 -0
  4. package/__fixtures__/-2.complex.openai/output.json +321646 -0
  5. package/__fixtures__/-2.complex.openai/pluginOasOpenai.ts +553 -0
  6. package/__fixtures__/1.basic/input.yaml +226 -0
  7. package/__fixtures__/1.basic/output.json +1919 -0
  8. package/__fixtures__/2.more/input.yaml +76 -0
  9. package/__fixtures__/2.more/output.json +292 -0
  10. package/__fixtures__/3.multiple-responses/input.yaml +48 -0
  11. package/__fixtures__/3.multiple-responses/output.json +266 -0
  12. package/__fixtures__/4.abc/input.yaml +639 -0
  13. package/__fixtures__/4.abc/output.json +3828 -0
  14. package/__fixtures__/5.xdocs.codeLanguages/input.yaml +231 -0
  15. package/__fixtures__/5.xdocs.codeLanguages/output.json +1879 -0
  16. package/__fixtures__/5.xdocs.sidebar/input.yaml +256 -0
  17. package/__fixtures__/5.xdocs.sidebar/output.json +843 -0
  18. package/__fixtures__/6.codeSamples/input.yaml +75 -0
  19. package/__fixtures__/6.codeSamples/output.json +293 -0
  20. package/__tests__/oapSchemaToReferences.test.ts +88 -0
  21. package/__tests__/utils.ts +81 -0
  22. package/dist/index.cjs +1860 -163
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +36 -4
  25. package/dist/index.d.ts +36 -4
  26. package/dist/index.js +1856 -156
  27. package/dist/index.js.map +1 -1
  28. package/examples/basic/index2.ts +2 -2
  29. package/index.ts +10 -2
  30. package/package.json +11 -7
  31. package/src/const.ts +5 -1
  32. package/src/converters/oas-componentSchemas.ts +205 -0
  33. package/src/converters/oas-examples.ts +417 -0
  34. package/src/{parameters.ts → converters/oas-parameters.ts} +17 -3
  35. package/src/converters/oas-paths.ts +354 -0
  36. package/src/{requestBody.ts → converters/oas-requestBody.ts} +30 -10
  37. package/src/converters/oas-responses.ts +76 -0
  38. package/src/converters/oas-schema.ts +141 -0
  39. package/src/index.ts +13 -5
  40. package/src/oas-core.ts +579 -0
  41. package/src/types.ts +18 -0
  42. package/src/utils.ts +103 -89
  43. package/src/xdocs/index.ts +18 -0
  44. package/src/xdocs/pluginSidebar.ts +580 -0
  45. package/src/xdocs/types.ts +26 -0
  46. package/vitest.config.ts +7 -0
  47. package/src/examples.ts +0 -116
  48. package/src/paths.ts +0 -103
  49. package/src/properties.ts +0 -37
  50. package/src/responses.ts +0 -38
  51. package/src/schema.ts +0 -62
package/dist/index.cjs CHANGED
@@ -31,7 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  deferencedOpenAPI: () => deferencedOpenAPI,
34
- oapSchemaToReferences: () => oapSchemaToReferences
34
+ getXDocs: () => getXDocs,
35
+ oapResponseOperationToUniformDefinition: () => oapResponseOperationToUniformDefinition,
36
+ oapSchemaToReferences: () => oapSchemaToReferences,
37
+ uniformPluginXDocsSidebar: () => uniformPluginXDocsSidebar
35
38
  });
36
39
  module.exports = __toCommonJS(index_exports);
37
40
 
@@ -46,8 +49,485 @@ var SUPPORTED_HTTP_METHODS = [
46
49
  // 'head',
47
50
  // 'trace'
48
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 ("$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
+ }
49
529
 
50
- // src/parameters.ts
530
+ // src/converters/oas-parameters.ts
51
531
  function oapParametersToDefinitionProperties(parameters) {
52
532
  const parameterIn = {};
53
533
  parameters.forEach((param) => {
@@ -55,61 +535,56 @@ function oapParametersToDefinitionProperties(parameters) {
55
535
  parameterIn[param.in] = [];
56
536
  }
57
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
+ }
58
546
  const property = {
59
547
  name: param.name,
60
- type: schema.type || "",
61
- description: param.description || ""
548
+ type: (schema == null ? void 0 : schema.type) || oapV2Type || "",
549
+ description: param.description || "",
550
+ meta
62
551
  };
63
552
  parameterIn[param.in].push(property);
64
553
  });
65
554
  return parameterIn;
66
555
  }
67
556
 
68
- // src/properties.ts
69
- function schemaObjectToDefinitionProperties(v) {
70
- return Object.entries(v.properties || {}).map(([name, prop]) => {
71
- let objProp = prop;
72
- let merged = [];
73
- if (objProp.allOf) {
74
- merged = objProp.allOf.reduce((acc, of) => {
75
- return [
76
- ...acc,
77
- ...schemaObjectToDefinitionProperties(of)
78
- ];
79
- }, []);
80
- }
81
- if (objProp.type === "array") {
82
- const items = objProp.items;
83
- merged = schemaObjectToDefinitionProperties(items);
84
- }
85
- return {
86
- name,
87
- type: objProp.type || "",
88
- description: objProp.description || "",
89
- properties: (merged == null ? void 0 : merged.length) ? merged : objProp.properties ? schemaObjectToDefinitionProperties(objProp) : []
90
- };
91
- });
92
- }
557
+ // src/converters/oas-paths.ts
558
+ var import_uniform5 = require("@xyd-js/uniform");
93
559
 
94
- // src/requestBody.ts
95
- function oapRequestBodyToDefinitionProperties(reqBody) {
96
- const schema = reqBody.content["application/json"].schema;
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
+ }
97
567
  let schemaObject;
98
568
  if (schema.allOf) {
99
569
  return schema.allOf.reduce((acc, of) => {
100
570
  const fakeBody = {
101
571
  content: {
102
- "application/json": {
572
+ [contentType]: {
103
573
  schema: of
104
574
  }
105
575
  }
106
576
  };
577
+ const properties2 = oapRequestBodyToDefinitionProperties(fakeBody, contentType) || [];
578
+ if (!Array.isArray(properties2)) {
579
+ return acc;
580
+ }
107
581
  return [
108
582
  ...acc,
109
- ...oapRequestBodyToDefinitionProperties(fakeBody) || []
583
+ ...properties2
110
584
  ];
111
585
  }, []);
112
586
  }
587
+ let array = false;
113
588
  switch (schema.type) {
114
589
  case "object": {
115
590
  schemaObject = schema;
@@ -119,6 +594,7 @@ function oapRequestBodyToDefinitionProperties(reqBody) {
119
594
  const arrSchema = schema;
120
595
  const items = arrSchema.items;
121
596
  schemaObject = items;
597
+ array = true;
122
598
  break;
123
599
  }
124
600
  default:
@@ -127,53 +603,205 @@ function oapRequestBodyToDefinitionProperties(reqBody) {
127
603
  if (!schemaObject) {
128
604
  return null;
129
605
  }
130
- return schemaObjectToDefinitionProperties(schemaObject);
606
+ const properties = schemaObjectToUniformDefinitionProperties(schemaObject);
607
+ if (array) {
608
+ return {
609
+ type: import_uniform2.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
610
+ properties
611
+ };
612
+ }
613
+ return properties;
131
614
  }
132
615
 
133
- // src/responses.ts
134
- function oapResponseToDefinitionProperties(responses) {
135
- var _a, _b, _c, _d;
616
+ // src/converters/oas-responses.ts
617
+ var import_uniform3 = require("@xyd-js/uniform");
618
+ function oasResponseToDefinitionProperties(responses, code, contentType) {
619
+ var _a;
136
620
  let schemaObject;
137
- if (responses["default"]) {
138
- const w = responses["default"];
139
- schemaObject = (_b = (_a = w == null ? void 0 : w.content) == null ? void 0 : _a["application/json"]) == null ? void 0 : _b.schema;
140
- } else if (responses["200"]) {
141
- const w = responses["200"];
142
- schemaObject = (_d = (_c = w == null ? void 0 : w.content) == null ? void 0 : _c["application/json"]) == null ? void 0 : _d.schema;
621
+ let responseObject;
622
+ if (responses[code]) {
623
+ responseObject = responses[code];
624
+ if (!(responseObject == null ? void 0 : responseObject.content)) {
625
+ return null;
626
+ }
627
+ schemaObject = (_a = responseObject == null ? void 0 : responseObject.content[contentType]) == null ? void 0 : _a.schema;
143
628
  }
144
629
  if (!schemaObject) {
145
- return null;
630
+ return {
631
+ properties: [
632
+ {
633
+ description: (responseObject == null ? void 0 : responseObject.description) || "",
634
+ name: "",
635
+ type: ""
636
+ }
637
+ ]
638
+ };
146
639
  }
640
+ let array = false;
147
641
  switch (schemaObject.type) {
148
642
  case "array":
149
643
  const arrSchema = schemaObject;
150
644
  const items = arrSchema.items;
151
645
  schemaObject = items;
152
- break;
646
+ array = true;
153
647
  default:
154
648
  break;
155
649
  }
156
- return schemaObjectToDefinitionProperties(schemaObject);
650
+ const properties = schemaObjectToUniformDefinitionProperties(schemaObject, true);
651
+ let description = "";
652
+ if (schemaObject.allOf) {
653
+ for (const item of schemaObject.allOf) {
654
+ if ("description" in item) {
655
+ description += item.description + "\n";
656
+ }
657
+ }
658
+ }
659
+ if (array) {
660
+ return {
661
+ properties: {
662
+ type: import_uniform3.DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY,
663
+ properties
664
+ }
665
+ };
666
+ }
667
+ return {
668
+ properties: properties || [],
669
+ description: description || ""
670
+ };
157
671
  }
158
672
 
159
- // src/schema.ts
160
- var import_oas = __toESM(require("oas"), 1);
161
-
162
- // src/paths.ts
163
- var import_uniform2 = require("@xyd-js/uniform");
164
-
165
673
  // src/utils.ts
166
674
  var import_path = __toESM(require("path"), 1);
167
- var import_fs = __toESM(require("fs"), 1);
675
+ var import_promises = __toESM(require("fs/promises"), 1);
168
676
  var import_js_yaml = __toESM(require("js-yaml"), 1);
169
- var import_json_schema_ref_parser = __toESM(require("json-schema-ref-parser"), 1);
170
- var import_uniform = require("@xyd-js/uniform");
171
- function toPascalCase(str) {
172
- return str.split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
677
+
678
+ // ../../node_modules/.pnpm/github-slugger@2.0.0/node_modules/github-slugger/regex.js
679
+ 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;
680
+
681
+ // ../../node_modules/.pnpm/github-slugger@2.0.0/node_modules/github-slugger/index.js
682
+ var own = Object.hasOwnProperty;
683
+ var BananaSlug = class {
684
+ /**
685
+ * Create a new slug class.
686
+ */
687
+ constructor() {
688
+ this.occurrences;
689
+ this.reset();
690
+ }
691
+ /**
692
+ * Generate a unique slug.
693
+ *
694
+ * Tracks previously generated slugs: repeated calls with the same value
695
+ * will result in different slugs.
696
+ * Use the `slug` function to get same slugs.
697
+ *
698
+ * @param {string} value
699
+ * String of text to slugify
700
+ * @param {boolean} [maintainCase=false]
701
+ * Keep the current case, otherwise make all lowercase
702
+ * @return {string}
703
+ * A unique slug string
704
+ */
705
+ slug(value, maintainCase) {
706
+ const self = this;
707
+ let result = slug(value, maintainCase === true);
708
+ const originalSlug = result;
709
+ while (own.call(self.occurrences, result)) {
710
+ self.occurrences[originalSlug]++;
711
+ result = originalSlug + "-" + self.occurrences[originalSlug];
712
+ }
713
+ self.occurrences[result] = 0;
714
+ return result;
715
+ }
716
+ /**
717
+ * Reset - Forget all previous slugs
718
+ *
719
+ * @return void
720
+ */
721
+ reset() {
722
+ this.occurrences = /* @__PURE__ */ Object.create(null);
723
+ }
724
+ };
725
+ function slug(value, maintainCase) {
726
+ if (typeof value !== "string") return "";
727
+ if (!maintainCase) value = value.toLowerCase();
728
+ return value.replace(regex, "").replace(/ /g, "-");
729
+ }
730
+
731
+ // src/utils.ts
732
+ var import_json_schema_ref_parser = __toESM(require("@apidevtools/json-schema-ref-parser"), 1);
733
+ var import_uniform4 = require("@xyd-js/uniform");
734
+ function slug2(str) {
735
+ const slugger = new BananaSlug();
736
+ return slugger.slug(str);
737
+ }
738
+ async function deferencedOpenAPI(openApiPath) {
739
+ const openApiSpec = await readOpenApiSpec(openApiPath);
740
+ if (!openApiSpec) {
741
+ return;
742
+ }
743
+ const cwd = process.cwd();
744
+ const remoteOasPath = openApiPath.startsWith("http://") || openApiPath.startsWith("https://") ? true : false;
745
+ const options = {
746
+ dereference: {
747
+ onDereference(path4, value, parent) {
748
+ if (value && typeof value === "object") {
749
+ value.__UNSAFE_refPath = () => path4;
750
+ }
751
+ if (parent && typeof parent === "object") {
752
+ parent.__UNSAFE_refPath = () => path4;
753
+ }
754
+ }
755
+ }
756
+ };
757
+ if (remoteOasPath) {
758
+ if (!options.resolve) {
759
+ options.resolve = {};
760
+ }
761
+ options.resolve.file = {
762
+ read: async (file) => {
763
+ let rel = import_path.default.relative(cwd, file.url);
764
+ rel = rel.split(import_path.default.sep).join("/");
765
+ const absoluteUrl = new URL(rel, openApiPath).href;
766
+ const res = await fetch(absoluteUrl);
767
+ if (!res.ok) {
768
+ throw new Error(`Failed to fetch ${absoluteUrl}: ${res.status}`);
769
+ }
770
+ let content;
771
+ if (file.extension === ".json" || file.extension === ".yaml" || file.extension === ".yml") {
772
+ if (file.extension === ".json") {
773
+ content = await res.json();
774
+ } else {
775
+ content = import_js_yaml.default.load(await res.text());
776
+ }
777
+ } else {
778
+ content = await res.text();
779
+ }
780
+ return content;
781
+ }
782
+ };
783
+ }
784
+ await import_json_schema_ref_parser.default.dereference(openApiSpec, options);
785
+ return openApiSpec;
173
786
  }
174
- function readOpenApiSpec(filePath) {
787
+ async function readOpenApiSpec(filePath) {
788
+ let content;
789
+ if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
790
+ const response = await fetch(filePath);
791
+ if (!response.ok) {
792
+ throw new Error(`Failed to fetch OpenAPI spec from URL: ${response.statusText}`);
793
+ }
794
+ content = await response.text();
795
+ } else {
796
+ try {
797
+ await import_promises.default.access(filePath);
798
+ } catch (error) {
799
+ console.log(`\u26A0\uFE0F "${filePath}" is defined in the docs.json navigation but the file does not exist.`);
800
+ return;
801
+ }
802
+ content = await import_promises.default.readFile(filePath, "utf-8");
803
+ }
175
804
  const ext = import_path.default.extname(filePath).toLowerCase();
176
- const content = import_fs.default.readFileSync(filePath, "utf-8");
177
805
  if (ext === ".yaml" || ext === ".yml") {
178
806
  return import_js_yaml.default.load(content);
179
807
  } else if (ext === ".json") {
@@ -182,39 +810,35 @@ function readOpenApiSpec(filePath) {
182
810
  throw new Error("Unsupported file format. Use JSON or YAML.");
183
811
  }
184
812
  }
185
- async function deferencedOpenAPI(openApiPath) {
186
- const openApiSpec = readOpenApiSpec(openApiPath);
187
- await import_json_schema_ref_parser.default.dereference(openApiSpec);
188
- return openApiSpec;
189
- }
190
813
  function httpMethodToUniformMethod(method) {
191
814
  switch (method) {
192
815
  case "get":
193
- return import_uniform.ReferenceType.REST_HTTP_GET;
816
+ return import_uniform4.ReferenceType.REST_HTTP_GET;
194
817
  case "put":
195
- return import_uniform.ReferenceType.REST_HTTP_PUT;
818
+ return import_uniform4.ReferenceType.REST_HTTP_PUT;
196
819
  case "patch":
197
- return import_uniform.ReferenceType.REST_HTTP_PATCH;
820
+ return import_uniform4.ReferenceType.REST_HTTP_PATCH;
198
821
  case "post":
199
- return import_uniform.ReferenceType.REST_HTTP_POST;
822
+ return import_uniform4.ReferenceType.REST_HTTP_POST;
200
823
  case "delete":
201
- return import_uniform.ReferenceType.REST_HTTP_DELETE;
202
- // case 'options':
203
- // return ReferenceType.REST_HTTP_OPTIONS
204
- // case 'head':
205
- // return ReferenceType.REST_HTTP_HEAD
206
- // case 'trace':
207
- // return ReferenceType.REST_HTTP_TRACE
824
+ return import_uniform4.ReferenceType.REST_HTTP_DELETE;
825
+ case "options":
826
+ return import_uniform4.ReferenceType.REST_HTTP_OPTIONS;
827
+ case "head":
828
+ return import_uniform4.ReferenceType.REST_HTTP_HEAD;
829
+ case "trace":
830
+ return import_uniform4.ReferenceType.REST_HTTP_TRACE;
208
831
  default:
209
832
  return null;
210
833
  }
211
834
  }
212
835
 
213
- // src/paths.ts
214
- function oapPathToReference(httpMethod, path2, oapPath) {
836
+ // src/converters/oas-paths.ts
837
+ var import_node_path = __toESM(require("path"), 1);
838
+ function oapPathToReference(schema, httpMethod, path4, oapPath) {
215
839
  const mType = httpMethodToUniformMethod(httpMethod);
216
840
  if (!mType) {
217
- console.error(`Unsupported method v222: ${httpMethod}`);
841
+ console.error(`Unsupported method: ${httpMethod}`);
218
842
  return null;
219
843
  }
220
844
  const definitions = [];
@@ -223,15 +847,19 @@ function oapPathToReference(httpMethod, path2, oapPath) {
223
847
  if (!oapMethod) {
224
848
  return null;
225
849
  }
850
+ const tag = getFirstTag(oapMethod);
851
+ const group = [tag];
226
852
  const endpointRef = {
227
- title: (oapMethod == null ? void 0 : oapMethod.summary) || "",
228
- canonical: toPascalCase((oapMethod == null ? void 0 : oapMethod.summary) || ""),
229
- description: (oapMethod == null ? void 0 : oapMethod.description) || "",
230
- category: import_uniform2.ReferenceCategory.REST,
853
+ title: title(oapMethod, httpMethod, path4),
854
+ canonical: canonical(oapMethod, httpMethod, path4),
855
+ description: (oapMethod == null ? void 0 : oapMethod.description) || (oapMethod == null ? void 0 : oapMethod.summary),
231
856
  type: mType,
857
+ category: import_uniform5.ReferenceCategory.REST,
232
858
  context: {
233
859
  method: httpMethod,
234
- path: `${encodeURIComponent(path2)}`
860
+ path: `${encodeURIComponent(path4)}`,
861
+ fullPath: path4,
862
+ group
235
863
  },
236
864
  examples: {
237
865
  groups: exampleGroups
@@ -242,108 +870,507 @@ function oapPathToReference(httpMethod, path2, oapPath) {
242
870
  const parameters = oapMethod.parameters;
243
871
  const paramtersMap = oapParametersToDefinitionProperties(parameters);
244
872
  Object.entries(paramtersMap).forEach(([key, definitionProperties]) => {
245
- let title;
873
+ let title2;
246
874
  switch (key) {
247
875
  case "path":
248
- title = "Path parameters";
876
+ title2 = "Path parameters";
249
877
  break;
250
878
  case "query":
251
- title = "Query";
879
+ title2 = "Query parameters";
252
880
  break;
253
881
  case "header":
254
- title = "Header";
882
+ title2 = "Headers";
255
883
  break;
256
884
  default:
257
- console.error(`Unsupported parameter type: ${key} for ${httpMethod} ${path2}`);
885
+ console.error(`Unsupported parameter type: ${key} for ${httpMethod} ${path4}`);
258
886
  return;
259
887
  }
260
888
  definitions.push({
261
- title,
889
+ title: title2,
262
890
  properties: definitionProperties
263
891
  });
264
892
  });
265
893
  }
894
+ definitions.push(...oapOperationToDefinitions(oapMethod));
895
+ endpointRef.__UNSAFE_selector = function __UNSAFE_selector(selector) {
896
+ switch (selector) {
897
+ case "[schema]": {
898
+ return schema;
899
+ }
900
+ case "[method]": {
901
+ return {
902
+ oapPath,
903
+ httpMethod,
904
+ path: path4
905
+ };
906
+ }
907
+ case "[method] [path]": {
908
+ return oapMethod;
909
+ }
910
+ default:
911
+ return null;
912
+ }
913
+ };
914
+ return endpointRef;
915
+ }
916
+ function oapOperationToDefinitions(oapMethod) {
917
+ const definitions = [];
266
918
  if (oapMethod.requestBody) {
267
- const reqBody = oapMethod.requestBody;
268
- definitions.push({
269
- title: "Request body",
270
- properties: oapRequestBodyToDefinitionProperties(reqBody) || []
271
- });
919
+ const definition = oapRequestOperationToUniformDefinition(oapMethod);
920
+ definitions.push(definition);
272
921
  }
273
922
  if (oapMethod.responses) {
274
- const responses = oapMethod.responses;
275
- definitions.push({
276
- title: "Response",
277
- properties: oapResponseToDefinitionProperties(responses) || []
923
+ const definition = oapResponseOperationToUniformDefinition(oapMethod);
924
+ definitions.push(definition);
925
+ }
926
+ return definitions;
927
+ }
928
+ function oapRequestOperationToUniformDefinition(oapOperation) {
929
+ var _a;
930
+ const reqBody = oapOperation.requestBody;
931
+ const variants = [];
932
+ for (const contentType of Object.keys(reqBody.content)) {
933
+ const schema = (_a = reqBody.content[contentType]) == null ? void 0 : _a.schema;
934
+ let properties = [];
935
+ let rootProperty;
936
+ let propertiesResp = oapRequestBodyToDefinitionProperties(reqBody, contentType) || [];
937
+ if (Array.isArray(propertiesResp)) {
938
+ properties = propertiesResp;
939
+ } else {
940
+ rootProperty = propertiesResp;
941
+ }
942
+ const meta2 = [
943
+ {
944
+ name: "contentType",
945
+ value: contentType || ""
946
+ }
947
+ ];
948
+ if (schema == null ? void 0 : schema.required) {
949
+ meta2.push({
950
+ name: "required",
951
+ value: schema.required ? "true" : "false"
952
+ });
953
+ }
954
+ variants.push({
955
+ title: contentType,
956
+ description: schema.description || "",
957
+ properties,
958
+ rootProperty,
959
+ meta: meta2,
960
+ symbolDef: definitionPropertyTypeDef(schema)
278
961
  });
279
962
  }
280
- return endpointRef;
963
+ const meta = [];
964
+ if (reqBody.required) {
965
+ meta.push({
966
+ name: "required",
967
+ value: "true"
968
+ });
969
+ }
970
+ return {
971
+ title: "Request body",
972
+ variants,
973
+ properties: [],
974
+ meta
975
+ };
281
976
  }
977
+ function oapResponseOperationToUniformDefinition(oapOperation) {
978
+ const responses = oapOperation.responses;
979
+ const variants = [];
980
+ Object.keys(responses).forEach((code) => {
981
+ var _a;
982
+ const responseObject = responses[code];
983
+ if (!(responseObject == null ? void 0 : responseObject.content)) {
984
+ variants.push({
985
+ title: code,
986
+ description: responseObject.description,
987
+ properties: [],
988
+ meta: [
989
+ {
990
+ name: "status",
991
+ value: code || ""
992
+ }
993
+ ]
994
+ });
995
+ return null;
996
+ }
997
+ const contentTypes = Object.keys(responseObject.content);
998
+ for (const contentType of contentTypes) {
999
+ let properties = [];
1000
+ let rootProperty;
1001
+ const schema = (_a = responseObject.content[contentType]) == null ? void 0 : _a.schema;
1002
+ const respProperties = oasResponseToDefinitionProperties(responses, code, contentType) || [];
1003
+ if (respProperties && "properties" in respProperties && (respProperties == null ? void 0 : respProperties.properties)) {
1004
+ if (Array.isArray(respProperties.properties)) {
1005
+ properties = respProperties.properties;
1006
+ } else {
1007
+ rootProperty = respProperties.properties;
1008
+ }
1009
+ }
1010
+ let definitionDescription = "";
1011
+ if ("description" in respProperties) {
1012
+ definitionDescription = respProperties.description || "";
1013
+ }
1014
+ variants.push({
1015
+ title: code,
1016
+ description: responseObject.description,
1017
+ properties,
1018
+ rootProperty,
1019
+ meta: [
1020
+ {
1021
+ name: "status",
1022
+ value: code || ""
1023
+ },
1024
+ {
1025
+ name: "contentType",
1026
+ value: contentType || ""
1027
+ },
1028
+ {
1029
+ name: "definitionDescription",
1030
+ value: definitionDescription
1031
+ }
1032
+ ],
1033
+ symbolDef: definitionPropertyTypeDef(schema)
1034
+ });
1035
+ }
1036
+ });
1037
+ return {
1038
+ title: "Response",
1039
+ variants,
1040
+ properties: []
1041
+ };
1042
+ }
1043
+ function definitionPropertyTypeDef(schema) {
1044
+ if (!schema) {
1045
+ return;
1046
+ }
1047
+ let typeDef;
1048
+ let oasSchema = schema;
1049
+ if (oasSchema.type === "array") {
1050
+ oasSchema = oasSchema.items;
1051
+ }
1052
+ if (oasSchema == null ? void 0 : oasSchema.__internal_getRefPath) {
1053
+ const symbolId = oasSchema.__internal_getRefPath();
1054
+ typeDef = {
1055
+ id: symbolId
1056
+ };
1057
+ }
1058
+ return typeDef;
1059
+ }
1060
+ function title(oapMethod, httpMethod, httpPath) {
1061
+ const tit = (oapMethod == null ? void 0 : oapMethod.summary) || oapMethod.operationId || "";
1062
+ if (tit) {
1063
+ return tit;
1064
+ }
1065
+ if (!httpMethod || !httpPath) {
1066
+ throw new Error("httpMethod and path are required to generate title");
1067
+ }
1068
+ return import_node_path.default.join(httpMethod, cleanPath(httpPath));
1069
+ }
1070
+ function canonical(oapMethod, httpMethod, httpPath) {
1071
+ let canon = oapMethod.operationId || slug2((oapMethod == null ? void 0 : oapMethod.summary) || "");
1072
+ if (canon) {
1073
+ return canon;
1074
+ }
1075
+ if (!httpMethod || !httpPath) {
1076
+ throw new Error("httpMethod and path are required to generate canonical");
1077
+ }
1078
+ return import_node_path.default.join(httpMethod, cleanPath(httpPath));
1079
+ }
1080
+ function getFirstTag(oapMethod) {
1081
+ for (const tag of (oapMethod == null ? void 0 : oapMethod.tags) || []) {
1082
+ return tag;
1083
+ }
1084
+ return "";
1085
+ }
1086
+ function cleanPath(httpPath) {
1087
+ return httpPath.replace(/\{([^}]+)\}/g, "$1");
1088
+ }
1089
+
1090
+ // src/converters/oas-schema.ts
1091
+ var import_node_path2 = __toESM(require("path"), 1);
1092
+ var import_oas = __toESM(require("oas"), 1);
282
1093
 
283
- // src/examples.ts
1094
+ // src/converters/oas-examples.ts
284
1095
  var import_oas_to_snippet = __toESM(require("@readme/oas-to-snippet"), 1);
285
- var import_openapi_sampler = __toESM(require("openapi-sampler"), 1);
286
- function oapExamples(oas, operation) {
1096
+ var import_openapi_sampler = require("@xyd-js/openapi-sampler");
1097
+
1098
+ // src/xdocs/index.ts
1099
+ function xDocsLanguages(oasDoc) {
1100
+ const xDocs = getXDocs(oasDoc);
1101
+ if (!xDocs) {
1102
+ return null;
1103
+ }
1104
+ return (xDocs == null ? void 0 : xDocs.codeLanguages) ?? null;
1105
+ }
1106
+ function getXDocs(oasDoc) {
1107
+ if (!("x-docs" in oasDoc)) {
1108
+ return null;
1109
+ }
1110
+ return oasDoc["x-docs"];
1111
+ }
1112
+
1113
+ // src/converters/oas-examples.ts
1114
+ var DEFAULT_CODE_LANGUAGES = ["shell", "javascript", "python", "go"];
1115
+ function oapExamples(oas, operation, visitedExamples) {
1116
+ const exampleGroups = [
1117
+ ...reqExamples(operation, oas, visitedExamples),
1118
+ ...resBodyExmaples(operation, oas, visitedExamples)
1119
+ ];
1120
+ return exampleGroups;
1121
+ }
1122
+ function langFallback(lang) {
1123
+ const langLower = lang.toLowerCase();
1124
+ switch (langLower) {
1125
+ case "curl": {
1126
+ return "shell";
1127
+ }
1128
+ }
1129
+ return langLower;
1130
+ }
1131
+ function smartDeepCopy(obj, excludeProps = []) {
1132
+ const seen = /* @__PURE__ */ new WeakMap();
1133
+ function copy(value) {
1134
+ if (value === null || typeof value !== "object") {
1135
+ return value;
1136
+ }
1137
+ if (Array.isArray(value)) {
1138
+ return value.map(copy);
1139
+ }
1140
+ if (value instanceof Date) {
1141
+ return new Date(value);
1142
+ }
1143
+ if (seen.has(value)) {
1144
+ return seen.get(value);
1145
+ }
1146
+ const result = {};
1147
+ seen.set(value, result);
1148
+ for (const [key, val] of Object.entries(value)) {
1149
+ const propPath = key;
1150
+ if (!excludeProps.some((prop) => propPath.startsWith(prop))) {
1151
+ result[key] = copy(val);
1152
+ }
1153
+ }
1154
+ return result;
1155
+ }
1156
+ return copy(obj);
1157
+ }
1158
+ function excludeProperties(operation, excludeProps) {
1159
+ return smartDeepCopy(operation, excludeProps);
1160
+ }
1161
+ function reqExamples(operation, oas, vistedExamples) {
287
1162
  const exampleGroups = [];
288
- if (operation.schema.requestBody) {
289
- const body = operation.schema.requestBody;
290
- const schema = fixAllOfBug(
291
- body.content["application/json"].schema
292
- );
293
- if (!schema) {
1163
+ const examples = [];
1164
+ const tabs = [];
1165
+ if (operation.schema["x-codeSamples"]) {
1166
+ const codeSamples = operation.schema["x-codeSamples"];
1167
+ const codeSampleTabs = codeSamples.map((sample) => ({
1168
+ title: sample.lang,
1169
+ language: langFallback(sample.lang),
1170
+ code: sample.source
1171
+ }));
1172
+ if (codeSampleTabs.length > 0) {
1173
+ examples.push({
1174
+ codeblock: {
1175
+ tabs: codeSampleTabs
1176
+ }
1177
+ });
1178
+ exampleGroups.push({
1179
+ description: "Example request",
1180
+ examples
1181
+ });
294
1182
  return exampleGroups;
295
1183
  }
296
- const fakeData = import_openapi_sampler.default.sample(schema);
297
- const { code } = (0, import_oas_to_snippet.default)(oas, operation, {
298
- body: fakeData
299
- }, null, "shell");
300
- const examples = [];
301
- examples.push({
302
- codeblock: {
303
- tabs: [{
304
- title: "curl",
305
- language: "curl",
306
- code: code || ""
307
- }]
1184
+ }
1185
+ const paramData = operation.schema.parameters ? operation.schema.parameters.reduce((acc, param) => {
1186
+ const location = param.in || "query";
1187
+ if (!acc[location]) {
1188
+ acc[location] = {};
1189
+ }
1190
+ let value = param.example;
1191
+ if (!value && param.schema) {
1192
+ value = (0, import_openapi_sampler.sample)(sanitizeSchema(param.schema));
1193
+ }
1194
+ if (value !== void 0) {
1195
+ acc[location][param.name] = value;
1196
+ }
1197
+ return acc;
1198
+ }, {}) : {};
1199
+ let bodyData = {};
1200
+ if (operation.schema.requestBody) {
1201
+ const body = operation.schema.requestBody;
1202
+ const contentTypes = Object.keys(body.content);
1203
+ if (contentTypes.length > 0) {
1204
+ const contentType = contentTypes[contentTypes.length - 1];
1205
+ const content = body.content[contentType];
1206
+ let schema = content == null ? void 0 : content.schema;
1207
+ if (schema) {
1208
+ schema = fixAllOfBug(schema);
1209
+ schema = sanitizeSchema(schema);
1210
+ let requestData;
1211
+ if (content.examples) {
1212
+ const requestExample = content.examples["request"];
1213
+ if (requestExample && "value" in requestExample) {
1214
+ requestData = requestExample.value;
1215
+ }
1216
+ }
1217
+ if (!requestData) {
1218
+ requestData = (0, import_openapi_sampler.sample)(schema);
1219
+ }
1220
+ if (contentType === "application/x-www-form-urlencoded") {
1221
+ bodyData = { formData: requestData };
1222
+ } else {
1223
+ bodyData = { body: requestData };
1224
+ }
308
1225
  }
1226
+ }
1227
+ }
1228
+ const hasRequestBody = operation.schema.requestBody !== void 0;
1229
+ const hasParameters = Object.keys(paramData).length > 0;
1230
+ if (hasParameters || hasRequestBody || !hasRequestBody && !hasParameters) {
1231
+ const langs = xDocsLanguages(operation.api) || DEFAULT_CODE_LANGUAGES;
1232
+ langs.forEach((lang) => {
1233
+ const operationCopy = excludeProperties(operation, ["api.components", "api.paths"]);
1234
+ const { code } = (0, import_oas_to_snippet.default)(oas, operationCopy, {
1235
+ ...paramData,
1236
+ ...bodyData
1237
+ }, null, lang);
1238
+ tabs.push({
1239
+ title: lang,
1240
+ language: lang,
1241
+ code: code || ""
1242
+ });
309
1243
  });
310
- exampleGroups.push({
311
- description: "Example request",
312
- examples
313
- });
1244
+ if (tabs.length > 0) {
1245
+ examples.push({
1246
+ codeblock: {
1247
+ tabs
1248
+ }
1249
+ });
1250
+ }
1251
+ if (examples.length > 0) {
1252
+ exampleGroups.push({
1253
+ description: "Example request",
1254
+ examples
1255
+ });
1256
+ }
314
1257
  }
1258
+ return exampleGroups;
1259
+ }
1260
+ function resBodyExmaples(operation, oas, vistedExamples) {
1261
+ const exampleGroups = [];
315
1262
  if (operation.schema.responses) {
316
1263
  const responses = operation.schema.responses;
317
1264
  const examples = [];
318
1265
  Object.entries(responses).forEach(([status, r]) => {
319
- var _a;
320
1266
  const response = r;
321
- const schema = (_a = response == null ? void 0 : response.content) == null ? void 0 : _a["application/json"].schema;
322
- if (!schema) {
1267
+ if (!response.content) {
323
1268
  return;
324
1269
  }
325
- const fakeData = import_openapi_sampler.default.sample(schema);
326
- examples.push({
327
- codeblock: {
328
- title: status,
329
- tabs: [{
330
- title: "json",
331
- language: "json",
332
- code: JSON.stringify(fakeData, null, 2) || ""
333
- }]
1270
+ const contentTypes = Object.keys(response.content);
1271
+ if (contentTypes.length === 0) {
1272
+ return;
1273
+ }
1274
+ const tabs = [];
1275
+ for (const contentType of contentTypes) {
1276
+ const content = response.content[contentType];
1277
+ const schema = content == null ? void 0 : content.schema;
1278
+ if (!schema) {
1279
+ continue;
334
1280
  }
335
- });
336
- });
337
- exampleGroups.push({
338
- description: "Response",
339
- examples
1281
+ let responseData;
1282
+ if (content.examples) {
1283
+ const responseExample = content.examples["response"];
1284
+ if (responseExample && "value" in responseExample) {
1285
+ responseData = responseExample.value;
1286
+ } else {
1287
+ const namedExamples = [];
1288
+ const exampleNames = Object.keys(content.examples);
1289
+ exampleNames.forEach((exampleName) => {
1290
+ var _a;
1291
+ const data = (_a = content == null ? void 0 : content.examples) == null ? void 0 : _a[exampleName];
1292
+ if (!data || !("value" in data) || typeof data.value != "object") {
1293
+ return;
1294
+ }
1295
+ namedExamples.push({
1296
+ description: "",
1297
+ codeblock: {
1298
+ title: exampleName,
1299
+ tabs: [
1300
+ {
1301
+ title: "application/json",
1302
+ // TODO: support multiple types
1303
+ language: "json",
1304
+ code: JSON.stringify(data.value, null, 2) || ""
1305
+ }
1306
+ ]
1307
+ }
1308
+ });
1309
+ });
1310
+ if (namedExamples.length === 1) {
1311
+ const firstCodeblock = namedExamples[0].codeblock;
1312
+ tabs.push(
1313
+ ...firstCodeblock.tabs.map((tab) => ({
1314
+ ...tab,
1315
+ title: contentType
1316
+ }))
1317
+ );
1318
+ } else {
1319
+ exampleGroups.push({
1320
+ description: "",
1321
+ examples: namedExamples
1322
+ });
1323
+ }
1324
+ continue;
1325
+ }
1326
+ } else if (content.example) {
1327
+ responseData = content.example;
1328
+ }
1329
+ if (!responseData) {
1330
+ responseData = (0, import_openapi_sampler.sample)(sanitizeSchema(schema));
1331
+ }
1332
+ let extension = "text";
1333
+ switch (contentType) {
1334
+ case "application/json":
1335
+ case "application/problem+json":
1336
+ case "application/vnd.api+json": {
1337
+ extension = "json";
1338
+ break;
1339
+ }
1340
+ case "application/xml":
1341
+ case "text/xml":
1342
+ case "application/problem+xml": {
1343
+ extension = "xml";
1344
+ break;
1345
+ }
1346
+ }
1347
+ tabs.push({
1348
+ title: contentType,
1349
+ language: extension,
1350
+ code: JSON.stringify(responseData, null, 2) || ""
1351
+ });
1352
+ }
1353
+ if (tabs.length > 0) {
1354
+ examples.push({
1355
+ codeblock: {
1356
+ title: status,
1357
+ tabs
1358
+ }
1359
+ });
1360
+ }
340
1361
  });
1362
+ if (examples.length > 0) {
1363
+ exampleGroups.push({
1364
+ description: "Example response",
1365
+ examples
1366
+ });
1367
+ }
341
1368
  }
342
1369
  return exampleGroups;
343
1370
  }
344
1371
  function fixAllOfBug(schema) {
345
1372
  const modifiedSchema = { ...schema };
346
- if (schema.allOf) {
1373
+ if (schema == null ? void 0 : schema.allOf) {
347
1374
  schema.allOf.forEach((prop, i) => {
348
1375
  var _a;
349
1376
  const propObj = prop;
@@ -354,50 +1381,720 @@ function fixAllOfBug(schema) {
354
1381
  }
355
1382
  return modifiedSchema;
356
1383
  }
1384
+ function sanitizeSchema(schema, vistedExamples = /* @__PURE__ */ new Map(), parent) {
1385
+ if (vistedExamples.has(schema)) {
1386
+ const cached = vistedExamples.get(schema);
1387
+ if (typeof cached === "object") {
1388
+ return JSON.parse(JSON.stringify(cached));
1389
+ }
1390
+ return cached;
1391
+ }
1392
+ if (parent) {
1393
+ vistedExamples.set(schema, parent);
1394
+ }
1395
+ if (!schema || typeof schema !== "object") {
1396
+ vistedExamples.set(schema, schema);
1397
+ return schema;
1398
+ }
1399
+ if (Array.isArray(schema)) {
1400
+ const v = schema.map((item) => sanitizeSchema(item, vistedExamples));
1401
+ vistedExamples.set(schema, v);
1402
+ return v;
1403
+ }
1404
+ const cleaned = {};
1405
+ for (const [key, value] of Object.entries(schema)) {
1406
+ if (key === "__UNSAFE_refPath") {
1407
+ continue;
1408
+ }
1409
+ if (!BUILT_IN_PROPERTIES[key]) {
1410
+ cleaned[key] = sanitizeSchema(value, vistedExamples, cleaned);
1411
+ }
1412
+ }
1413
+ vistedExamples.set(schema, cleaned);
1414
+ return cleaned;
1415
+ }
357
1416
 
358
- // src/schema.ts
359
- function oapSchemaToReferences(schema) {
1417
+ // src/converters/oas-componentSchemas.ts
1418
+ var import_uniform6 = require("@xyd-js/uniform");
1419
+ function schemaComponentsToUniformReferences(openapi, options) {
1420
+ var _a;
1421
+ const references = [];
1422
+ if (!((_a = openapi.components) == null ? void 0 : _a.schemas)) {
1423
+ return references;
1424
+ }
1425
+ for (const [componentSchemaName, componentSchema] of Object.entries(openapi.components.schemas)) {
1426
+ if ((options == null ? void 0 : options.regions) && options.regions.length > 0) {
1427
+ if (!options.regions.some((region) => region === "/components/schemas/" + componentSchemaName)) {
1428
+ continue;
1429
+ }
1430
+ }
1431
+ if ("$ref" in componentSchema) {
1432
+ console.warn(`Skipping reference object: ${componentSchemaName}`);
1433
+ continue;
1434
+ }
1435
+ let properties = [];
1436
+ let rootProperty = void 0;
1437
+ const respProperties = schemaObjectToUniformDefinitionProperties(componentSchema, false) || [];
1438
+ if (Array.isArray(respProperties)) {
1439
+ properties = respProperties;
1440
+ } else {
1441
+ rootProperty = respProperties;
1442
+ }
1443
+ const symbolDef = definitionPropertyTypeDef2(componentSchema);
1444
+ const definition = {
1445
+ title: componentSchemaName,
1446
+ properties,
1447
+ rootProperty,
1448
+ meta: [],
1449
+ symbolDef
1450
+ };
1451
+ const reference = {
1452
+ title: componentSchemaName,
1453
+ description: componentSchema.description || "",
1454
+ canonical: `objects/${componentSchemaName}`,
1455
+ definitions: [definition],
1456
+ examples: {
1457
+ groups: createSchemaExampleGroup(componentSchema)
1458
+ },
1459
+ type: import_uniform6.ReferenceType.REST_COMPONENT_SCHEMA,
1460
+ context: {
1461
+ componentSchema: componentSchemaName,
1462
+ group: ["Objects"]
1463
+ }
1464
+ };
1465
+ reference.__UNSAFE_selector = function __UNSAFE_selector(selector) {
1466
+ switch (selector) {
1467
+ case "[schema]": {
1468
+ return openapi;
1469
+ }
1470
+ case "[component]": {
1471
+ return componentSchema;
1472
+ }
1473
+ default:
1474
+ return null;
1475
+ }
1476
+ };
1477
+ references.push(reference);
1478
+ }
1479
+ return references;
1480
+ }
1481
+ function createSchemaExampleGroup(schema, map) {
1482
+ const example = generateSchemaExample(schema);
1483
+ if (!example) {
1484
+ return [];
1485
+ }
1486
+ const tabs = [{
1487
+ title: "json",
1488
+ language: "json",
1489
+ code: JSON.stringify(example, null, 2)
1490
+ }];
1491
+ return [{
1492
+ description: "Example",
1493
+ examples: [{
1494
+ codeblock: {
1495
+ tabs
1496
+ }
1497
+ }]
1498
+ }];
1499
+ }
1500
+ function definitionPropertyTypeDef2(schema) {
1501
+ if (!schema) {
1502
+ return;
1503
+ }
1504
+ let typeDef;
1505
+ let oasSchema = schema;
1506
+ if (oasSchema.type === "array") {
1507
+ oasSchema = oasSchema.items;
1508
+ }
1509
+ if (oasSchema == null ? void 0 : oasSchema.__internal_getRefPath) {
1510
+ const symbolId = oasSchema.__internal_getRefPath();
1511
+ typeDef = {
1512
+ id: symbolId
1513
+ };
1514
+ }
1515
+ return typeDef;
1516
+ }
1517
+ function generateSchemaExample(schema, visitedExample, parent) {
1518
+ if (!schema) {
1519
+ return null;
1520
+ }
1521
+ if (!visitedExample) {
1522
+ visitedExample = /* @__PURE__ */ new Map();
1523
+ }
1524
+ const cached = visitedExample.get(schema);
1525
+ if (cached) {
1526
+ return JSON.parse(JSON.stringify(cached));
1527
+ }
1528
+ if (parent) {
1529
+ visitedExample.set(schema, parent);
1530
+ }
1531
+ if ("examples" in schema && Array.isArray(schema.examples)) {
1532
+ const v = schema.examples[0];
1533
+ visitedExample.set(schema, v);
1534
+ return v;
1535
+ }
1536
+ if ("example" in schema && schema.example !== void 0) {
1537
+ const v = schema.example;
1538
+ visitedExample.set(schema, v);
1539
+ return v;
1540
+ }
1541
+ if (schema.type === "object" && schema.properties) {
1542
+ const result = {};
1543
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
1544
+ result[propName] = generateSchemaExample(propSchema, visitedExample, result);
1545
+ }
1546
+ visitedExample.set(schema, result);
1547
+ return result;
1548
+ }
1549
+ if (schema.type === "array" && schema.items) {
1550
+ const itemExample = generateSchemaExample(schema.items, visitedExample);
1551
+ const v = itemExample ? [itemExample] : [];
1552
+ visitedExample.set(schema, v);
1553
+ return v;
1554
+ }
1555
+ switch (schema.type) {
1556
+ case "string":
1557
+ return "";
1558
+ case "number":
1559
+ case "integer":
1560
+ return 0;
1561
+ case "boolean":
1562
+ return false;
1563
+ default:
1564
+ return null;
1565
+ }
1566
+ }
1567
+
1568
+ // src/converters/oas-schema.ts
1569
+ function oapSchemaToReferences(schema, options) {
360
1570
  var _a, _b;
1571
+ if (!schema) {
1572
+ return [];
1573
+ }
361
1574
  const references = [];
362
1575
  const oas = new import_oas.default(schema);
363
1576
  const server = ((_b = (_a = schema.servers) == null ? void 0 : _a[0]) == null ? void 0 : _b.url) || "";
364
- Object.entries(schema.paths).forEach(([path2, oapPath]) => {
1577
+ Object.entries(schema.paths).forEach(([endpointPath, oapPath]) => {
365
1578
  SUPPORTED_HTTP_METHODS.forEach((eachMethod) => {
1579
+ var _a2, _b2, _c, _d;
366
1580
  const httpMethod = eachMethod.toLowerCase();
367
- switch (httpMethod) {
368
- case "get":
369
- break;
370
- case "put":
371
- break;
372
- case "post":
373
- break;
374
- case "delete":
375
- break;
376
- case "patch":
377
- break;
378
- default:
379
- console.error(`Unsupported method v111: ${httpMethod}`);
1581
+ const found = httpMethodToUniformMethod(httpMethod);
1582
+ if (!found) {
1583
+ console.warn(`Unsupported method: ${httpMethod} for path: ${endpointPath}`);
1584
+ return;
1585
+ }
1586
+ if ((options == null ? void 0 : options.regions) && options.regions.length > 0) {
1587
+ const regionKey = `${eachMethod.toUpperCase()} ${endpointPath}`;
1588
+ if (!options.regions.some((region) => region === regionKey)) {
380
1589
  return;
1590
+ }
381
1591
  }
382
1592
  const reference = oapPathToReference(
1593
+ schema,
383
1594
  httpMethod,
384
- path2,
1595
+ endpointPath,
385
1596
  oapPath
386
1597
  );
387
1598
  if (reference) {
388
1599
  const ctx = reference.context;
389
- ctx.path = `${encodeURIComponent(server)}${encodeURIComponent(path2)}`;
390
- const operation = oas.operation(path2, httpMethod);
1600
+ ctx.path = endpointPath;
1601
+ ctx.fullPath = import_node_path2.default.join(server, endpointPath);
1602
+ const operation = oas.operation(endpointPath, httpMethod);
391
1603
  reference.examples.groups = oapExamples(oas, operation);
1604
+ const scopes = [];
1605
+ const oapMethod = oapPath == null ? void 0 : oapPath[httpMethod];
1606
+ if ((_a2 = schema == null ? void 0 : schema.security) == null ? void 0 : _a2.length) {
1607
+ for (const security of schema.security) {
1608
+ for (const securityKey of Object.keys(security)) {
1609
+ if (securityKey === "oauth2" || securityKey === "OAuth2") {
1610
+ const securityScopes = security[securityKey];
1611
+ if (Array.isArray(securityScopes)) {
1612
+ scopes.push(...securityScopes);
1613
+ }
1614
+ }
1615
+ }
1616
+ }
1617
+ }
1618
+ if (oapMethod == null ? void 0 : oapMethod.security) {
1619
+ if (!((_b2 = oapMethod == null ? void 0 : oapMethod.security) == null ? void 0 : _b2.length)) {
1620
+ scopes.length = 0;
1621
+ }
1622
+ for (const security of oapMethod.security) {
1623
+ for (const securityKey of Object.keys(security)) {
1624
+ const securityScheme = (_d = (_c = schema == null ? void 0 : schema.components) == null ? void 0 : _c.securitySchemes) == null ? void 0 : _d[securityKey];
1625
+ if (securityScheme && "type" in securityScheme && securityScheme.type === "oauth2") {
1626
+ const methodScopes = security[securityKey];
1627
+ if (Array.isArray(methodScopes)) {
1628
+ scopes.push(...methodScopes);
1629
+ }
1630
+ }
1631
+ }
1632
+ }
1633
+ }
1634
+ ctx.scopes = scopes;
392
1635
  references.push(reference);
393
1636
  }
394
1637
  });
395
1638
  });
1639
+ const schemas = schemaComponentsToUniformReferences(
1640
+ schema,
1641
+ options
1642
+ );
1643
+ references.push(...schemas);
1644
+ const tags = oas.getTags();
1645
+ sortReferencesByTags(references, tags);
1646
+ references.__internal_options = () => options;
396
1647
  return references;
397
1648
  }
1649
+ function sortReferencesByTags(references, tags) {
1650
+ return references.sort((prev, next) => {
1651
+ var _a, _b;
1652
+ const aTags = ((_a = prev.context) == null ? void 0 : _a.group) || [];
1653
+ const bTags = ((_b = next.context) == null ? void 0 : _b.group) || [];
1654
+ for (const tag of tags) {
1655
+ const aIndex = aTags.indexOf(tag);
1656
+ const bIndex = bTags.indexOf(tag);
1657
+ if (aIndex !== -1 && bIndex !== -1) {
1658
+ return aIndex - bIndex;
1659
+ }
1660
+ if (aIndex !== -1) return -1;
1661
+ if (bIndex !== -1) return 1;
1662
+ }
1663
+ return (aTags[0] || "").localeCompare(bTags[0] || "");
1664
+ });
1665
+ }
1666
+
1667
+ // src/xdocs/pluginSidebar.ts
1668
+ function uniformPluginXDocsSidebar({
1669
+ references,
1670
+ defer
1671
+ }) {
1672
+ let schema;
1673
+ const refByOperationId = {};
1674
+ const refByComponentSchema = {};
1675
+ defer(() => {
1676
+ var _a;
1677
+ if (typeof references.__internal_options === "function") {
1678
+ const options = references.__internal_options();
1679
+ if ((_a = options == null ? void 0 : options.regions) == null ? void 0 : _a.length) {
1680
+ return {};
1681
+ }
1682
+ }
1683
+ const output = [];
1684
+ if (!schema) {
1685
+ return {};
1686
+ }
1687
+ const xDocs = schema["x-docs"];
1688
+ if (!(xDocs == null ? void 0 : xDocs.sidebar)) {
1689
+ return {};
1690
+ }
1691
+ const navigationMap = {};
1692
+ for (let i = 0; i < xDocs.sidebar.length; i++) {
1693
+ const navGroup = xDocs.sidebar[i];
1694
+ if (!navGroup) {
1695
+ continue;
1696
+ }
1697
+ const uniqueKey = `${navGroup.group}-${i}`;
1698
+ navigationMap[uniqueKey] = {
1699
+ id: navGroup.group,
1700
+ title: navGroup.group,
1701
+ beta: false,
1702
+ index: i
1703
+ };
1704
+ }
1705
+ for (let i = 0; i < xDocs.sidebar.length; i++) {
1706
+ const group = xDocs.sidebar[i];
1707
+ const uniqueKey = `${group.group}-${i}`;
1708
+ const navGroup = navigationMap[uniqueKey];
1709
+ if (!navGroup) {
1710
+ console.warn(`No navigation group found for group: ${group.group}`);
1711
+ continue;
1712
+ }
1713
+ if (!Array.isArray(group.pages)) {
1714
+ continue;
1715
+ }
1716
+ processGroupPages(xDocs, group.pages, [group.group], navGroup, output);
1717
+ }
1718
+ if (Array.isArray(references)) {
1719
+ references.length = 0;
1720
+ references.push(...output);
1721
+ } else {
1722
+ references = output[0] || references;
1723
+ }
1724
+ return {};
1725
+ });
1726
+ function processGroupPages(xDocs, pages, groupPath, navGroup, output, parentPath) {
1727
+ for (const page of pages) {
1728
+ if ("pages" in page && Array.isArray(page.pages)) {
1729
+ processGroupPages(xDocs, page.pages, [...groupPath, page.group], navGroup, output, page.path);
1730
+ } else if ("type" in page && "key" in page) {
1731
+ processPage(xDocs, page, groupPath, navGroup, output, parentPath);
1732
+ }
1733
+ }
1734
+ }
1735
+ function processPage(xDocs, page, groupPath, navGroup, output, parentPath) {
1736
+ let uniformRef;
1737
+ switch (page.type) {
1738
+ case "endpoint": {
1739
+ const operationRef = refByOperationId[page.key];
1740
+ if (!operationRef) {
1741
+ console.warn(`No operation found for key: ${page.key} in group ${groupPath.join("/")}`);
1742
+ return;
1743
+ }
1744
+ uniformRef = operationRef;
1745
+ break;
1746
+ }
1747
+ case "object": {
1748
+ const componentRef = refByComponentSchema[page.key];
1749
+ if (!componentRef) {
1750
+ console.warn(`No component schema found for key: ${page.key} in group ${groupPath.join("/")}`);
1751
+ return;
1752
+ }
1753
+ const selector = componentRef.__UNSAFE_selector;
1754
+ if (!selector || typeof selector !== "function") {
1755
+ return;
1756
+ }
1757
+ const component = selector("[component]");
1758
+ if (!component) {
1759
+ console.warn(`No component schema found for key: ${page.key} in group ${groupPath.join("/")}`);
1760
+ return;
1761
+ }
1762
+ let componentMeta;
1763
+ if (component.allOf) {
1764
+ let found = false;
1765
+ for (const item of component.allOf) {
1766
+ const docsMeta = item["x-docs"];
1767
+ if (docsMeta && found) {
1768
+ console.warn(`Multiple x-docs found in allOf for component schema: ${page.key} in group ${groupPath.join("/")}`);
1769
+ }
1770
+ if (docsMeta) {
1771
+ found = true;
1772
+ componentMeta = docsMeta;
1773
+ break;
1774
+ }
1775
+ }
1776
+ if (!found) {
1777
+ console.warn(`No x-docs found in allOf for component schema: ${page.key} in group ${groupPath.join("/")}`);
1778
+ return;
1779
+ }
1780
+ } else {
1781
+ const docsMeta = component["x-docs"];
1782
+ if (docsMeta) {
1783
+ componentMeta = docsMeta;
1784
+ }
1785
+ }
1786
+ uniformRef = componentRef;
1787
+ if (!componentMeta) {
1788
+ break;
1789
+ }
1790
+ componentRef.title = componentMeta.name || componentRef.title;
1791
+ if (componentMeta.example) {
1792
+ const exampleGroups = oasXDocsExamples(componentMeta.example);
1793
+ uniformRef.examples = {
1794
+ groups: exampleGroups
1795
+ };
1796
+ }
1797
+ break;
1798
+ }
1799
+ default: {
1800
+ console.warn(`Unknown page type: ${page.type} in group ${groupPath.join("/")}`);
1801
+ return;
1802
+ }
1803
+ }
1804
+ if (!uniformRef) {
1805
+ return;
1806
+ }
1807
+ if (xDocs.sidebarPathStrategy === "inherit") {
1808
+ const ctx = uniformRef.context;
1809
+ let firstPart = "";
1810
+ if (parentPath) {
1811
+ firstPart = parentPath;
1812
+ } else {
1813
+ firstPart = (ctx == null ? void 0 : ctx.path) || "";
1814
+ }
1815
+ const canonical2 = joinPaths(firstPart || "", page.path);
1816
+ if (canonical2) {
1817
+ uniformRef.canonical = canonical2;
1818
+ }
1819
+ } else if (page.path) {
1820
+ uniformRef.canonical = joinPaths(parentPath, page.path);
1821
+ } else if (parentPath) {
1822
+ uniformRef.canonical = parentPath;
1823
+ }
1824
+ if (!uniformRef.context) {
1825
+ uniformRef.context = {};
1826
+ }
1827
+ uniformRef.context.group = groupPath;
1828
+ output.push(uniformRef);
1829
+ }
1830
+ return function pluginXDocsSidebarInner(ref) {
1831
+ var _a, _b;
1832
+ const selector = ref.__UNSAFE_selector;
1833
+ if (!selector || typeof selector !== "function") {
1834
+ return;
1835
+ }
1836
+ const oapSchema = selector("[schema]");
1837
+ if (!oapSchema) {
1838
+ return;
1839
+ }
1840
+ schema = oapSchema;
1841
+ const ctx = ref.context;
1842
+ if (ctx == null ? void 0 : ctx.componentSchema) {
1843
+ refByComponentSchema[ctx.componentSchema] = ref;
1844
+ }
1845
+ const methodPath = selector("[method] [path]");
1846
+ if (!methodPath) {
1847
+ return;
1848
+ }
1849
+ const oapMethod = selector("[method]");
1850
+ if (!oapMethod) {
1851
+ return;
1852
+ }
1853
+ const operationId = methodPath.operationId;
1854
+ if (operationId) {
1855
+ refByOperationId[operationId] = ref;
1856
+ }
1857
+ const methodId = (((_a = oapMethod == null ? void 0 : oapMethod.httpMethod) == null ? void 0 : _a.toUpperCase()) + " " + (oapMethod == null ? void 0 : oapMethod.path) || "").trim();
1858
+ if (methodId) {
1859
+ refByOperationId[methodId] = ref;
1860
+ }
1861
+ const meta = methodPath["x-docs"];
1862
+ if (!meta) {
1863
+ return;
1864
+ }
1865
+ if (meta.name) {
1866
+ ref.title = meta.name;
1867
+ }
1868
+ if (meta.group) {
1869
+ if (ref.context) {
1870
+ ref.context.group = [meta.group];
1871
+ }
1872
+ }
1873
+ if (!ref.description) {
1874
+ ref.description = methodPath.summary || "";
1875
+ }
1876
+ if (meta.examples) {
1877
+ const exampleGroups = oasXDocsExamples(meta.examples);
1878
+ ref.examples = {
1879
+ groups: exampleGroups
1880
+ };
1881
+ }
1882
+ if (meta.returns) {
1883
+ if ((_b = ref.definitions) == null ? void 0 : _b.length) {
1884
+ ref.definitions[ref.definitions.length - 1] = {
1885
+ title: ref.definitions[ref.definitions.length - 1].title,
1886
+ description: meta.returns,
1887
+ properties: []
1888
+ };
1889
+ } else {
1890
+ ref.definitions = [
1891
+ {
1892
+ title: "Response",
1893
+ description: meta.returns,
1894
+ properties: []
1895
+ }
1896
+ ];
1897
+ }
1898
+ }
1899
+ };
1900
+ }
1901
+ function oasXDocsExamples(examples) {
1902
+ const groups = [];
1903
+ if (examples) {
1904
+ if (Array.isArray(examples)) {
1905
+ const requestExamples = [];
1906
+ examples.forEach((example) => {
1907
+ if (example.request) {
1908
+ const tabs = [];
1909
+ if (typeof example.request === "string") {
1910
+ tabs.push({
1911
+ title: "",
1912
+ language: "json",
1913
+ code: example.request
1914
+ });
1915
+ } else {
1916
+ for (let lang of Object.keys(example.request)) {
1917
+ const code = example.request[lang] || "";
1918
+ const language = lang === "curl" ? "bash" : lang === "node.js" ? "js" : lang;
1919
+ tabs.push({
1920
+ title: lang,
1921
+ language,
1922
+ code
1923
+ });
1924
+ }
1925
+ }
1926
+ if (tabs.length > 0) {
1927
+ requestExamples.push({
1928
+ description: example.title || "",
1929
+ codeblock: {
1930
+ title: example.title || "",
1931
+ tabs
1932
+ }
1933
+ });
1934
+ }
1935
+ }
1936
+ });
1937
+ if (requestExamples.length > 0) {
1938
+ groups.push({
1939
+ description: "Example request",
1940
+ examples: requestExamples
1941
+ });
1942
+ }
1943
+ const responseExamples = [];
1944
+ examples.forEach((example) => {
1945
+ if (example.response) {
1946
+ const tabs = [];
1947
+ if (typeof example.response === "string") {
1948
+ tabs.push({
1949
+ title: "",
1950
+ language: "json",
1951
+ code: example.response
1952
+ });
1953
+ } else {
1954
+ for (let lang of Object.keys(example.response)) {
1955
+ const code = example.response[lang] || "";
1956
+ const language = lang === "curl" ? "bash" : lang === "node.js" ? "js" : lang;
1957
+ tabs.push({
1958
+ title: lang,
1959
+ language,
1960
+ code
1961
+ });
1962
+ }
1963
+ }
1964
+ if (tabs.length > 0) {
1965
+ responseExamples.push({
1966
+ description: example.title || "",
1967
+ codeblock: {
1968
+ title: example.title || "",
1969
+ tabs
1970
+ }
1971
+ });
1972
+ }
1973
+ }
1974
+ });
1975
+ if (responseExamples.length > 0) {
1976
+ groups.push({
1977
+ description: "Example response",
1978
+ examples: responseExamples
1979
+ });
1980
+ }
1981
+ } else {
1982
+ if (typeof examples === "string") {
1983
+ groups.push({
1984
+ description: "Example",
1985
+ examples: [
1986
+ {
1987
+ description: "",
1988
+ codeblock: {
1989
+ tabs: [
1990
+ {
1991
+ title: "",
1992
+ language: "json",
1993
+ code: examples
1994
+ }
1995
+ ]
1996
+ }
1997
+ }
1998
+ ]
1999
+ });
2000
+ } else {
2001
+ if (examples.request) {
2002
+ const tabs = [];
2003
+ if (typeof examples.request === "string") {
2004
+ tabs.push({
2005
+ title: "",
2006
+ language: "json",
2007
+ code: examples.request || ""
2008
+ });
2009
+ } else {
2010
+ for (let lang of Object.keys(examples.request)) {
2011
+ const code = examples.request[lang] || "";
2012
+ switch (lang) {
2013
+ case "curl":
2014
+ lang = "bash";
2015
+ break;
2016
+ case "node.js":
2017
+ lang = "js";
2018
+ break;
2019
+ default:
2020
+ break;
2021
+ }
2022
+ tabs.push({
2023
+ title: lang,
2024
+ language: lang,
2025
+ code
2026
+ });
2027
+ }
2028
+ }
2029
+ groups.push({
2030
+ description: "Example request",
2031
+ examples: [
2032
+ {
2033
+ description: "",
2034
+ codeblock: {
2035
+ tabs
2036
+ }
2037
+ }
2038
+ ]
2039
+ });
2040
+ }
2041
+ if (examples.response) {
2042
+ const tabs = [];
2043
+ if (typeof examples.response === "string") {
2044
+ tabs.push({
2045
+ title: "",
2046
+ language: "json",
2047
+ code: examples.response || ""
2048
+ });
2049
+ } else {
2050
+ for (let lang of Object.keys(examples.response)) {
2051
+ const code = examples.response[lang] || "";
2052
+ switch (lang) {
2053
+ case "curl":
2054
+ lang = "bash";
2055
+ break;
2056
+ case "node.js":
2057
+ lang = "js";
2058
+ break;
2059
+ default:
2060
+ break;
2061
+ }
2062
+ tabs.push({
2063
+ title: lang,
2064
+ language: lang,
2065
+ code
2066
+ });
2067
+ }
2068
+ }
2069
+ groups.push({
2070
+ description: "Example response",
2071
+ examples: [
2072
+ {
2073
+ description: "",
2074
+ codeblock: {
2075
+ tabs
2076
+ }
2077
+ }
2078
+ ]
2079
+ });
2080
+ }
2081
+ }
2082
+ }
2083
+ }
2084
+ return groups;
2085
+ }
2086
+ function joinPaths(...paths) {
2087
+ return paths.filter(Boolean).map((path4) => {
2088
+ path4 = path4.replace(/^\/+|\/+$/g, "");
2089
+ return path4 ? `/${path4}` : "";
2090
+ }).join("").replace(/\/+/g, "/").replace(/\/\{[^}]+\}/g, "").replace(/\/:[^/]+/g, "");
2091
+ }
398
2092
  // Annotate the CommonJS export names for ESM import in node:
399
2093
  0 && (module.exports = {
400
2094
  deferencedOpenAPI,
401
- oapSchemaToReferences
2095
+ getXDocs,
2096
+ oapResponseOperationToUniformDefinition,
2097
+ oapSchemaToReferences,
2098
+ uniformPluginXDocsSidebar
402
2099
  });
403
2100
  //# sourceMappingURL=index.cjs.map