fumadocs-openapi 3.1.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +46 -16
- package/dist/index.js +31 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,48 @@ interface Renderer {
|
|
|
44
44
|
}
|
|
45
45
|
declare const defaultRenderer: Renderer;
|
|
46
46
|
|
|
47
|
+
interface CodeSample {
|
|
48
|
+
lang: string;
|
|
49
|
+
label: string;
|
|
50
|
+
source: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface RouteInformation {
|
|
54
|
+
path: string;
|
|
55
|
+
summary?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
methods: MethodInformation[];
|
|
58
|
+
}
|
|
59
|
+
interface MethodInformation extends OpenAPIV3.OperationObject {
|
|
60
|
+
parameters: OpenAPIV3.ParameterObject[];
|
|
61
|
+
method: string;
|
|
62
|
+
}
|
|
63
|
+
interface RenderContext {
|
|
64
|
+
renderer: Renderer;
|
|
65
|
+
document: OpenAPIV3.Document;
|
|
66
|
+
baseUrl: string;
|
|
67
|
+
generateCodeSamples?: (endpoint: Endpoint) => CodeSample[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface Endpoint {
|
|
71
|
+
/**
|
|
72
|
+
* URL, including path and query parameters
|
|
73
|
+
*/
|
|
74
|
+
url: string;
|
|
75
|
+
method: string;
|
|
76
|
+
body?: unknown;
|
|
77
|
+
responses: Record<string, Response>;
|
|
78
|
+
parameters: Parameter[];
|
|
79
|
+
}
|
|
80
|
+
interface Response {
|
|
81
|
+
schema: OpenAPIV3.SchemaObject;
|
|
82
|
+
}
|
|
83
|
+
interface Parameter {
|
|
84
|
+
name: string;
|
|
85
|
+
in: string;
|
|
86
|
+
schema: OpenAPIV3.SchemaObject;
|
|
87
|
+
}
|
|
88
|
+
|
|
47
89
|
interface GenerateOptions {
|
|
48
90
|
/**
|
|
49
91
|
* The imports of your MDX components.
|
|
@@ -60,6 +102,10 @@ interface GenerateOptions {
|
|
|
60
102
|
* A `full: true` property will be added by default.
|
|
61
103
|
*/
|
|
62
104
|
frontmatter?: (title: string, description: string | undefined) => Record<string, unknown>;
|
|
105
|
+
/**
|
|
106
|
+
* Generate code samples for endpoint
|
|
107
|
+
*/
|
|
108
|
+
generateCodeSamples?: (endpoint: Endpoint) => CodeSample[];
|
|
63
109
|
renderer?: Partial<Renderer>;
|
|
64
110
|
}
|
|
65
111
|
interface GenerateTagOutput {
|
|
@@ -99,22 +145,6 @@ interface Config extends GenerateOptions {
|
|
|
99
145
|
}
|
|
100
146
|
declare function generateFiles({ input, output, name: nameFn, per, cwd, ...options }: Config): Promise<void>;
|
|
101
147
|
|
|
102
|
-
interface RouteInformation {
|
|
103
|
-
path: string;
|
|
104
|
-
summary?: string;
|
|
105
|
-
description?: string;
|
|
106
|
-
methods: MethodInformation[];
|
|
107
|
-
}
|
|
108
|
-
interface MethodInformation extends OpenAPIV3.OperationObject {
|
|
109
|
-
parameters: OpenAPIV3.ParameterObject[];
|
|
110
|
-
method: string;
|
|
111
|
-
}
|
|
112
|
-
interface RenderContext {
|
|
113
|
-
renderer: Renderer;
|
|
114
|
-
document: OpenAPIV3.Document;
|
|
115
|
-
baseUrl: string;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
148
|
declare function createElement(name: string, props: object, ...child: string[]): string;
|
|
119
149
|
|
|
120
150
|
export { type APIInfoProps, type Config, type GenerateOperationOutput, type GenerateOptions, type GenerateTagOutput, type MethodInformation, type ObjectCollapsibleProps, type PropertyProps, type RenderContext, type Renderer, type RequestProps, type ResponseProps, type ResponsesProps, type RouteInformation, createElement, defaultRenderer, generate, generateFiles, generateOperations, generateTags };
|
package/dist/index.js
CHANGED
|
@@ -448,21 +448,30 @@ async function renderOperation(path, method, ctx, noTitle = false) {
|
|
|
448
448
|
info.push(heading(level, group), ...parameters);
|
|
449
449
|
}
|
|
450
450
|
info.push(getResponseTable(method));
|
|
451
|
+
const samples = dedupe([
|
|
452
|
+
{
|
|
453
|
+
label: "cURL",
|
|
454
|
+
source: getSampleRequest(endpoint),
|
|
455
|
+
lang: "bash"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
label: "JavaScript",
|
|
459
|
+
source: getSampleRequest2(endpoint),
|
|
460
|
+
lang: "js"
|
|
461
|
+
},
|
|
462
|
+
...ctx.generateCodeSamples?.(endpoint) ?? [],
|
|
463
|
+
...method["x-codeSamples"] ?? []
|
|
464
|
+
]);
|
|
451
465
|
example.push(
|
|
452
466
|
ctx.renderer.Requests(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
ctx.renderer.Request({
|
|
456
|
-
name:
|
|
457
|
-
code:
|
|
458
|
-
language:
|
|
459
|
-
}),
|
|
460
|
-
ctx.renderer.Request({
|
|
461
|
-
name: "JavaScript",
|
|
462
|
-
code: getSampleRequest2(endpoint),
|
|
463
|
-
language: "js"
|
|
467
|
+
samples.map((s) => s.label),
|
|
468
|
+
samples.map(
|
|
469
|
+
(s) => ctx.renderer.Request({
|
|
470
|
+
name: s.label,
|
|
471
|
+
code: s.source,
|
|
472
|
+
language: s.lang
|
|
464
473
|
})
|
|
465
|
-
|
|
474
|
+
)
|
|
466
475
|
)
|
|
467
476
|
);
|
|
468
477
|
example.push(await getResponseTabs(endpoint, method, ctx));
|
|
@@ -471,6 +480,16 @@ async function renderOperation(path, method, ctx, noTitle = false) {
|
|
|
471
480
|
ctx.renderer.APIExample(example)
|
|
472
481
|
]);
|
|
473
482
|
}
|
|
483
|
+
function dedupe(samples) {
|
|
484
|
+
const set = /* @__PURE__ */ new Set();
|
|
485
|
+
const out = [];
|
|
486
|
+
for (let i = samples.length - 1; i >= 0; i--) {
|
|
487
|
+
if (set.has(samples[i].label)) continue;
|
|
488
|
+
set.add(samples[i].label);
|
|
489
|
+
out.unshift(samples[i]);
|
|
490
|
+
}
|
|
491
|
+
return out;
|
|
492
|
+
}
|
|
474
493
|
function getAuthSection(requirements, { document, renderer }) {
|
|
475
494
|
const info = [];
|
|
476
495
|
const schemas = document.components?.securitySchemes ?? {};
|