@xyd-js/openapi 0.1.0-xyd.11 → 0.1.0-xyd.13

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