fumadocs-openapi 9.0.17 → 9.1.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/media/adapter.d.ts +47 -16
- package/dist/media/adapter.d.ts.map +1 -1
- package/dist/media/adapter.js +3 -4
- package/dist/playground/client.d.ts +6 -4
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +19 -18
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +14 -24
- package/dist/playground/index.d.ts +3 -5
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +2 -4
- package/dist/render/api-page.d.ts.map +1 -1
- package/dist/render/api-page.js +2 -8
- package/dist/render/operation/api-example.d.ts +3 -2
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +8 -6
- package/dist/render/operation/get-request-data.d.ts +2 -2
- package/dist/render/operation/get-request-data.d.ts.map +1 -1
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +3 -2
- package/dist/render/schema.d.ts +1 -1
- package/dist/render/schema.d.ts.map +1 -1
- package/dist/render/schema.js +11 -12
- package/dist/requests/_shared.d.ts +20 -4
- package/dist/requests/_shared.d.ts.map +1 -1
- package/dist/requests/_shared.js +113 -0
- package/dist/requests/csharp.d.ts.map +1 -1
- package/dist/requests/csharp.js +12 -8
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +5 -6
- package/dist/requests/go.d.ts +1 -1
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +6 -6
- package/dist/requests/java.d.ts.map +1 -1
- package/dist/requests/java.js +8 -8
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +9 -6
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +12 -5
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/components/accordion.d.ts.map +1 -1
- package/dist/ui/components/accordion.js +1 -1
- package/dist/ui/contexts/api.d.ts +2 -1
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.d.ts +5 -4
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +14 -11
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +8 -2
- package/dist/ui/lazy.d.ts +2 -1
- package/dist/ui/lazy.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.js +13 -8
- package/dist/utils/process-document.d.ts.map +1 -1
- package/dist/utils/process-document.js +8 -11
- package/dist/utils/schema-to-string.d.ts +2 -1
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +54 -46
- package/dist/utils/url.js +10 -12
- package/package.json +5 -5
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { compile } from '@fumari/json-schema-to-typescript';
|
|
2
2
|
export async function getTypescriptSchema(schema, dereferenceMap) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
try {
|
|
4
|
+
const cloned = structuredClone({ schema, dereferenceMap });
|
|
5
|
+
return await compile(cloned.schema, 'Response', {
|
|
6
|
+
$refOptions: false,
|
|
7
|
+
schemaToId: cloned.dereferenceMap,
|
|
8
|
+
bannerComment: '',
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
enableConstEnums: false,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
console.warn('Failed to generate typescript schema:', e);
|
|
15
|
+
}
|
|
11
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-document.d.ts","sourceRoot":"","sources":["../../src/utils/process-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"process-document.d.ts","sourceRoot":"","sources":["../../src/utils/process-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAE/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAChC,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC;CACtB,CAAC;AAIF;;GAEG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,aAAa,EACpB,YAAY,UAAQ,GACnB,OAAO,CAAC,iBAAiB,CAAC,CA+B5B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetchUrls } from '@scalar/openapi-parser/plugins
|
|
3
|
-
import { readFiles } from '@scalar/openapi-parser/plugins/read-files';
|
|
1
|
+
import { bundle, dereference, upgrade } from '@scalar/openapi-parser';
|
|
2
|
+
import { fetchUrls, readFiles } from '@scalar/openapi-parser/plugins';
|
|
4
3
|
const cache = new Map();
|
|
5
4
|
/**
|
|
6
5
|
* process & reference input document to a Fumadocs OpenAPI compatible format
|
|
@@ -10,15 +9,13 @@ export async function processDocument(input, disableCache = false) {
|
|
|
10
9
|
if (cached)
|
|
11
10
|
return cached;
|
|
12
11
|
const dereferenceMap = new Map();
|
|
13
|
-
|
|
14
|
-
plugins: [
|
|
12
|
+
let document = await bundle(input, {
|
|
13
|
+
plugins: [fetchUrls(), readFiles()],
|
|
14
|
+
treeShake: false,
|
|
15
15
|
});
|
|
16
|
-
if (loaded.errors && loaded.errors.length > 0) {
|
|
17
|
-
throw new Error(loaded.errors.map((err) => `${err.code}: ${err.message}`).join('\n'));
|
|
18
|
-
}
|
|
19
16
|
// upgrade
|
|
20
|
-
|
|
21
|
-
const { schema: dereferenced } = await dereference(
|
|
17
|
+
document = upgrade(document).specification;
|
|
18
|
+
const { schema: dereferenced } = await dereference(document, {
|
|
22
19
|
onDereference({ ref, schema }) {
|
|
23
20
|
dereferenceMap.set(schema, ref);
|
|
24
21
|
},
|
|
@@ -26,7 +23,7 @@ export async function processDocument(input, disableCache = false) {
|
|
|
26
23
|
const processed = {
|
|
27
24
|
document: dereferenced,
|
|
28
25
|
dereferenceMap,
|
|
29
|
-
downloaded:
|
|
26
|
+
downloaded: document,
|
|
30
27
|
};
|
|
31
28
|
if (!disableCache && typeof input === 'string') {
|
|
32
29
|
cache.set(input, processed);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type ResolvedSchema } from '../utils/schema.js';
|
|
2
|
-
|
|
2
|
+
import type { ProcessedDocument } from '../utils/process-document.js';
|
|
3
|
+
export declare function schemaToString(value: ResolvedSchema, ctx?: ProcessedDocument): string;
|
|
3
4
|
//# sourceMappingURL=schema-to-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EACrB,GAAG,CAAC,EAAE,iBAAiB,GACtB,MAAM,CA8DR"}
|
|
@@ -1,50 +1,58 @@
|
|
|
1
|
-
export function schemaToString(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export function schemaToString(value, ctx) {
|
|
2
|
+
function run(schema, isRoot) {
|
|
3
|
+
if (schema === true)
|
|
4
|
+
return 'any';
|
|
5
|
+
else if (schema === false)
|
|
6
|
+
return 'never';
|
|
7
|
+
if (isNullable(schema) && isRoot) {
|
|
8
|
+
const type = run(schema, false);
|
|
9
|
+
// null if schema only contains `nullable`
|
|
10
|
+
return type === 'unknown' ? 'null' : `${type} | null`;
|
|
11
|
+
}
|
|
12
|
+
if (schema.title)
|
|
13
|
+
return schema.title;
|
|
14
|
+
const referenceName = ctx?.dereferenceMap.get(schema);
|
|
15
|
+
if (referenceName)
|
|
16
|
+
return referenceName.split('/').at(-1);
|
|
17
|
+
if (Array.isArray(schema.type)) {
|
|
18
|
+
return schema.type
|
|
19
|
+
.map((type, _, originalType) => {
|
|
20
|
+
schema.type = type;
|
|
21
|
+
const str = run(schema, false);
|
|
22
|
+
schema.type = originalType;
|
|
23
|
+
return str;
|
|
24
|
+
})
|
|
25
|
+
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
26
|
+
.join(' | ');
|
|
27
|
+
}
|
|
28
|
+
if (schema.type === 'array')
|
|
29
|
+
return `array<${schema.items ? run(schema.items, true) : 'unknown'}>`;
|
|
30
|
+
if (schema.oneOf) {
|
|
31
|
+
return schema.oneOf
|
|
32
|
+
.map((one) => run(one, false))
|
|
33
|
+
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
34
|
+
.join(' | ');
|
|
35
|
+
}
|
|
36
|
+
const combinedOf = schema.anyOf ?? schema.allOf;
|
|
37
|
+
if (combinedOf) {
|
|
38
|
+
return combinedOf
|
|
39
|
+
.map((one) => run(one, false))
|
|
40
|
+
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
41
|
+
.join(' & ');
|
|
42
|
+
}
|
|
43
|
+
if (schema.not)
|
|
44
|
+
return `not ${run(schema.not, false)}`;
|
|
45
|
+
if (schema.type === 'string' && schema.format === 'binary')
|
|
46
|
+
return 'file';
|
|
47
|
+
if (schema.type && Array.isArray(schema.type)) {
|
|
48
|
+
return schema.type.filter((v) => v !== 'null').join(' | ');
|
|
49
|
+
}
|
|
50
|
+
if (schema.type) {
|
|
51
|
+
return schema.type;
|
|
52
|
+
}
|
|
53
|
+
return 'unknown';
|
|
10
54
|
}
|
|
11
|
-
|
|
12
|
-
return schema.title;
|
|
13
|
-
if (Array.isArray(schema.type)) {
|
|
14
|
-
return schema.type
|
|
15
|
-
.map((type) => schemaToString({
|
|
16
|
-
...schema,
|
|
17
|
-
type,
|
|
18
|
-
}, false))
|
|
19
|
-
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
20
|
-
.join(' | ');
|
|
21
|
-
}
|
|
22
|
-
if (schema.type === 'array')
|
|
23
|
-
return `array<${schema.items ? schemaToString(schema.items) : 'unknown'}>`;
|
|
24
|
-
if (schema.oneOf) {
|
|
25
|
-
return schema.oneOf
|
|
26
|
-
.map((one) => schemaToString(one, false))
|
|
27
|
-
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
28
|
-
.join(' | ');
|
|
29
|
-
}
|
|
30
|
-
const combinedOf = schema.anyOf ?? schema.allOf;
|
|
31
|
-
if (combinedOf) {
|
|
32
|
-
return combinedOf
|
|
33
|
-
.map((one) => schemaToString(one, false))
|
|
34
|
-
.filter((v) => v !== 'unknown' && v !== 'null')
|
|
35
|
-
.join(' & ');
|
|
36
|
-
}
|
|
37
|
-
if (schema.not)
|
|
38
|
-
return `not ${schemaToString(schema.not, false)}`;
|
|
39
|
-
if (schema.type === 'string' && schema.format === 'binary')
|
|
40
|
-
return 'file';
|
|
41
|
-
if (schema.type && Array.isArray(schema.type)) {
|
|
42
|
-
return schema.type.filter((v) => v !== 'null').join(' | ');
|
|
43
|
-
}
|
|
44
|
-
if (schema.type) {
|
|
45
|
-
return schema.type;
|
|
46
|
-
}
|
|
47
|
-
return 'unknown';
|
|
55
|
+
return run(value, true);
|
|
48
56
|
}
|
|
49
57
|
function isNullable(schema) {
|
|
50
58
|
if (typeof schema === 'boolean')
|
package/dist/utils/url.js
CHANGED
|
@@ -26,26 +26,24 @@ export function resolveServerUrl(template, variables) {
|
|
|
26
26
|
}
|
|
27
27
|
export function resolveRequestData(pathname, { path, query }) {
|
|
28
28
|
for (const key in path) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pathname = pathname.replace(`{${key}}`, path[key].join('/'));
|
|
29
|
+
const param = path[key];
|
|
30
|
+
if (Array.isArray(param.value)) {
|
|
31
|
+
pathname = pathname.replace(`{${key}}`, param.value.join('/'));
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
|
-
pathname = pathname.replace(`{${key}}`,
|
|
34
|
+
pathname = pathname.replace(`{${key}}`, param.value);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
const searchParams = new URLSearchParams();
|
|
39
38
|
for (const key in query) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
searchParams.append(key, String(value));
|
|
39
|
+
const param = query[key];
|
|
40
|
+
if (Array.isArray(param.value)) {
|
|
41
|
+
for (const item of param.value) {
|
|
42
|
+
searchParams.append(key, item);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
else
|
|
48
|
-
searchParams.
|
|
45
|
+
else {
|
|
46
|
+
searchParams.append(key, param.value);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
return searchParams.size > 0 ? `${pathname}?${searchParams}` : pathname;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"shiki": "^3.7.0",
|
|
65
65
|
"tinyglobby": "^0.2.14",
|
|
66
66
|
"xml-js": "^1.6.11",
|
|
67
|
-
"fumadocs-core": "15.6.
|
|
68
|
-
"fumadocs-ui": "15.6.
|
|
67
|
+
"fumadocs-core": "15.6.2",
|
|
68
|
+
"fumadocs-ui": "15.6.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@scalar/api-client-react": "^1.3.18",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"openapi-types": "^12.1.3",
|
|
79
79
|
"tailwindcss": "^4.1.11",
|
|
80
80
|
"tsc-alias": "^1.8.16",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
81
|
+
"eslint-config-custom": "0.0.0",
|
|
82
|
+
"tsconfig": "0.0.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@scalar/api-client-react": "*",
|