fumadocs-openapi 10.1.2 → 10.1.4
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/server/create.d.ts +1 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +8 -0
- package/dist/ui/api-page.js +1 -1
- package/dist/ui/operation/index.js +1 -1
- package/dist/ui/operation/request-tabs.d.ts.map +1 -1
- package/dist/ui/operation/request-tabs.js +13 -19
- package/dist/utils/schema.d.ts +12 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +19 -0
- package/package.json +7 -7
package/dist/server/create.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface OpenAPIOptions {
|
|
|
24
24
|
export interface OpenAPIServer {
|
|
25
25
|
createProxy: typeof createProxy;
|
|
26
26
|
getSchemas: () => Promise<ProcessedSchemaMap>;
|
|
27
|
+
getSchema: (document: string) => Promise<ProcessedDocument>;
|
|
27
28
|
readonly options: OpenAPIOptions;
|
|
28
29
|
}
|
|
29
30
|
export declare function createOpenAPI(options?: OpenAPIOptions): OpenAPIServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,CACrB,MAAM,EACN,MAAM,GAAG,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CACnD,CAAC;AACF,KAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC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aAAa;IAC5B,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC5D,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CA2CzE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GACtC,kBAAkB,CAQpB"}
|
package/dist/server/create.js
CHANGED
|
@@ -20,6 +20,14 @@ export function createOpenAPI(options = {}) {
|
|
|
20
20
|
return {
|
|
21
21
|
options,
|
|
22
22
|
createProxy,
|
|
23
|
+
async getSchema(document) {
|
|
24
|
+
const schemas = await getSchemas();
|
|
25
|
+
if (document in schemas)
|
|
26
|
+
return schemas[document];
|
|
27
|
+
console.warn(`[Fumadocs OpenAPI] the document "${document}" is not listed in the input array, this may not be expected.`);
|
|
28
|
+
// do not cache unlisted documents
|
|
29
|
+
return processDocument(document);
|
|
30
|
+
},
|
|
23
31
|
async getSchemas() {
|
|
24
32
|
if (disableCache)
|
|
25
33
|
return getSchemas();
|
package/dist/ui/api-page.js
CHANGED
|
@@ -40,7 +40,7 @@ export function createAPIPage(server, options = {}) {
|
|
|
40
40
|
return async function APIPageWrapper({ document, ...props }) {
|
|
41
41
|
let processed;
|
|
42
42
|
if (typeof document === 'string') {
|
|
43
|
-
processed =
|
|
43
|
+
processed = await server.getSchema(document);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
processed = await document;
|
|
@@ -84,7 +84,7 @@ export async function Operation({ type = 'operation', path, method, ctx, showTit
|
|
|
84
84
|
});
|
|
85
85
|
authNode = (_jsxs(SelectTabs, { defaultValue: items[0].value, children: [_jsxs("div", { className: "flex items-start justify-between gap-2 mt-10", children: [ctx.renderHeading(headingLevel, 'Authorization', {
|
|
86
86
|
className: 'my-0!',
|
|
87
|
-
}), items.length > 1 ? (_jsx(SelectTabTrigger, { items: items })) : (_jsx("
|
|
87
|
+
}), items.length > 1 ? (_jsx(SelectTabTrigger, { items: items })) : (_jsx("div", { className: "not-prose", children: items[0].label }))] }), securities.map((security, i) => (_jsx(SelectTab, { value: items[i].value, children: Object.entries(security).map(([key, scopes]) => {
|
|
88
88
|
const scheme = securitySchemes?.[key];
|
|
89
89
|
if (!scheme)
|
|
90
90
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-tabs.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/request-tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"request-tabs.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/request-tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,gBAAgB,CAAC;AASxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAWpE,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACzC,GAAG,EAAE,aAAa,GACjB,kBAAkB,EAAE,CA0CtB;AA2ED,wBAAsB,WAAW,CAAC,EAChC,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC1C,GAAG,EAAE,aAAa,CAAC;CACpB,kIASA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { getPreferredType } from '../../utils/schema.js';
|
|
2
|
+
import { getPreferredType, pickExample, } from '../../utils/schema.js';
|
|
3
3
|
import { AccordionContent, AccordionHeader, AccordionItem, Accordions, AccordionTrigger, } from '../../ui/components/accordion.js';
|
|
4
4
|
import { sample } from 'openapi-sampler';
|
|
5
5
|
import { encodeRequestData } from '../../requests/media/encode.js';
|
|
@@ -46,24 +46,18 @@ function getRequestData(path, method, sampleKey, _ctx) {
|
|
|
46
46
|
method: method.method,
|
|
47
47
|
};
|
|
48
48
|
for (const param of method.parameters ?? []) {
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if (param.required) {
|
|
63
|
-
value ?? (value = sample(schema));
|
|
64
|
-
}
|
|
65
|
-
else if (value === undefined) {
|
|
66
|
-
continue;
|
|
49
|
+
let value = pickExample(param);
|
|
50
|
+
if (value === undefined && param.required) {
|
|
51
|
+
if (param.schema) {
|
|
52
|
+
value = sample(param.schema);
|
|
53
|
+
}
|
|
54
|
+
else if (param.content) {
|
|
55
|
+
const type = getPreferredType(param.content);
|
|
56
|
+
const content = type ? param.content[type] : undefined;
|
|
57
|
+
if (!content || !content.schema)
|
|
58
|
+
throw new Error(`Cannot find "${param.name}" parameter info for media type "${type}" in ${path} ${method.method}`);
|
|
59
|
+
value = sample(content.schema);
|
|
60
|
+
}
|
|
67
61
|
}
|
|
68
62
|
switch (param.in) {
|
|
69
63
|
case 'cookie':
|
package/dist/utils/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
2
2
|
import type { MethodInformation, OperationObject, PathItemObject, ReferenceObject, TagObject } from '../types.js';
|
|
3
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
4
|
export declare const methodKeys: readonly ["get", "post", "patch", "delete", "head", "put"];
|
|
4
5
|
export type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
5
6
|
[K in keyof T]: NoReference<T[K]>;
|
|
@@ -9,11 +10,21 @@ type NoReferenceJSONSchema<T> = T extends (infer I)[] ? NoReference<I>[] : T ext
|
|
|
9
10
|
} ? Omit<T, '$ref'> : T;
|
|
10
11
|
export type ParsedSchema = JSONSchema;
|
|
11
12
|
export type ResolvedSchema = NoReferenceJSONSchema<ParsedSchema>;
|
|
12
|
-
export declare function getPreferredType
|
|
13
|
+
export declare function getPreferredType(body: Record<string, unknown>): string | undefined;
|
|
13
14
|
export declare function getTagDisplayName(tag: TagObject): string;
|
|
14
15
|
/**
|
|
15
16
|
* Summarize method endpoint information
|
|
16
17
|
*/
|
|
17
18
|
export declare function createMethod(method: string, path: NoReference<PathItemObject>, operation: NoReference<OperationObject>): MethodInformation;
|
|
19
|
+
interface ExampleLike {
|
|
20
|
+
example?: unknown;
|
|
21
|
+
examples?: {
|
|
22
|
+
[media: string]: OpenAPIV3_1.ExampleObject;
|
|
23
|
+
};
|
|
24
|
+
content?: {
|
|
25
|
+
[media: string]: OpenAPIV3_1.MediaTypeObject;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare function pickExample(value: ExampleLike): unknown | undefined;
|
|
18
29
|
export {};
|
|
19
30
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACV,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,UAAU,4DAOb,CAAC;AAEX,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9C,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,eAAe,GACvB,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,GAC3B,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,GACD,CAAC,CAAC;AAEV,KAAK,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACjD,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACzB,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,GACf,CAAC,CAAC;AAER,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AACtC,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEjE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,GAAG,SAAS,CAIpB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAIxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC,EACjC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,GACtC,iBAAiB,CAQnB;AAED,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,aAAa,CAAC;KAC5C,CAAC;IACF,OAAO,CAAC,EAAE;QACR,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,eAAe,CAAC;KAC9C,CAAC;CACH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,CAmBnE"}
|
package/dist/utils/schema.js
CHANGED
|
@@ -29,3 +29,22 @@ export function createMethod(method, path, operation) {
|
|
|
29
29
|
method: method.toUpperCase(),
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
export function pickExample(value) {
|
|
33
|
+
if (value.example !== undefined) {
|
|
34
|
+
return value.example;
|
|
35
|
+
}
|
|
36
|
+
if (value.content) {
|
|
37
|
+
const type = getPreferredType(value.content);
|
|
38
|
+
const content = type ? value.content[type] : undefined;
|
|
39
|
+
if (type && content) {
|
|
40
|
+
const out = value.examples?.[type].value ?? pickExample(content);
|
|
41
|
+
if (out !== undefined)
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (value.examples) {
|
|
46
|
+
const examples = Object.values(value.examples);
|
|
47
|
+
if (examples.length > 0)
|
|
48
|
+
return examples[0].value;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.4",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
55
55
|
"@radix-ui/react-select": "^2.2.6",
|
|
56
56
|
"@radix-ui/react-slot": "^1.2.4",
|
|
57
|
-
"@scalar/json-magic": "^0.8.
|
|
58
|
-
"@scalar/openapi-parser": "0.23.
|
|
57
|
+
"@scalar/json-magic": "^0.8.6",
|
|
58
|
+
"@scalar/openapi-parser": "0.23.7",
|
|
59
59
|
"ajv": "^8.17.1",
|
|
60
60
|
"class-variance-authority": "^0.7.1",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
@@ -69,18 +69,18 @@
|
|
|
69
69
|
"xml-js": "^1.6.11"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@scalar/api-client-react": "^1.3.
|
|
72
|
+
"@scalar/api-client-react": "^1.3.55",
|
|
73
73
|
"@types/js-yaml": "^4.0.9",
|
|
74
74
|
"@types/node": "24.10.2",
|
|
75
75
|
"@types/openapi-sampler": "^1.0.3",
|
|
76
76
|
"@types/react": "^19.2.7",
|
|
77
77
|
"json-schema-typed": "^8.0.2",
|
|
78
78
|
"openapi-types": "^12.1.3",
|
|
79
|
-
"tailwindcss": "^4.1.
|
|
79
|
+
"tailwindcss": "^4.1.18",
|
|
80
80
|
"tsc-alias": "^1.8.16",
|
|
81
81
|
"eslint-config-custom": "0.0.0",
|
|
82
|
-
"fumadocs-
|
|
83
|
-
"fumadocs-
|
|
82
|
+
"fumadocs-ui": "16.2.5",
|
|
83
|
+
"fumadocs-core": "16.2.5",
|
|
84
84
|
"tsconfig": "0.0.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|