fumadocs-openapi 3.1.2 → 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 +34 -13
- 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
|
@@ -182,8 +182,10 @@ function createEndpoint(path, method, baseUrl) {
|
|
|
182
182
|
toSampleInput(value)
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
|
+
if (queryParams.size > 0)
|
|
186
|
+
pathWithParameters = `${pathWithParameters}?${queryParams.toString()}`;
|
|
185
187
|
return {
|
|
186
|
-
url: new URL(pathWithParameters
|
|
188
|
+
url: new URL(`${baseUrl}${pathWithParameters}`).toString(),
|
|
187
189
|
body: bodySchema ? generateInput(method.method, bodySchema) : void 0,
|
|
188
190
|
responses,
|
|
189
191
|
method: method.method,
|
|
@@ -446,21 +448,30 @@ async function renderOperation(path, method, ctx, noTitle = false) {
|
|
|
446
448
|
info.push(heading(level, group), ...parameters);
|
|
447
449
|
}
|
|
448
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
|
+
]);
|
|
449
465
|
example.push(
|
|
450
466
|
ctx.renderer.Requests(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
ctx.renderer.Request({
|
|
454
|
-
name:
|
|
455
|
-
code:
|
|
456
|
-
language:
|
|
457
|
-
}),
|
|
458
|
-
ctx.renderer.Request({
|
|
459
|
-
name: "JavaScript",
|
|
460
|
-
code: getSampleRequest2(endpoint),
|
|
461
|
-
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
|
|
462
473
|
})
|
|
463
|
-
|
|
474
|
+
)
|
|
464
475
|
)
|
|
465
476
|
);
|
|
466
477
|
example.push(await getResponseTabs(endpoint, method, ctx));
|
|
@@ -469,6 +480,16 @@ async function renderOperation(path, method, ctx, noTitle = false) {
|
|
|
469
480
|
ctx.renderer.APIExample(example)
|
|
470
481
|
]);
|
|
471
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
|
+
}
|
|
472
493
|
function getAuthSection(requirements, { document, renderer }) {
|
|
473
494
|
const info = [];
|
|
474
495
|
const schemas = document.components?.securitySchemes ?? {};
|