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.
Files changed (61) hide show
  1. package/dist/media/adapter.d.ts +47 -16
  2. package/dist/media/adapter.d.ts.map +1 -1
  3. package/dist/media/adapter.js +3 -4
  4. package/dist/playground/client.d.ts +6 -4
  5. package/dist/playground/client.d.ts.map +1 -1
  6. package/dist/playground/client.js +19 -18
  7. package/dist/playground/fetcher.d.ts.map +1 -1
  8. package/dist/playground/fetcher.js +14 -24
  9. package/dist/playground/index.d.ts +3 -5
  10. package/dist/playground/index.d.ts.map +1 -1
  11. package/dist/playground/index.js +2 -4
  12. package/dist/render/api-page.d.ts.map +1 -1
  13. package/dist/render/api-page.js +2 -8
  14. package/dist/render/operation/api-example.d.ts +3 -2
  15. package/dist/render/operation/api-example.d.ts.map +1 -1
  16. package/dist/render/operation/api-example.js +8 -6
  17. package/dist/render/operation/get-request-data.d.ts +2 -2
  18. package/dist/render/operation/get-request-data.d.ts.map +1 -1
  19. package/dist/render/renderer.d.ts.map +1 -1
  20. package/dist/render/renderer.js +3 -2
  21. package/dist/render/schema.d.ts +1 -1
  22. package/dist/render/schema.d.ts.map +1 -1
  23. package/dist/render/schema.js +11 -12
  24. package/dist/requests/_shared.d.ts +20 -4
  25. package/dist/requests/_shared.d.ts.map +1 -1
  26. package/dist/requests/_shared.js +113 -0
  27. package/dist/requests/csharp.d.ts.map +1 -1
  28. package/dist/requests/csharp.js +12 -8
  29. package/dist/requests/curl.d.ts.map +1 -1
  30. package/dist/requests/curl.js +5 -6
  31. package/dist/requests/go.d.ts +1 -1
  32. package/dist/requests/go.d.ts.map +1 -1
  33. package/dist/requests/go.js +6 -6
  34. package/dist/requests/java.d.ts.map +1 -1
  35. package/dist/requests/java.js +8 -8
  36. package/dist/requests/javascript.d.ts.map +1 -1
  37. package/dist/requests/javascript.js +9 -6
  38. package/dist/requests/python.d.ts.map +1 -1
  39. package/dist/requests/python.js +12 -5
  40. package/dist/types.d.ts +1 -1
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/ui/components/accordion.d.ts.map +1 -1
  43. package/dist/ui/components/accordion.js +1 -1
  44. package/dist/ui/contexts/api.d.ts +2 -1
  45. package/dist/ui/contexts/api.d.ts.map +1 -1
  46. package/dist/ui/contexts/code-example.d.ts +5 -4
  47. package/dist/ui/contexts/code-example.d.ts.map +1 -1
  48. package/dist/ui/contexts/code-example.js +14 -11
  49. package/dist/ui/index.d.ts.map +1 -1
  50. package/dist/ui/index.js +8 -2
  51. package/dist/ui/lazy.d.ts +2 -1
  52. package/dist/ui/lazy.d.ts.map +1 -1
  53. package/dist/utils/get-typescript-schema.d.ts.map +1 -1
  54. package/dist/utils/get-typescript-schema.js +13 -8
  55. package/dist/utils/process-document.d.ts.map +1 -1
  56. package/dist/utils/process-document.js +8 -11
  57. package/dist/utils/schema-to-string.d.ts +2 -1
  58. package/dist/utils/schema-to-string.d.ts.map +1 -1
  59. package/dist/utils/schema-to-string.js +54 -46
  60. package/dist/utils/url.js +10 -12
  61. 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
- const cloned = structuredClone({ schema, dereferenceMap });
4
- return compile(cloned.schema, 'Response', {
5
- $refOptions: false,
6
- schemaToId: cloned.dereferenceMap,
7
- bannerComment: '',
8
- additionalProperties: false,
9
- enableConstEnums: false,
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;AAK5D,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,CAoC5B"}
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 { dereference, load, upgrade } from '@scalar/openapi-parser';
2
- import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls';
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
- const loaded = await load(input, {
14
- plugins: [readFiles(), fetchUrls()],
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
- loaded.specification = upgrade(loaded.specification).specification;
21
- const { schema: dereferenced } = await dereference(loaded.filesystem, {
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: loaded.specification,
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
- export declare function schemaToString(schema: ResolvedSchema, isRoot?: boolean): string;
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;AAExE,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,UAAO,GAAG,MAAM,CA0D5E"}
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(schema, isRoot = true) {
2
- if (schema === true)
3
- return 'any';
4
- else if (schema === false)
5
- return 'never';
6
- if (isNullable(schema) && isRoot) {
7
- const type = schemaToString(schema, false);
8
- // null if schema only contains `nullable`
9
- return type === 'unknown' ? 'null' : `${type} | null`;
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
- if (schema.title)
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
- if (path[key] === '')
30
- continue;
31
- if (Array.isArray(path[key])) {
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}}`, String(path[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
- if (Array.isArray(query[key])) {
41
- for (const value of query[key]) {
42
- if (!query[key])
43
- continue;
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 if (query[key] && query[key] !== '') {
48
- searchParams.set(key, String(query[key]));
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.17",
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.1",
68
- "fumadocs-ui": "15.6.1"
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
- "tsconfig": "0.0.0",
82
- "eslint-config-custom": "0.0.0"
81
+ "eslint-config-custom": "0.0.0",
82
+ "tsconfig": "0.0.0"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "@scalar/api-client-react": "*",