fumadocs-openapi 10.3.16 → 10.3.17

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 (148) hide show
  1. package/css/generated/shared.css +1 -0
  2. package/dist/generate-file.js +1 -2
  3. package/dist/generate-file.js.map +1 -1
  4. package/dist/index.js +1 -2
  5. package/dist/playground/client.d.ts +4 -3
  6. package/dist/playground/client.d.ts.map +1 -1
  7. package/dist/playground/client.js +2 -4
  8. package/dist/playground/client.js.map +1 -1
  9. package/dist/playground/components/inputs.js +2 -4
  10. package/dist/playground/components/inputs.js.map +1 -1
  11. package/dist/playground/components/oauth-dialog.js +1 -2
  12. package/dist/playground/components/oauth-dialog.js.map +1 -1
  13. package/dist/playground/components/server-select.js +2 -4
  14. package/dist/playground/components/server-select.js.map +1 -1
  15. package/dist/playground/fetcher.js +1 -2
  16. package/dist/playground/fetcher.js.map +1 -1
  17. package/dist/playground/index.d.ts +2 -7
  18. package/dist/playground/index.d.ts.map +1 -1
  19. package/dist/playground/index.js +23 -3
  20. package/dist/playground/index.js.map +1 -1
  21. package/dist/playground/lazy.js +2 -4
  22. package/dist/playground/lazy.js.map +1 -1
  23. package/dist/playground/schema.js +1 -2
  24. package/dist/playground/schema.js.map +1 -1
  25. package/dist/playground/status-info.js +1 -2
  26. package/dist/playground/status-info.js.map +1 -1
  27. package/dist/requests/generators/all.js +1 -2
  28. package/dist/requests/generators/all.js.map +1 -1
  29. package/dist/requests/generators/csharp.js +1 -2
  30. package/dist/requests/generators/csharp.js.map +1 -1
  31. package/dist/requests/generators/curl.js +1 -2
  32. package/dist/requests/generators/curl.js.map +1 -1
  33. package/dist/requests/generators/go.js +1 -2
  34. package/dist/requests/generators/go.js.map +1 -1
  35. package/dist/requests/generators/index.js +1 -1
  36. package/dist/requests/generators/java.js +1 -2
  37. package/dist/requests/generators/java.js.map +1 -1
  38. package/dist/requests/generators/javascript.js +1 -2
  39. package/dist/requests/generators/javascript.js.map +1 -1
  40. package/dist/requests/generators/python.js +1 -2
  41. package/dist/requests/generators/python.js.map +1 -1
  42. package/dist/requests/media/adapter.js +2 -3
  43. package/dist/requests/media/adapter.js.map +1 -1
  44. package/dist/requests/media/encode.d.ts.map +1 -1
  45. package/dist/requests/media/encode.js +1 -2
  46. package/dist/requests/media/encode.js.map +1 -1
  47. package/dist/requests/media/resolve-adapter.js +1 -1
  48. package/dist/requests/media/resolve-adapter.js.map +1 -1
  49. package/dist/requests/string-utils.js +1 -2
  50. package/dist/requests/string-utils.js.map +1 -1
  51. package/dist/requests/to-python-object.js +1 -1
  52. package/dist/scalar/client.js +2 -4
  53. package/dist/scalar/client.js.map +1 -1
  54. package/dist/scalar/index.js +1 -2
  55. package/dist/scalar/index.js.map +1 -1
  56. package/dist/server/create.js +1 -2
  57. package/dist/server/create.js.map +1 -1
  58. package/dist/server/index.js +1 -2
  59. package/dist/server/proxy.js +1 -1
  60. package/dist/server/proxy.js.map +1 -1
  61. package/dist/server/source-api.js +1 -2
  62. package/dist/server/source-api.js.map +1 -1
  63. package/dist/ui/api-page.js +1 -2
  64. package/dist/ui/api-page.js.map +1 -1
  65. package/dist/ui/base.js +1 -2
  66. package/dist/ui/base.js.map +1 -1
  67. package/dist/ui/client/index.js +2 -3
  68. package/dist/ui/client/index.js.map +1 -1
  69. package/dist/ui/client/storage-key.js +1 -2
  70. package/dist/ui/client/storage-key.js.map +1 -1
  71. package/dist/ui/components/accordion.js +2 -4
  72. package/dist/ui/components/accordion.js.map +1 -1
  73. package/dist/ui/components/dialog.js +3 -5
  74. package/dist/ui/components/dialog.js.map +1 -1
  75. package/dist/ui/components/input.js +1 -2
  76. package/dist/ui/components/input.js.map +1 -1
  77. package/dist/ui/components/method-label.js +1 -2
  78. package/dist/ui/components/method-label.js.map +1 -1
  79. package/dist/ui/components/select.js +2 -3
  80. package/dist/ui/components/select.js.map +1 -1
  81. package/dist/ui/contexts/api.js +2 -4
  82. package/dist/ui/contexts/api.js.map +1 -1
  83. package/dist/ui/contexts/api.lazy.js +2 -4
  84. package/dist/ui/contexts/api.lazy.js.map +1 -1
  85. package/dist/ui/full.client.js +2 -4
  86. package/dist/ui/full.client.js.map +1 -1
  87. package/dist/ui/full.js +1 -2
  88. package/dist/ui/full.js.map +1 -1
  89. package/dist/ui/index.js +1 -2
  90. package/dist/ui/operation/client.js +2 -4
  91. package/dist/ui/operation/client.js.map +1 -1
  92. package/dist/ui/operation/index.js +1 -2
  93. package/dist/ui/operation/index.js.map +1 -1
  94. package/dist/ui/operation/request-tabs.js +1 -2
  95. package/dist/ui/operation/request-tabs.js.map +1 -1
  96. package/dist/ui/operation/response-tabs.js +1 -2
  97. package/dist/ui/operation/response-tabs.js.map +1 -1
  98. package/dist/ui/operation/usage-tabs/client.js +4 -7
  99. package/dist/ui/operation/usage-tabs/client.js.map +1 -1
  100. package/dist/ui/operation/usage-tabs/index.js +1 -2
  101. package/dist/ui/operation/usage-tabs/index.js.map +1 -1
  102. package/dist/ui/operation/usage-tabs/lazy.js +2 -4
  103. package/dist/ui/operation/usage-tabs/lazy.js.map +1 -1
  104. package/dist/ui/schema/client.js +2 -4
  105. package/dist/ui/schema/client.js.map +1 -1
  106. package/dist/ui/schema/index.js +1 -2
  107. package/dist/ui/schema/index.js.map +1 -1
  108. package/dist/ui/schema/lazy.js +2 -4
  109. package/dist/ui/schema/lazy.js.map +1 -1
  110. package/dist/utils/cn.js +1 -2
  111. package/dist/utils/deep-equal.js +1 -1
  112. package/dist/utils/id-to-title.js +1 -1
  113. package/dist/utils/lazy.js +1 -2
  114. package/dist/utils/lazy.js.map +1 -1
  115. package/dist/utils/merge-schema.js +1 -2
  116. package/dist/utils/merge-schema.js.map +1 -1
  117. package/dist/utils/pages/builder.js +1 -2
  118. package/dist/utils/pages/builder.js.map +1 -1
  119. package/dist/utils/pages/preset-auto.js +1 -2
  120. package/dist/utils/pages/preset-auto.js.map +1 -1
  121. package/dist/utils/pages/to-body.js +1 -1
  122. package/dist/utils/pages/to-static-data.js +1 -2
  123. package/dist/utils/pages/to-static-data.js.map +1 -1
  124. package/dist/utils/pages/to-text.js +1 -2
  125. package/dist/utils/pages/to-text.js.map +1 -1
  126. package/dist/utils/process-document.js +3 -5
  127. package/dist/utils/process-document.js.map +1 -1
  128. package/dist/utils/remove-undefined.js +1 -1
  129. package/dist/utils/remove-undefined.js.map +1 -1
  130. package/dist/utils/schema-to-string.js +1 -1
  131. package/dist/utils/schema-to-string.js.map +1 -1
  132. package/dist/utils/schema.js +1 -2
  133. package/dist/utils/schema.js.map +1 -1
  134. package/dist/utils/url.js +1 -1
  135. package/dist/utils/use-query.js +1 -2
  136. package/dist/utils/use-query.js.map +1 -1
  137. package/package.json +8 -8
  138. package/dist/_virtual/_rolldown/runtime.js +0 -5
  139. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js +0 -43
  140. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js.map +0 -1
  141. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js +0 -29
  142. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js.map +0 -1
  143. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js +0 -42
  144. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js.map +0 -1
  145. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js +0 -46
  146. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js.map +0 -1
  147. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/types.js +0 -12
  148. package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","names":[],"sources":["../../../src/requests/media/adapter.ts"],"sourcesContent":["import { escapeString, inputToString } from '@/requests/string-utils';\nexport { resolveMediaAdapter, isMediaTypeSupported } from './resolve-adapter';\n// @ts-expect-error -- untyped\nimport js2xml from 'xml-js/lib/js2xml';\n\ninterface BaseContext {\n /**\n * Passed by your custom example generator, for your custom media adapter to receive.\n */\n customData?: Record<string, unknown>;\n}\n\ninterface GoContext extends BaseContext {\n lang: 'go';\n addImport: (name: string) => void;\n}\n\ninterface JavaScriptContext extends BaseContext {\n lang: 'js';\n addImport: (pkg: string, name: string) => void;\n}\n\ninterface JavaContext extends BaseContext {\n lang: 'java';\n addImport: (specifier: string) => void;\n}\n\ninterface CSharpContext extends BaseContext {\n lang: 'csharp';\n addImport: (specifier: string) => void;\n}\n\nexport type MediaContext =\n | JavaContext\n | GoContext\n | JavaScriptContext\n | CSharpContext\n | (BaseContext & { lang: string });\n\nexport interface MediaAdapter {\n /**\n * encode data into specified media type for `fetch()`.\n *\n * Return the encoded form of `data.body` property.\n */\n encode: (data: { body: unknown }) => BodyInit;\n\n /**\n * generate code example for creating the body in a given programming language.\n *\n * @param data - request data.\n * @param lang - name of programming language.\n * @param ctx - context passed from the generator of programming language.\n *\n * @returns code that inits a `body` variable, or undefined if not supported (skip example for that language).\n */\n generateExample: (data: { body: unknown }, ctx: MediaContext) => string | undefined;\n}\n\nexport const defaultAdapters = {\n 'application/json': {\n encode(data) {\n return JSON.stringify(data.body);\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/json', ctx);\n },\n },\n 'application/xml': {\n encode(data) {\n return js2xml(data.body as Record<string, unknown>, {\n compact: true,\n spaces: 2,\n });\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/xml', ctx);\n },\n },\n 'application/x-ndjson': {\n encode(data) {\n if (Array.isArray(data.body)) {\n return data.body.map((v) => JSON.stringify(v)).join('\\n');\n }\n\n return JSON.stringify(data.body);\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/x-ndjson', ctx);\n },\n },\n 'application/x-www-form-urlencoded': {\n encode(data) {\n if (typeof data.body !== 'object')\n throw new Error(`Input value must be object, received: ${typeof data.body}`);\n\n const params = new URLSearchParams();\n for (const key in data.body) {\n params.set(key, String(data.body[key as keyof object]));\n }\n\n return params;\n },\n generateExample(data, ctx) {\n if (ctx.lang === 'js') {\n return `const body = new URLSearchParams(${JSON.stringify(data.body, null, 2)})`;\n }\n\n return str(data.body, 'application/x-www-form-urlencoded', ctx);\n },\n },\n 'multipart/form-data': {\n encode(data) {\n const formData = new FormData();\n const body = data.body as Record<string, unknown>;\n\n if (typeof body !== 'object' || !body) {\n throw new Error(`Unsupported body type: ${typeof body}, expected: object`);\n }\n\n for (const key in body) {\n const prop = body[key];\n\n if (prop === null || prop === undefined || Number.isNaN(prop)) continue;\n\n // Arrays (multi-value field)\n if (Array.isArray(prop)) {\n for (const item of prop) {\n if (item === null || item === undefined) continue;\n if (item instanceof File) {\n formData.append(key, item, item.name);\n } else if (item instanceof Blob) {\n formData.append(key, item, 'blob');\n } else if (typeof item === 'object') {\n formData.append(key, JSON.stringify(item));\n } else {\n formData.append(key, String(item));\n }\n }\n }\n\n // Single File\n else if (prop instanceof File) {\n formData.set(key, prop, prop.name);\n }\n\n // Single Blob\n else if (prop instanceof Blob) {\n formData.set(key, prop, 'blob');\n }\n\n // Any other object (stringify)\n else if (typeof prop === 'object') {\n formData.set(key, JSON.stringify(prop));\n }\n\n // Primitive types\n else {\n formData.set(key, String(prop));\n }\n }\n\n return formData;\n },\n generateExample(data, ctx) {\n if (ctx.lang === 'python') {\n return `body = ${JSON.stringify(data.body, null, 2)}`;\n }\n\n const s: string[] = [];\n if (ctx.lang === 'js') {\n s.push(`const body = new FormData();`);\n\n for (const [key, value] of Object.entries(data.body as object)) {\n s.push(`body.set(${key}, ${JSON.stringify(inputToString(value))})`);\n }\n }\n\n if (ctx.lang === 'go') {\n const { addImport } = ctx as GoContext;\n addImport('mime/multipart');\n addImport('bytes');\n\n s.push('body := new(bytes.Buffer)');\n s.push('mp := multipart.NewWriter(payload)');\n\n for (const [key, value] of Object.entries(data.body as object)) {\n if (!value) continue;\n\n const escaped = escapeString(inputToString(value, 'application/json'), '`');\n\n s.push(`mp.WriteField(\"${key}\", ${escaped})`);\n }\n }\n\n if (ctx.lang === 'java') {\n const { addImport } = ctx as JavaContext;\n addImport('java.net.http.HttpRequest.BodyPublishers');\n\n s.push(`var body = BodyPublishers.ofByteArray(new byte[] { ... });`);\n }\n\n if (ctx.lang === 'csharp') {\n s.push(`var body = new MultipartFormDataContent();`);\n }\n\n if (s.length > 0) return s.join('\\n');\n },\n },\n 'application/octet-stream': {\n encode(data) {\n return data.body as BodyInit;\n },\n generateExample() {\n // not supported\n return undefined;\n },\n },\n} satisfies Record<string, MediaAdapter>;\n\nfunction str(\n init: unknown,\n mediaType:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml',\n ctx: MediaContext,\n) {\n if (ctx.lang === 'js') {\n if (mediaType === 'application/json') {\n return `const body = JSON.stringify(${JSON.stringify(init, null, 2)})`;\n }\n return `const body = ${escapeString(inputToString(init, mediaType), '`')}`;\n }\n\n if (ctx.lang === 'python') {\n return `body = ${escapeString(inputToString(init, mediaType), '\"\"\"')}`;\n }\n\n if (ctx.lang === 'go') {\n const { addImport } = ctx as GoContext;\n addImport('strings');\n return `body := strings.NewReader(${escapeString(inputToString(init, mediaType), '`')})`;\n }\n\n if (ctx.lang === 'java') {\n const { addImport } = ctx as JavaContext;\n addImport('java.net.http.HttpRequest.BodyPublishers');\n return `var body = BodyPublishers.ofString(${escapeString(inputToString(init, mediaType), '\"\"\"')});`;\n }\n\n if (ctx.lang === 'csharp') {\n const input = `\\n${inputToString(init, mediaType)}\\n`;\n\n return `var body = new StringContent(${escapeString(input, '\"\"\"')}, Encoding.UTF8, \"${mediaType}\");`;\n }\n}\n"],"mappings":";;;;;AA2DA,MAAa,kBAAkB;CAC7B,oBAAoB;EAClB,OAAO,MAAM;AACX,UAAO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IAAI,KAAK,QAAQ,GAAG;;;AAIjD,OAAI,IAAI,SAAS,QAAQ;IACvB,MAAM,EAAE,cAAc;AACtB,cAAU,2CAA2C;AAErD,MAAE,KAAK,6DAA6D;;AAGtE,OAAI,IAAI,SAAS,SACf,GAAE,KAAK,6CAA6C;AAGtD,OAAI,EAAE,SAAS,EAAG,QAAO,EAAE,KAAK,KAAK;;EAExC;CACD,4BAA4B;EAC1B,OAAO,MAAM;AACX,UAAO,KAAK;;EAEd,kBAAkB;EAInB;CACF;AAED,SAAS,IACP,MACA,WAKA,KACA;AACA,KAAI,IAAI,SAAS,MAAM;AACrB,MAAI,cAAc,mBAChB,QAAO,+BAA+B,KAAK,UAAU,MAAM,MAAM,EAAE,CAAC;AAEtE,SAAO,gBAAgB,aAAa,cAAc,MAAM,UAAU,EAAE,IAAI;;AAG1E,KAAI,IAAI,SAAS,SACf,QAAO,UAAU,aAAa,cAAc,MAAM,UAAU,EAAE,SAAM;AAGtE,KAAI,IAAI,SAAS,MAAM;EACrB,MAAM,EAAE,cAAc;AACtB,YAAU,UAAU;AACpB,SAAO,6BAA6B,aAAa,cAAc,MAAM,UAAU,EAAE,IAAI,CAAC;;AAGxF,KAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,EAAE,cAAc;AACtB,YAAU,2CAA2C;AACrD,SAAO,sCAAsC,aAAa,cAAc,MAAM,UAAU,EAAE,SAAM,CAAC;;AAGnG,KAAI,IAAI,SAAS,SAGf,QAAO,gCAAgC,aAFzB,KAAK,cAAc,MAAM,UAAU,CAAC,KAES,SAAM,CAAC,oBAAoB,UAAU"}
1
+ {"version":3,"file":"adapter.js","names":[],"sources":["../../../src/requests/media/adapter.ts"],"sourcesContent":["import { escapeString, inputToString } from '@/requests/string-utils';\nexport { resolveMediaAdapter, isMediaTypeSupported } from './resolve-adapter';\n// @ts-expect-error -- untyped\nimport js2xml from 'xml-js/lib/js2xml';\n\ninterface BaseContext {\n /**\n * Passed by your custom example generator, for your custom media adapter to receive.\n */\n customData?: Record<string, unknown>;\n}\n\ninterface GoContext extends BaseContext {\n lang: 'go';\n addImport: (name: string) => void;\n}\n\ninterface JavaScriptContext extends BaseContext {\n lang: 'js';\n addImport: (pkg: string, name: string) => void;\n}\n\ninterface JavaContext extends BaseContext {\n lang: 'java';\n addImport: (specifier: string) => void;\n}\n\ninterface CSharpContext extends BaseContext {\n lang: 'csharp';\n addImport: (specifier: string) => void;\n}\n\nexport type MediaContext =\n | JavaContext\n | GoContext\n | JavaScriptContext\n | CSharpContext\n | (BaseContext & { lang: string });\n\nexport interface MediaAdapter {\n /**\n * encode data into specified media type for `fetch()`.\n *\n * Return the encoded form of `data.body` property.\n */\n encode: (data: { body: unknown }) => BodyInit;\n\n /**\n * generate code example for creating the body in a given programming language.\n *\n * @param data - request data.\n * @param lang - name of programming language.\n * @param ctx - context passed from the generator of programming language.\n *\n * @returns code that inits a `body` variable, or undefined if not supported (skip example for that language).\n */\n generateExample: (data: { body: unknown }, ctx: MediaContext) => string | undefined;\n}\n\nexport const defaultAdapters = {\n 'application/json': {\n encode(data) {\n return JSON.stringify(data.body);\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/json', ctx);\n },\n },\n 'application/xml': {\n encode(data) {\n return js2xml(data.body as Record<string, unknown>, {\n compact: true,\n spaces: 2,\n });\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/xml', ctx);\n },\n },\n 'application/x-ndjson': {\n encode(data) {\n if (Array.isArray(data.body)) {\n return data.body.map((v) => JSON.stringify(v)).join('\\n');\n }\n\n return JSON.stringify(data.body);\n },\n generateExample(data, ctx) {\n return str(data.body, 'application/x-ndjson', ctx);\n },\n },\n 'application/x-www-form-urlencoded': {\n encode(data) {\n if (typeof data.body !== 'object')\n throw new Error(`Input value must be object, received: ${typeof data.body}`);\n\n const params = new URLSearchParams();\n for (const key in data.body) {\n params.set(key, String(data.body[key as keyof object]));\n }\n\n return params;\n },\n generateExample(data, ctx) {\n if (ctx.lang === 'js') {\n return `const body = new URLSearchParams(${JSON.stringify(data.body, null, 2)})`;\n }\n\n return str(data.body, 'application/x-www-form-urlencoded', ctx);\n },\n },\n 'multipart/form-data': {\n encode(data) {\n const formData = new FormData();\n const body = data.body as Record<string, unknown>;\n\n if (typeof body !== 'object' || !body) {\n throw new Error(`Unsupported body type: ${typeof body}, expected: object`);\n }\n\n for (const key in body) {\n const prop = body[key];\n\n if (prop === null || prop === undefined || Number.isNaN(prop)) continue;\n\n // Arrays (multi-value field)\n if (Array.isArray(prop)) {\n for (const item of prop) {\n if (item === null || item === undefined) continue;\n if (item instanceof File) {\n formData.append(key, item, item.name);\n } else if (item instanceof Blob) {\n formData.append(key, item, 'blob');\n } else if (typeof item === 'object') {\n formData.append(key, JSON.stringify(item));\n } else {\n formData.append(key, String(item));\n }\n }\n }\n\n // Single File\n else if (prop instanceof File) {\n formData.set(key, prop, prop.name);\n }\n\n // Single Blob\n else if (prop instanceof Blob) {\n formData.set(key, prop, 'blob');\n }\n\n // Any other object (stringify)\n else if (typeof prop === 'object') {\n formData.set(key, JSON.stringify(prop));\n }\n\n // Primitive types\n else {\n formData.set(key, String(prop));\n }\n }\n\n return formData;\n },\n generateExample(data, ctx) {\n if (ctx.lang === 'python') {\n return `body = ${JSON.stringify(data.body, null, 2)}`;\n }\n\n const s: string[] = [];\n if (ctx.lang === 'js') {\n s.push(`const body = new FormData();`);\n\n for (const [key, value] of Object.entries(data.body as object)) {\n s.push(`body.set(${key}, ${JSON.stringify(inputToString(value))})`);\n }\n }\n\n if (ctx.lang === 'go') {\n const { addImport } = ctx as GoContext;\n addImport('mime/multipart');\n addImport('bytes');\n\n s.push('body := new(bytes.Buffer)');\n s.push('mp := multipart.NewWriter(payload)');\n\n for (const [key, value] of Object.entries(data.body as object)) {\n if (!value) continue;\n\n const escaped = escapeString(inputToString(value, 'application/json'), '`');\n\n s.push(`mp.WriteField(\"${key}\", ${escaped})`);\n }\n }\n\n if (ctx.lang === 'java') {\n const { addImport } = ctx as JavaContext;\n addImport('java.net.http.HttpRequest.BodyPublishers');\n\n s.push(`var body = BodyPublishers.ofByteArray(new byte[] { ... });`);\n }\n\n if (ctx.lang === 'csharp') {\n s.push(`var body = new MultipartFormDataContent();`);\n }\n\n if (s.length > 0) return s.join('\\n');\n },\n },\n 'application/octet-stream': {\n encode(data) {\n return data.body as BodyInit;\n },\n generateExample() {\n // not supported\n return undefined;\n },\n },\n} satisfies Record<string, MediaAdapter>;\n\nfunction str(\n init: unknown,\n mediaType:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml',\n ctx: MediaContext,\n) {\n if (ctx.lang === 'js') {\n if (mediaType === 'application/json') {\n return `const body = JSON.stringify(${JSON.stringify(init, null, 2)})`;\n }\n return `const body = ${escapeString(inputToString(init, mediaType), '`')}`;\n }\n\n if (ctx.lang === 'python') {\n return `body = ${escapeString(inputToString(init, mediaType), '\"\"\"')}`;\n }\n\n if (ctx.lang === 'go') {\n const { addImport } = ctx as GoContext;\n addImport('strings');\n return `body := strings.NewReader(${escapeString(inputToString(init, mediaType), '`')})`;\n }\n\n if (ctx.lang === 'java') {\n const { addImport } = ctx as JavaContext;\n addImport('java.net.http.HttpRequest.BodyPublishers');\n return `var body = BodyPublishers.ofString(${escapeString(inputToString(init, mediaType), '\"\"\"')});`;\n }\n\n if (ctx.lang === 'csharp') {\n const input = `\\n${inputToString(init, mediaType)}\\n`;\n\n return `var body = new StringContent(${escapeString(input, '\"\"\"')}, Encoding.UTF8, \"${mediaType}\");`;\n }\n}\n"],"mappings":";;;;AA2DA,MAAa,kBAAkB;CAC7B,oBAAoB;EAClB,OAAO,MAAM;AACX,UAAO,KAAK,UAAU,KAAK,KAAK;;EAElC,gBAAgB,MAAM,KAAK;AACzB,UAAO,IAAI,KAAK,MAAM,oBAAoB,IAAI;;EAEjD;CACD,mBAAmB;EACjB,OAAO,MAAM;AACX,UAAO,OAAO,KAAK,MAAiC;IAClD,SAAS;IACT,QAAQ;IACT,CAAC;;EAEJ,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AE,SAAS,EAAG,QAAO,EAAE,KAAK,KAAK;;EAExC;CACD,4BAA4B;EAC1B,OAAO,MAAM;AACX,UAAO,KAAK;;EAEd,kBAAkB;EAInB;CACF;AAED,SAAS,IACP,MACA,WAKA,KACA;AACA,KAAI,IAAI,SAAS,MAAM;AACrB,MAAI,cAAc,mBAChB,QAAO,+BAA+B,KAAK,UAAU,MAAM,MAAM,EAAE,CAAC;AAEtE,SAAO,gBAAgB,aAAa,cAAc,MAAM,UAAU,EAAE,IAAI;;AAG1E,KAAI,IAAI,SAAS,SACf,QAAO,UAAU,aAAa,cAAc,MAAM,UAAU,EAAE,SAAM;AAGtE,KAAI,IAAI,SAAS,MAAM;EACrB,MAAM,EAAE,cAAc;AACtB,YAAU,UAAU;AACpB,SAAO,6BAA6B,aAAa,cAAc,MAAM,UAAU,EAAE,IAAI,CAAC;;AAGxF,KAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,EAAE,cAAc;AACtB,YAAU,2CAA2C;AACrD,SAAO,sCAAsC,aAAa,cAAc,MAAM,UAAU,EAAE,SAAM,CAAC;;AAGnG,KAAI,IAAI,SAAS,SAGf,QAAO,gCAAgC,aAFzB,KAAK,cAAc,MAAM,UAAU,CAAC,KAES,SAAM,CAAC,oBAAoB,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","names":[],"sources":["../../../src/requests/media/encode.ts"],"mappings":";UAMiB,gBAAA;EAAA,SACN,KAAA;AAAA;AAAA,UAGM,wBAAA;EAAA,SACN,MAAA;AAAA"}
1
+ {"version":3,"file":"encode.d.ts","names":[],"sources":["../../../src/requests/media/encode.ts"],"mappings":";UAKiB,gBAAA;EAAA,SACN,KAAA;AAAA;AAAA,UAGM,wBAAA;EAAA,SACN,MAAA;AAAA"}
@@ -1,6 +1,5 @@
1
1
  import { resolveMediaAdapter } from "./resolve-adapter.js";
2
2
  import "./adapter.js";
3
-
4
3
  //#region src/requests/media/encode.ts
5
4
  /**
6
5
  * serialize parameters, see https://swagger.io/docs/specification/v3_0/serialization.
@@ -127,7 +126,7 @@ function serializeCookieParameter(field, value, output) {
127
126
  else if (typeof value === "object") output[field.name] = { value: Object.entries(value).flat().join(",") };
128
127
  else output[field.name] = { value: String(value) };
129
128
  }
130
-
131
129
  //#endregion
132
130
  export { encodeRequestData };
131
+
133
132
  //# sourceMappingURL=encode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"encode.js","names":[],"sources":["../../../src/requests/media/encode.ts"],"sourcesContent":["import type { MediaAdapter } from '@/requests/media/adapter';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\nimport type { NoReference } from '@/utils/schema';\nimport type { ParameterObject } from '@/types';\nimport type { RawRequestData, RequestData } from '@/requests/types';\n\nexport interface EncodedParameter {\n readonly value: string;\n}\n\nexport interface EncodedParameterMultiple {\n readonly values: string[];\n}\n\n/**\n * serialize parameters, see https://swagger.io/docs/specification/v3_0/serialization.\n */\nexport function encodeRequestData(\n from: RawRequestData,\n adapters: Record<string, MediaAdapter>,\n parameters: NoReference<ParameterObject>[] = [],\n): RequestData {\n const result: RequestData = {\n method: from.method,\n body: from.body,\n bodyMediaType: from.bodyMediaType,\n cookie: {},\n header: {},\n path: {},\n query: {},\n };\n\n for (const type of ['cookie', 'query', 'header', 'path'] as const) {\n for (const key in from[type]) {\n const value = from[type][key];\n if (value == null) continue;\n\n const field: NoReference<ParameterObject> = parameters.find(\n (p) => p.name === key && p.in === type,\n ) ?? {\n name: key,\n in: type,\n };\n\n const encoder = getMediaEncoder(field, adapters);\n if (encoder) {\n if (type === 'query') result[type][key] = { values: [encoder(value)] };\n else result[type][key] = { value: encoder(value) };\n continue;\n }\n\n switch (type) {\n case 'path':\n serializePathParameter(field, value, result.path);\n break;\n case 'query':\n serializeQueryParameter(field, value, result.query);\n break;\n case 'header': {\n result.header[key] = {\n value: serializeSimple(value, field.explode ?? false),\n };\n break;\n }\n case 'cookie':\n serializeCookieParameter(field, value, result.cookie);\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction getMediaEncoder(\n field: NoReference<ParameterObject>,\n adapters: Record<string, MediaAdapter>,\n) {\n if (!field.content) return;\n\n for (const k in field.content) {\n const adapter = resolveMediaAdapter(k, adapters);\n if (adapter) {\n return (v: unknown) => String(adapter.encode({ body: v }));\n }\n }\n}\n\nfunction serializeSimple(value: NonNullable<unknown>, explode: boolean): string {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n if (typeof value === 'object') {\n return explode\n ? Object.entries(value)\n .map(([k, v]) => `${k}=${v}`)\n .join(',')\n : Object.entries(value).flat().join(',');\n }\n return String(value);\n}\n\nfunction serializePathParameter(\n field: NoReference<ParameterObject>,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameter>,\n): void {\n const { explode = false, name } = field;\n\n switch (field.style) {\n case 'label':\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: '.' + value.join(explode ? '.' : ','),\n };\n break;\n }\n if (typeof value === 'object') {\n output[field.name!] = {\n value:\n '.' +\n (explode\n ? Object.entries(value)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n : Object.entries(value).flat().join(',')),\n };\n break;\n }\n output[field.name!] = {\n value: `.${value}`,\n };\n break;\n case 'matrix': {\n const specifier = `;${name}=`;\n\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: explode\n ? `${specifier}${value.join(',')}`\n : `${specifier}${value.join(specifier)}`,\n };\n break;\n }\n if (typeof value === 'object') {\n output[field.name!] = {\n value: explode\n ? Object.entries(value)\n .map(([k, v]) => `;${k}=${v}`)\n .join('')\n : specifier + Object.entries(value).flat().join(','),\n };\n break;\n }\n\n output[field.name!] = {\n value: `${specifier}${value}`,\n };\n break;\n }\n // simple\n default:\n output[field.name!] = {\n value: serializeSimple(value, explode),\n };\n }\n}\n\nfunction serializeQueryParameter(\n field: NoReference<ParameterObject>,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameterMultiple>,\n): void {\n const { style, explode = true } = field;\n\n if (style === 'spaceDelimited' && !explode && Array.isArray(value)) {\n output[field.name!] = {\n values: [value.join(' ')],\n };\n return;\n }\n\n if (style === 'pipeDelimited' && !explode && Array.isArray(value)) {\n output[field.name!] = {\n values: [value.join('|')],\n };\n return;\n }\n\n if (style === 'deepObject' && !Array.isArray(value) && typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n output[`${field.name}[${k}]`] = {\n // note: the behaviour of nested array is undefined, we do this to avoid edge cases\n values: Array.isArray(v) ? v : [String(v)],\n };\n }\n return;\n }\n\n if (Array.isArray(value)) {\n output[field.name!] = {\n values: explode ? value : [value.join(',')],\n };\n return;\n }\n\n if (typeof value === 'object' && explode) {\n for (const [k, v] of Object.entries(value)) {\n output[k] = {\n values: [String(v)],\n };\n }\n return;\n }\n\n if (typeof value === 'object') {\n output[field.name!] = {\n values: [Object.entries(value).flat().join(',')],\n };\n return;\n }\n\n output[field.name!] = {\n values: [String(value)],\n };\n}\n\nfunction serializeCookieParameter(\n field: NoReference<ParameterObject>,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameter>,\n) {\n const { explode = true } = field;\n\n // form\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: explode ? value.map((v) => `${field.name}=${v}`).join('&') : value.join(','),\n };\n } else if (typeof value === 'object' && explode) {\n for (const [k, v] of Object.entries(value)) {\n output[k] = {\n value: String(v),\n };\n }\n } else if (typeof value === 'object') {\n output[field.name!] = {\n value: Object.entries(value).flat().join(','),\n };\n } else {\n output[field.name!] = {\n value: String(value),\n };\n }\n}\n"],"mappings":";;;;;;;AAiBA,SAAgB,kBACd,MACA,UACA,aAA6C,EAAE,EAClC;CACb,MAAM,SAAsB;EAC1B,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,eAAe,KAAK;EACpB,QAAQ,EAAE;EACV,QAAQ,EAAE;EACV,MAAM,EAAE;EACR,OAAO,EAAE;EACV;AAED,MAAK,MAAM,QAAQ;EAAC;EAAU;EAAS;EAAU;EAAO,CACtD,MAAK,MAAM,OAAO,KA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M,OAAO,QAAQ,MAAM,CACxC,QAAO,KAAK,EACV,OAAO,OAAO,EAAE,EACjB;UAEM,OAAO,UAAU,SAC1B,QAAO,MAAM,QAAS,EACpB,OAAO,OAAO,QAAQ,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAC9C;KAED,QAAO,MAAM,QAAS,EACpB,OAAO,OAAO,MAAM,EACrB"}
1
+ {"version":3,"file":"encode.js","names":[],"sources":["../../../src/requests/media/encode.ts"],"sourcesContent":["import type { MediaAdapter } from '@/requests/media/adapter';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\nimport type { ParameterObject } from '@/types';\nimport type { RawRequestData, RequestData } from '@/requests/types';\n\nexport interface EncodedParameter {\n readonly value: string;\n}\n\nexport interface EncodedParameterMultiple {\n readonly values: string[];\n}\n\n/**\n * serialize parameters, see https://swagger.io/docs/specification/v3_0/serialization.\n */\nexport function encodeRequestData(\n from: RawRequestData,\n adapters: Record<string, MediaAdapter>,\n parameters: ParameterObject[] = [],\n): RequestData {\n const result: RequestData = {\n method: from.method,\n body: from.body,\n bodyMediaType: from.bodyMediaType,\n cookie: {},\n header: {},\n path: {},\n query: {},\n };\n\n for (const type of ['cookie', 'query', 'header', 'path'] as const) {\n for (const key in from[type]) {\n const value = from[type][key];\n if (value == null) continue;\n\n const field: ParameterObject = parameters.find((p) => p.name === key && p.in === type) ?? {\n name: key,\n in: type,\n };\n\n const encoder = getMediaEncoder(field, adapters);\n if (encoder) {\n if (type === 'query') result[type][key] = { values: [encoder(value)] };\n else result[type][key] = { value: encoder(value) };\n continue;\n }\n\n switch (type) {\n case 'path':\n serializePathParameter(field, value, result.path);\n break;\n case 'query':\n serializeQueryParameter(field, value, result.query);\n break;\n case 'header': {\n result.header[key] = {\n value: serializeSimple(value, field.explode ?? false),\n };\n break;\n }\n case 'cookie':\n serializeCookieParameter(field, value, result.cookie);\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction getMediaEncoder(field: ParameterObject, adapters: Record<string, MediaAdapter>) {\n if (!field.content) return;\n\n for (const k in field.content) {\n const adapter = resolveMediaAdapter(k, adapters);\n if (adapter) {\n return (v: unknown) => String(adapter.encode({ body: v }));\n }\n }\n}\n\nfunction serializeSimple(value: NonNullable<unknown>, explode: boolean): string {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n if (typeof value === 'object') {\n return explode\n ? Object.entries(value)\n .map(([k, v]) => `${k}=${v}`)\n .join(',')\n : Object.entries(value).flat().join(',');\n }\n return String(value);\n}\n\nfunction serializePathParameter(\n field: ParameterObject,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameter>,\n): void {\n const { explode = false, name } = field;\n\n switch (field.style) {\n case 'label':\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: '.' + value.join(explode ? '.' : ','),\n };\n break;\n }\n if (typeof value === 'object') {\n output[field.name!] = {\n value:\n '.' +\n (explode\n ? Object.entries(value)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n : Object.entries(value).flat().join(',')),\n };\n break;\n }\n output[field.name!] = {\n value: `.${value}`,\n };\n break;\n case 'matrix': {\n const specifier = `;${name}=`;\n\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: explode\n ? `${specifier}${value.join(',')}`\n : `${specifier}${value.join(specifier)}`,\n };\n break;\n }\n if (typeof value === 'object') {\n output[field.name!] = {\n value: explode\n ? Object.entries(value)\n .map(([k, v]) => `;${k}=${v}`)\n .join('')\n : specifier + Object.entries(value).flat().join(','),\n };\n break;\n }\n\n output[field.name!] = {\n value: `${specifier}${value}`,\n };\n break;\n }\n // simple\n default:\n output[field.name!] = {\n value: serializeSimple(value, explode),\n };\n }\n}\n\nfunction serializeQueryParameter(\n field: ParameterObject,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameterMultiple>,\n): void {\n const { style, explode = true } = field;\n\n if (style === 'spaceDelimited' && !explode && Array.isArray(value)) {\n output[field.name!] = {\n values: [value.join(' ')],\n };\n return;\n }\n\n if (style === 'pipeDelimited' && !explode && Array.isArray(value)) {\n output[field.name!] = {\n values: [value.join('|')],\n };\n return;\n }\n\n if (style === 'deepObject' && !Array.isArray(value) && typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n output[`${field.name}[${k}]`] = {\n // note: the behaviour of nested array is undefined, we do this to avoid edge cases\n values: Array.isArray(v) ? v : [String(v)],\n };\n }\n return;\n }\n\n if (Array.isArray(value)) {\n output[field.name!] = {\n values: explode ? value : [value.join(',')],\n };\n return;\n }\n\n if (typeof value === 'object' && explode) {\n for (const [k, v] of Object.entries(value)) {\n output[k] = {\n values: [String(v)],\n };\n }\n return;\n }\n\n if (typeof value === 'object') {\n output[field.name!] = {\n values: [Object.entries(value).flat().join(',')],\n };\n return;\n }\n\n output[field.name!] = {\n values: [String(value)],\n };\n}\n\nfunction serializeCookieParameter(\n field: ParameterObject,\n value: NonNullable<unknown>,\n // write output\n output: Record<string, EncodedParameter>,\n) {\n const { explode = true } = field;\n\n // form\n if (Array.isArray(value)) {\n output[field.name!] = {\n value: explode ? value.map((v) => `${field.name}=${v}`).join('&') : value.join(','),\n };\n } else if (typeof value === 'object' && explode) {\n for (const [k, v] of Object.entries(value)) {\n output[k] = {\n value: String(v),\n };\n }\n } else if (typeof value === 'object') {\n output[field.name!] = {\n value: Object.entries(value).flat().join(','),\n };\n } else {\n output[field.name!] = {\n value: String(value),\n };\n }\n}\n"],"mappings":";;;;;;AAgBA,SAAgB,kBACd,MACA,UACA,aAAgC,EAAE,EACrB;CACb,MAAM,SAAsB;EAC1B,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,eAAe,KAAK;EACpB,QAAQ,EAAE;EACV,QAAQ,EAAE;EACV,MAAM,EAAE;EACR,OAAO,EAAE;EACV;AAED,MAAK,MAAM,QAAQ;EAAC;EAAU;EAAS;EAAU;EAAO,CACtD,MAAK,MAAM,OAAO,KAAK,OAAO;EAC5B,MAAM,QAAQ,KAAK,MAAM;AACzB,MAAI,SAAS,KAAM;EAEnB,MAAM,QAAyB,WA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,UAAU,SAC1B,QAAO,MAAM,QAAS,EACpB,OAAO,OAAO,QAAQ,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAC9C;KAED,QAAO,MAAM,QAAS,EACpB,OAAO,OAAO,MAAM,EACrB"}
@@ -31,7 +31,7 @@ function resolveMediaAdapter(mediaType, adapters) {
31
31
  function isMediaTypeSupported(mediaType, adapters) {
32
32
  return resolveMediaAdapter(mediaType, adapters) !== void 0;
33
33
  }
34
-
35
34
  //#endregion
36
35
  export { isMediaTypeSupported, resolveMediaAdapter };
36
+
37
37
  //# sourceMappingURL=resolve-adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-adapter.js","names":[],"sources":["../../../src/requests/media/resolve-adapter.ts"],"sourcesContent":["import type { MediaAdapter } from './adapter';\n\nconst VariantMediaTypeRegex =\n /^(?<dir>[a-zA-Z0-9._-]+)\\/(?<content>[a-zA-Z0-9._-]+)\\+(?<variant>[a-zA-Z0-9._-]+)$/;\n\n/**\n * Resolve a media adapter for a given media type.\n * Supports exact matches and pattern matching (e.g., +json suffix).\n *\n * @param mediaType - The media type to resolve (e.g., \"application/json\", \"application/json-patch+json\")\n * @param adapters - Record of media adapters\n * @returns The resolved adapter or undefined if not found\n */\nexport function resolveMediaAdapter(\n mediaType: string,\n adapters: Record<string, MediaAdapter>,\n): MediaAdapter | undefined {\n // Normalize media type (remove parameters like charset)\n const normalized = mediaType.split(';', 2)[0].trim().toLowerCase();\n\n if (normalized in adapters) {\n return adapters[normalized];\n }\n\n const match = VariantMediaTypeRegex.exec(normalized);\n if (match?.groups) {\n const baseType = `${match.groups.dir}/${match.groups.variant}`;\n\n if (baseType in adapters) {\n return adapters[baseType];\n }\n }\n\n if (mediaType === 'text/plain') {\n console.warn(\n 'there is no defined behaviour for encoding form values into \"text/plain\", using JSON encoder for now.',\n );\n return adapters['application/json'];\n }\n}\n\n/**\n * Check if a media type is supported by the given adapters.\n *\n * @param mediaType - The media type to check\n * @param adapters - Record of media adapters\n * @returns true if the media type is supported\n */\nexport function isMediaTypeSupported(\n mediaType: string,\n adapters: Record<string, MediaAdapter>,\n): boolean {\n return resolveMediaAdapter(mediaType, adapters) !== undefined;\n}\n"],"mappings":";AAEA,MAAM,wBACJ;;;;;;;;;AAUF,SAAgB,oBACd,WACA,UAC0B;CAE1B,MAAM,aAAa,UAAU,MAAM,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,aAAa;AAElE,KAAI,cAAc,SAChB,QAAO,SAAS;CAGlB,MAAM,QAAQ,sBAAsB,KAAK,WAAW;AACpD,KAAI,OAAO,QAAQ;EACjB,MAAM,WAAW,GAAG,MAAM,OAAO,IAAI,GAAG,MAAM,OAAO;AAErD,MAAI,YAAY,SACd,QAAO,SAAS;;AAIpB,KAAI,cAAc,cAAc;AAC9B,UAAQ,KACN,0GACD;AACD,SAAO,SAAS;;;;;;;;;;AAWpB,SAAgB,qBACd,WACA,UACS;AACT,QAAO,oBAAoB,WAAW,SAAS,KAAK"}
1
+ {"version":3,"file":"resolve-adapter.js","names":[],"sources":["../../../src/requests/media/resolve-adapter.ts"],"sourcesContent":["import type { MediaAdapter } from './adapter';\n\nconst VariantMediaTypeRegex =\n /^(?<dir>[a-zA-Z0-9._-]+)\\/(?<content>[a-zA-Z0-9._-]+)\\+(?<variant>[a-zA-Z0-9._-]+)$/;\n\n/**\n * Resolve a media adapter for a given media type.\n * Supports exact matches and pattern matching (e.g., +json suffix).\n *\n * @param mediaType - The media type to resolve (e.g., \"application/json\", \"application/json-patch+json\")\n * @param adapters - Record of media adapters\n * @returns The resolved adapter or undefined if not found\n */\nexport function resolveMediaAdapter(\n mediaType: string,\n adapters: Record<string, MediaAdapter>,\n): MediaAdapter | undefined {\n // Normalize media type (remove parameters like charset)\n const normalized = mediaType.split(';', 2)[0].trim().toLowerCase();\n\n if (normalized in adapters) {\n return adapters[normalized];\n }\n\n const match = VariantMediaTypeRegex.exec(normalized);\n if (match?.groups) {\n const baseType = `${match.groups.dir}/${match.groups.variant}`;\n\n if (baseType in adapters) {\n return adapters[baseType];\n }\n }\n\n if (mediaType === 'text/plain') {\n console.warn(\n 'there is no defined behaviour for encoding form values into \"text/plain\", using JSON encoder for now.',\n );\n return adapters['application/json'];\n }\n}\n\n/**\n * Check if a media type is supported by the given adapters.\n *\n * @param mediaType - The media type to check\n * @param adapters - Record of media adapters\n * @returns true if the media type is supported\n */\nexport function isMediaTypeSupported(\n mediaType: string,\n adapters: Record<string, MediaAdapter>,\n): boolean {\n return resolveMediaAdapter(mediaType, adapters) !== undefined;\n}\n"],"mappings":";AAEA,MAAM,wBACJ;;;;;;;;;AAUF,SAAgB,oBACd,WACA,UAC0B;CAE1B,MAAM,aAAa,UAAU,MAAM,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,aAAa;AAElE,KAAI,cAAc,SAChB,QAAO,SAAS;CAGlB,MAAM,QAAQ,sBAAsB,KAAK,WAAW;AACpD,KAAI,OAAO,QAAQ;EACjB,MAAM,WAAW,GAAG,MAAM,OAAO,IAAI,GAAG,MAAM,OAAO;AAErD,MAAI,YAAY,SACd,QAAO,SAAS;;AAIpB,KAAI,cAAc,cAAc;AAC9B,UAAQ,KACN,0GACD;AACD,SAAO,SAAS;;;;;;;;;;AAWpB,SAAgB,qBACd,WACA,UACS;AACT,QAAO,oBAAoB,WAAW,SAAS,KAAK,KAAA"}
@@ -1,5 +1,4 @@
1
1
  import js2xml from "xml-js/lib/js2xml";
2
-
3
2
  //#region src/requests/string-utils.ts
4
3
  /**
5
4
  * Convert input value to hardcoded string (with quotes)
@@ -26,7 +25,7 @@ function escapeString(str, delimit) {
26
25
  function ident(code, tab = 1) {
27
26
  return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
28
27
  }
29
-
30
28
  //#endregion
31
29
  export { escapeString, ident, inputToString };
30
+
32
31
  //# sourceMappingURL=string-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-utils.js","names":[],"sources":["../../src/requests/string-utils.ts"],"sourcesContent":["// @ts-expect-error -- nothing\nimport js2xml from 'xml-js/lib/js2xml';\n\n/**\n * Convert input value to hardcoded string (with quotes)\n */\nexport function inputToString(\n value: unknown,\n format:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml' = 'application/json',\n): string {\n if (typeof value === 'string') return value;\n\n if (format === 'application/json') {\n return JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-ndjson') {\n return Array.isArray(value)\n ? value.map((v) => JSON.stringify(v)).join('\\n')\n : JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-www-form-urlencoded') {\n const params = new URLSearchParams();\n if (typeof value !== 'object')\n throw new Error(\n `For url encoded data, \\`value\\` must be an object, but received: ${typeof value}`,\n );\n\n for (const key in value) {\n if (value[key as keyof object]) params.set(key, String(value[key as keyof object]));\n }\n\n return params.toString();\n }\n\n return js2xml(value, { compact: true, spaces: 2 });\n}\n\nexport function escapeString(str: string, delimit?: string): string {\n if (!delimit) return JSON.stringify(str);\n\n return `${delimit}${str.replaceAll(delimit, `\\\\${delimit}`)}${delimit}`;\n}\n\nexport function ident(code: string, tab: number = 1) {\n return code\n .split('\\n')\n .map((v) => ' '.repeat(tab) + v)\n .join('\\n');\n}\n"],"mappings":";;;;;;AAMA,SAAgB,cACd,OACA,SAIwB,oBAChB;AACR,KAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,KAAI,WAAW,mBACb,QAAO,KAAK,UAAU,OAAO,MAAM,EAAE;AAGvC,KAAI,WAAW,uBACb,QAAO,MAAM,QAAQ,MAAM,GACvB,MAAM,KAAK,MAAM,KAAK,UAAU,EAAE,CAAC,CAAC,KAAK,KAAK,GAC9C,KAAK,UAAU,OAAO,MAAM,EAAE;AAGpC,KAAI,WAAW,qCAAqC;EAClD,MAAM,SAAS,IAAI,iBAAiB;AACpC,MAAI,OAAO,UAAU,SACnB,OAAM,IAAI,MACR,oEAAoE,OAAO,QAC5E;AAEH,OAAK,MAAM,OAAO,MAChB,KAAI,MAAM,KAAsB,QAAO,IAAI,KAAK,OAAO,MAAM,KAAqB,CAAC;AAGrF,SAAO,OAAO,UAAU;;AAG1B,QAAO,OAAO,OAAO;EAAE,SAAS;EAAM,QAAQ;EAAG,CAAC;;AAGpD,SAAgB,aAAa,KAAa,SAA0B;AAClE,KAAI,CAAC,QAAS,QAAO,KAAK,UAAU,IAAI;AAExC,QAAO,GAAG,UAAU,IAAI,WAAW,SAAS,KAAK,UAAU,GAAG;;AAGhE,SAAgB,MAAM,MAAc,MAAc,GAAG;AACnD,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG,EAAE,CAChC,KAAK,KAAK"}
1
+ {"version":3,"file":"string-utils.js","names":[],"sources":["../../src/requests/string-utils.ts"],"sourcesContent":["// @ts-expect-error -- nothing\nimport js2xml from 'xml-js/lib/js2xml';\n\n/**\n * Convert input value to hardcoded string (with quotes)\n */\nexport function inputToString(\n value: unknown,\n format:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml' = 'application/json',\n): string {\n if (typeof value === 'string') return value;\n\n if (format === 'application/json') {\n return JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-ndjson') {\n return Array.isArray(value)\n ? value.map((v) => JSON.stringify(v)).join('\\n')\n : JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-www-form-urlencoded') {\n const params = new URLSearchParams();\n if (typeof value !== 'object')\n throw new Error(\n `For url encoded data, \\`value\\` must be an object, but received: ${typeof value}`,\n );\n\n for (const key in value) {\n if (value[key as keyof object]) params.set(key, String(value[key as keyof object]));\n }\n\n return params.toString();\n }\n\n return js2xml(value, { compact: true, spaces: 2 });\n}\n\nexport function escapeString(str: string, delimit?: string): string {\n if (!delimit) return JSON.stringify(str);\n\n return `${delimit}${str.replaceAll(delimit, `\\\\${delimit}`)}${delimit}`;\n}\n\nexport function ident(code: string, tab: number = 1) {\n return code\n .split('\\n')\n .map((v) => ' '.repeat(tab) + v)\n .join('\\n');\n}\n"],"mappings":";;;;;AAMA,SAAgB,cACd,OACA,SAIwB,oBAChB;AACR,KAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,KAAI,WAAW,mBACb,QAAO,KAAK,UAAU,OAAO,MAAM,EAAE;AAGvC,KAAI,WAAW,uBACb,QAAO,MAAM,QAAQ,MAAM,GACvB,MAAM,KAAK,MAAM,KAAK,UAAU,EAAE,CAAC,CAAC,KAAK,KAAK,GAC9C,KAAK,UAAU,OAAO,MAAM,EAAE;AAGpC,KAAI,WAAW,qCAAqC;EAClD,MAAM,SAAS,IAAI,iBAAiB;AACpC,MAAI,OAAO,UAAU,SACnB,OAAM,IAAI,MACR,oEAAoE,OAAO,QAC5E;AAEH,OAAK,MAAM,OAAO,MAChB,KAAI,MAAM,KAAsB,QAAO,IAAI,KAAK,OAAO,MAAM,KAAqB,CAAC;AAGrF,SAAO,OAAO,UAAU;;AAG1B,QAAO,OAAO,OAAO;EAAE,SAAS;EAAM,QAAQ;EAAG,CAAC;;AAGpD,SAAgB,aAAa,KAAa,SAA0B;AAClE,KAAI,CAAC,QAAS,QAAO,KAAK,UAAU,IAAI;AAExC,QAAO,GAAG,UAAU,IAAI,WAAW,SAAS,KAAK,UAAU,GAAG;;AAGhE,SAAgB,MAAM,MAAc,MAAc,GAAG;AACnD,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG,EAAE,CAChC,KAAK,KAAK"}
@@ -11,7 +11,7 @@ function generatePythonObject(v, imports = /* @__PURE__ */ new Set()) {
11
11
  } else if (typeof v === "object") return `{\n${Object.entries(v).map(([key, value]) => ` ${JSON.stringify(key)}: ${generatePythonObject(value, imports)}`).join(", \n")}\n}`;
12
12
  else throw new Error(`Unsupported type: ${typeof v}`);
13
13
  }
14
-
15
14
  //#endregion
16
15
  export { generatePythonObject };
16
+
17
17
  //# sourceMappingURL=to-python-object.js.map
@@ -1,5 +1,4 @@
1
- 'use client';
2
-
1
+ "use client";
3
2
  import { cn } from "../utils/cn.js";
4
3
  import { MethodLabel } from "../ui/components/method-label.js";
5
4
  import { useEffect, useState } from "react";
@@ -8,7 +7,6 @@ import { buttonVariants } from "fumadocs-ui/components/ui/button";
8
7
  import { ApiClientModalProvider, useApiClientModal } from "@scalar/api-client-react";
9
8
  import { useTheme } from "next-themes";
10
9
  import "@scalar/api-client-react/style.css";
11
-
12
10
  //#region src/scalar/client.tsx
13
11
  function ScalarPlayground({ path, method, spec }) {
14
12
  const { resolvedTheme } = useTheme();
@@ -55,7 +53,7 @@ function Trigger({ path, method }) {
55
53
  children: "Test"
56
54
  });
57
55
  }
58
-
59
56
  //#endregion
60
57
  export { ScalarPlayground as default };
58
+
61
59
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/scalar/client.tsx"],"sourcesContent":["'use client';\nimport { cn } from '@/utils/cn';\nimport { buttonVariants } from 'fumadocs-ui/components/ui/button';\nimport { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';\nimport { MethodLabel } from '@/ui/components/method-label';\nimport { useTheme } from 'next-themes';\nimport { useEffect, useState } from 'react';\nimport '@scalar/api-client-react/style.css';\nimport type { HttpMethods } from '@/types';\n\nexport default function ScalarPlayground({\n path,\n method,\n spec,\n}: {\n spec: object;\n path: string;\n method: string;\n}) {\n const { resolvedTheme } = useTheme();\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n return (\n <div\n className={cn(\n 'flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose',\n mounted ? `${resolvedTheme}-mode` : null,\n )}\n >\n <MethodLabel className=\"text-xs\">{method}</MethodLabel>\n <code className=\"flex-1 overflow-auto text-nowrap text-[0.8125rem] text-fd-muted-foreground\">\n {path}\n </code>\n <ApiClientModalProvider\n configuration={{\n theme: 'moon',\n content: spec,\n }}\n >\n <Trigger path={path} method={method} />\n </ApiClientModalProvider>\n </div>\n );\n}\n\nfunction Trigger({ path, method }: { path: string; method: string }) {\n const client = useApiClientModal();\n\n return (\n <button\n type=\"submit\"\n className={cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5')}\n onClick={() => client?.open({ path, method: method as HttpMethods })}\n >\n Test\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAwB,iBAAiB,EACvC,MACA,QACA,QAKC;CACD,MAAM,EAAE,kBAAkB,UAAU;CACpC,MAAM,CAAC,SAAS,cAAc,SAAS,MAAM;AAE7C,iBAAgB;AACd,aAAW,KAAK;IACf,EAAE,CAAC;AAEN,QACE,qBAAC;EACC,WAAW,GACT,yGACA,UAAU,GAAG,cAAc,SAAS,KACrC;;GAED,oBAAC;IAAY,WAAU;cAAW;KAAqB;GACvD,oBAAC;IAAK,WAAU;cACb;KACI;GACP,oBAAC;IACC,eAAe;KACb,OAAO;KACP,SAAS;KACV;cAED,oBAAC;KAAc;KAAc;MAAU;KAChB;;GACrB;;AAIV,SAAS,QAAQ,EAAE,MAAM,UAA4C;CACnE,MAAM,SAAS,mBAAmB;AAElC,QACE,oBAAC;EACC,MAAK;EACL,WAAW,GAAG,eAAe;GAAE,OAAO;GAAW,MAAM;GAAM,CAAC,EAAE,cAAc;EAC9E,eAAe,QAAQ,KAAK;GAAE;GAAc;GAAuB,CAAC;YACrE;GAEQ"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/scalar/client.tsx"],"sourcesContent":["'use client';\nimport { cn } from '@/utils/cn';\nimport { buttonVariants } from 'fumadocs-ui/components/ui/button';\nimport { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';\nimport { MethodLabel } from '@/ui/components/method-label';\nimport { useTheme } from 'next-themes';\nimport { useEffect, useState } from 'react';\nimport '@scalar/api-client-react/style.css';\nimport type { HttpMethods } from '@/types';\n\nexport default function ScalarPlayground({\n path,\n method,\n spec,\n}: {\n spec: object;\n path: string;\n method: string;\n}) {\n const { resolvedTheme } = useTheme();\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n return (\n <div\n className={cn(\n 'flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose',\n mounted ? `${resolvedTheme}-mode` : null,\n )}\n >\n <MethodLabel className=\"text-xs\">{method}</MethodLabel>\n <code className=\"flex-1 overflow-auto text-nowrap text-[0.8125rem] text-fd-muted-foreground\">\n {path}\n </code>\n <ApiClientModalProvider\n configuration={{\n theme: 'moon',\n content: spec,\n }}\n >\n <Trigger path={path} method={method} />\n </ApiClientModalProvider>\n </div>\n );\n}\n\nfunction Trigger({ path, method }: { path: string; method: string }) {\n const client = useApiClientModal();\n\n return (\n <button\n type=\"submit\"\n className={cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5')}\n onClick={() => client?.open({ path, method: method as HttpMethods })}\n >\n Test\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAwB,iBAAiB,EACvC,MACA,QACA,QAKC;CACD,MAAM,EAAE,kBAAkB,UAAU;CACpC,MAAM,CAAC,SAAS,cAAc,SAAS,MAAM;AAE7C,iBAAgB;AACd,aAAW,KAAK;IACf,EAAE,CAAC;AAEN,QACE,qBAAC,OAAD;EACE,WAAW,GACT,yGACA,UAAU,GAAG,cAAc,SAAS,KACrC;YAJH;GAME,oBAAC,aAAD;IAAa,WAAU;cAAW;IAAqB,CAAA;GACvD,oBAAC,QAAD;IAAM,WAAU;cACb;IACI,CAAA;GACP,oBAAC,wBAAD;IACE,eAAe;KACb,OAAO;KACP,SAAS;KACV;cAED,oBAAC,SAAD;KAAe;KAAc;KAAU,CAAA;IAChB,CAAA;GACrB;;;AAIV,SAAS,QAAQ,EAAE,MAAM,UAA4C;CACnE,MAAM,SAAS,mBAAmB;AAElC,QACE,oBAAC,UAAD;EACE,MAAK;EACL,WAAW,GAAG,eAAe;GAAE,OAAO;GAAW,MAAM;GAAM,CAAC,EAAE,cAAc;EAC9E,eAAe,QAAQ,KAAK;GAAE;GAAc;GAAuB,CAAC;YACrE;EAEQ,CAAA"}
@@ -1,6 +1,5 @@
1
1
  import { lazy } from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
-
4
3
  //#region src/scalar/index.tsx
5
4
  const Client = lazy(() => import("./client.js"));
6
5
  function APIPlayground({ path, method, ctx }) {
@@ -26,7 +25,7 @@ function withScalar(options = {}) {
26
25
  }
27
26
  };
28
27
  }
29
-
30
28
  //#endregion
31
29
  export { withScalar };
30
+
32
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/scalar/index.tsx"],"sourcesContent":["import type { MethodInformation, RenderContext } from '@/types';\nimport type { CreateAPIPageOptions } from '@/ui';\nimport { lazy } from 'react';\n\nconst Client = lazy(() => import('./client'));\n\nfunction APIPlayground({\n path,\n method,\n ctx,\n}: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n}) {\n return <Client method={method.method} path={path} spec={ctx.schema.bundled} />;\n}\n\n/**\n * Enable Scalar for API playgrounds by wrapping your options inside.\n *\n * Requires `@scalar/api-client-react` to be installed, it imports the styles automatically.\n */\nexport function withScalar(options: CreateAPIPageOptions = {}): CreateAPIPageOptions {\n return {\n ...options,\n playground: {\n ...options.playground,\n render(props) {\n return <APIPlayground {...props} />;\n },\n },\n };\n}\n"],"mappings":";;;;AAIA,MAAM,SAAS,WAAW,OAAO,eAAY;AAE7C,SAAS,cAAc,EACrB,MACA,QACA,OAKC;AACD,QAAO,oBAAC;EAAO,QAAQ,OAAO;EAAc;EAAM,MAAM,IAAI,OAAO;GAAW;;;;;;;AAQhF,SAAgB,WAAW,UAAgC,EAAE,EAAwB;AACnF,QAAO;EACL,GAAG;EACH,YAAY;GACV,GAAG,QAAQ;GACX,OAAO,OAAO;AACZ,WAAO,oBAAC,iBAAc,GAAI,QAAS;;GAEtC;EACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/scalar/index.tsx"],"sourcesContent":["import type { MethodInformation, RenderContext } from '@/types';\nimport type { CreateAPIPageOptions } from '@/ui';\nimport { lazy } from 'react';\n\nconst Client = lazy(() => import('./client'));\n\nfunction APIPlayground({\n path,\n method,\n ctx,\n}: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n}) {\n return <Client method={method.method} path={path} spec={ctx.schema.bundled} />;\n}\n\n/**\n * Enable Scalar for API playgrounds by wrapping your options inside.\n *\n * Requires `@scalar/api-client-react` to be installed, it imports the styles automatically.\n */\nexport function withScalar(options: CreateAPIPageOptions = {}): CreateAPIPageOptions {\n return {\n ...options,\n playground: {\n ...options.playground,\n render(props) {\n return <APIPlayground {...props} />;\n },\n },\n };\n}\n"],"mappings":";;;AAIA,MAAM,SAAS,WAAW,OAAO,eAAY;AAE7C,SAAS,cAAc,EACrB,MACA,QACA,OAKC;AACD,QAAO,oBAAC,QAAD;EAAQ,QAAQ,OAAO;EAAc;EAAM,MAAM,IAAI,OAAO;EAAW,CAAA;;;;;;;AAQhF,SAAgB,WAAW,UAAgC,EAAE,EAAwB;AACnF,QAAO;EACL,GAAG;EACH,YAAY;GACV,GAAG,QAAQ;GACX,OAAO,OAAO;AACZ,WAAO,oBAAC,eAAD,EAAe,GAAI,OAAS,CAAA;;GAEtC;EACF"}
@@ -1,6 +1,5 @@
1
1
  import { createProxy } from "./proxy.js";
2
2
  import { processDocument } from "../utils/process-document.js";
3
-
4
3
  //#region src/server/create.ts
5
4
  function createOpenAPI(options = {}) {
6
5
  const { input = [], disableCache = false } = options;
@@ -36,7 +35,7 @@ function createOpenAPI(options = {}) {
36
35
  function createCodeSample(options) {
37
36
  return options;
38
37
  }
39
-
40
38
  //#endregion
41
39
  export { createCodeSample, createOpenAPI };
40
+
42
41
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","names":[],"sources":["../../src/server/create.ts"],"sourcesContent":["import { createProxy } from '@/server/proxy';\nimport { processDocument, type ProcessedDocument } from '@/utils/process-document';\nimport type { Document } from '@/types';\nimport type { InlineCodeUsageGenerator } from '@/requests/generators';\n\n/**\n * schema id -> file path, URL, or downloaded schema object\n */\ntype SchemaMap = Record<string, string | Document>;\ntype ProcessedSchemaMap = Record<string, ProcessedDocument>;\n\nexport interface OpenAPIOptions {\n /**\n * Schema files, can be:\n * - URL\n * - file path\n * - a function returning records of downloaded schemas.\n */\n input?: string[] | (() => SchemaMap | Promise<SchemaMap>);\n\n disableCache?: boolean;\n\n /**\n * The url of proxy to avoid CORS issues\n */\n proxyUrl?: string;\n}\n\nexport interface OpenAPIServer {\n createProxy: typeof createProxy;\n getSchemas: () => Promise<ProcessedSchemaMap>;\n getSchema: (document: string) => Promise<ProcessedDocument>;\n readonly options: OpenAPIOptions;\n}\n\nexport function createOpenAPI(options: OpenAPIOptions = {}): OpenAPIServer {\n const { input = [], disableCache = false } = options;\n let schemas: Promise<ProcessedSchemaMap> | undefined;\n\n async function getSchemas() {\n const out: ProcessedSchemaMap = {};\n\n if (Array.isArray(input)) {\n await Promise.all(\n input.map(async (item) => {\n out[item] = await processDocument(item);\n }),\n );\n } else {\n await Promise.all(\n Object.entries(await input()).map(async ([k, v]) => {\n out[k] = await processDocument(v);\n }),\n );\n }\n\n return out;\n }\n\n return {\n options,\n createProxy,\n async getSchema(document) {\n const schemas = await this.getSchemas();\n if (document in schemas) return schemas[document];\n\n console.warn(\n `[Fumadocs OpenAPI] the document \"${document}\" is not listed in the input array, this may not be expected.`,\n );\n // do not cache unlisted documents\n return processDocument(document);\n },\n async getSchemas() {\n if (disableCache) return getSchemas();\n\n return (schemas ??= getSchemas());\n },\n };\n}\n\n/**\n * @deprecated\n */\nexport function createCodeSample<T>(\n options: InlineCodeUsageGenerator<T>,\n): InlineCodeUsageGenerator<T> {\n return options;\n}\n"],"mappings":";;;;AAmCA,SAAgB,cAAc,UAA0B,EAAE,EAAiB;CACzE,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe,UAAU;CAC7C,IAAI;CAEJ,eAAe,aAAa;EAC1B,MAAM,MAA0B,EAAE;AAElC,MAAI,MAAM,QAAQ,MAAM,CACtB,OAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;AACxB,OAAI,QAAQ,MAAM,gBAAgB,KAAK;IACvC,CACH;MAED,OAAM,QAAQ,IACZ,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,OAAO;AAClD,OAAI,KAAK,MAAM,gBAAgB,EAAE;IACjC,CACH;AAGH,SAAO;;AAGT,QAAO;EACL;EACA;EACA,MAAM,UAAU,UAAU;GACxB,MAAM,UAAU,MAAM,KAAK,YAAY;AACvC,OAAI,YAAY,QAAS,QAAO,QAAQ;AAExC,WAAQ,KACN,oCAAoC,SAAS,+DAC9C;AAED,UAAO,gBAAgB,SAAS;;EAElC,MAAM,aAAa;AACjB,OAAI,aAAc,QAAO,YAAY;AAErC,UAAQ,YAAY,YAAY;;EAEnC;;;;;AAMH,SAAgB,iBACd,SAC6B;AAC7B,QAAO"}
1
+ {"version":3,"file":"create.js","names":[],"sources":["../../src/server/create.ts"],"sourcesContent":["import { createProxy } from '@/server/proxy';\nimport { processDocument, type ProcessedDocument } from '@/utils/process-document';\nimport type { Document } from '@/types';\nimport type { InlineCodeUsageGenerator } from '@/requests/generators';\n\n/**\n * schema id -> file path, URL, or downloaded schema object\n */\ntype SchemaMap = Record<string, string | Document>;\ntype ProcessedSchemaMap = Record<string, ProcessedDocument>;\n\nexport interface OpenAPIOptions {\n /**\n * Schema files, can be:\n * - URL\n * - file path\n * - a function returning records of downloaded schemas.\n */\n input?: string[] | (() => SchemaMap | Promise<SchemaMap>);\n\n disableCache?: boolean;\n\n /**\n * The url of proxy to avoid CORS issues\n */\n proxyUrl?: string;\n}\n\nexport interface OpenAPIServer {\n createProxy: typeof createProxy;\n getSchemas: () => Promise<ProcessedSchemaMap>;\n getSchema: (document: string) => Promise<ProcessedDocument>;\n readonly options: OpenAPIOptions;\n}\n\nexport function createOpenAPI(options: OpenAPIOptions = {}): OpenAPIServer {\n const { input = [], disableCache = false } = options;\n let schemas: Promise<ProcessedSchemaMap> | undefined;\n\n async function getSchemas() {\n const out: ProcessedSchemaMap = {};\n\n if (Array.isArray(input)) {\n await Promise.all(\n input.map(async (item) => {\n out[item] = await processDocument(item);\n }),\n );\n } else {\n await Promise.all(\n Object.entries(await input()).map(async ([k, v]) => {\n out[k] = await processDocument(v);\n }),\n );\n }\n\n return out;\n }\n\n return {\n options,\n createProxy,\n async getSchema(document) {\n const schemas = await this.getSchemas();\n if (document in schemas) return schemas[document];\n\n console.warn(\n `[Fumadocs OpenAPI] the document \"${document}\" is not listed in the input array, this may not be expected.`,\n );\n // do not cache unlisted documents\n return processDocument(document);\n },\n async getSchemas() {\n if (disableCache) return getSchemas();\n\n return (schemas ??= getSchemas());\n },\n };\n}\n\n/**\n * @deprecated\n */\nexport function createCodeSample<T>(\n options: InlineCodeUsageGenerator<T>,\n): InlineCodeUsageGenerator<T> {\n return options;\n}\n"],"mappings":";;;AAmCA,SAAgB,cAAc,UAA0B,EAAE,EAAiB;CACzE,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe,UAAU;CAC7C,IAAI;CAEJ,eAAe,aAAa;EAC1B,MAAM,MAA0B,EAAE;AAElC,MAAI,MAAM,QAAQ,MAAM,CACtB,OAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;AACxB,OAAI,QAAQ,MAAM,gBAAgB,KAAK;IACvC,CACH;MAED,OAAM,QAAQ,IACZ,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,OAAO;AAClD,OAAI,KAAK,MAAM,gBAAgB,EAAE;IACjC,CACH;AAGH,SAAO;;AAGT,QAAO;EACL;EACA;EACA,MAAM,UAAU,UAAU;GACxB,MAAM,UAAU,MAAM,KAAK,YAAY;AACvC,OAAI,YAAY,QAAS,QAAO,QAAQ;AAExC,WAAQ,KACN,oCAAoC,SAAS,+DAC9C;AAED,UAAO,gBAAgB,SAAS;;EAElC,MAAM,aAAa;AACjB,OAAI,aAAc,QAAO,YAAY;AAErC,UAAQ,YAAY,YAAY;;EAEnC;;;;;AAMH,SAAgB,iBACd,SAC6B;AAC7B,QAAO"}
@@ -1,4 +1,3 @@
1
1
  import { createCodeSample, createOpenAPI } from "./create.js";
2
2
  import { openapiPlugin, openapiSource, transformerOpenAPI } from "./source-api.js";
3
-
4
- export { createCodeSample, createOpenAPI, openapiPlugin, openapiSource, transformerOpenAPI };
3
+ export { createCodeSample, createOpenAPI, openapiPlugin, openapiSource, transformerOpenAPI };
@@ -53,7 +53,7 @@ function createProxy(options = {}) {
53
53
  for (const key of keys) handlers[key] = handler;
54
54
  return handlers;
55
55
  }
56
-
57
56
  //#endregion
58
57
  export { createProxy };
58
+
59
59
  //# sourceMappingURL=proxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","names":[],"sources":["../../src/server/proxy.ts"],"sourcesContent":["const keys = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'] as const;\n\ntype Proxy = {\n [K in (typeof keys)[number]]: (req: Request) => Promise<Response>;\n};\n\ninterface CreateProxyOptions {\n /**\n * Filter by prefixes of request url\n *\n * @deprecated Use `allowedOrigins` for filtering origins, or `filterRequest` for more detailed rules.\n */\n allowedUrls?: string[];\n\n /**\n * List of allowed origins to proxy to.\n */\n allowedOrigins?: string[];\n\n /**\n * Determine if the proxied request is allowed.\n *\n * @returns true if allowed, otherwise forbidden.\n */\n filterRequest?: (request: Request) => boolean;\n\n /**\n * Override proxied request/response with yours\n */\n overrides?: {\n request?: (request: Request) => Request;\n response?: (response: Response) => Response;\n };\n}\n\nexport function createProxy(options: CreateProxyOptions = {}): Proxy {\n const {\n allowedOrigins,\n allowedUrls,\n filterRequest = (req) => {\n return !allowedUrls || allowedUrls.some((item) => req.url.startsWith(item));\n },\n overrides,\n } = options;\n const handlers: Partial<Proxy> = {};\n\n async function handler(req: Request): Promise<Response> {\n const searchParams = new URL(req.url).searchParams;\n const url = searchParams.get('url');\n\n if (!url)\n return Response.json('[Proxy] A `url` query parameter is required for proxy url', {\n status: 400,\n });\n\n const parsedUrl = URL.parse(url);\n if (!parsedUrl)\n return Response.json('[Proxy] Invalid `url` parameter value.', {\n status: 400,\n });\n\n if (allowedOrigins && !allowedOrigins.includes(parsedUrl.origin)) {\n return Response.json(`[Proxy] The origin \"${parsedUrl.origin}\" is not allowed.`, {\n status: 400,\n });\n }\n\n const contentLength = req.headers.get('content-length');\n const hasBody = contentLength && parseInt(contentLength) > 0;\n\n let proxied = new Request(parsedUrl, {\n method: req.method,\n cache: 'no-cache',\n headers: req.headers,\n body:\n hasBody && ['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method.toUpperCase())\n ? await req.arrayBuffer()\n : undefined,\n });\n\n if (overrides?.request) {\n proxied = overrides.request(proxied);\n }\n\n if (!filterRequest(proxied)) {\n return Response.json('[Proxy] The proxied request is not allowed', {\n status: 403,\n });\n }\n\n proxied.headers.forEach((_value, originalKey) => {\n const key = originalKey.toLowerCase();\n\n if (key === 'origin') {\n proxied.headers.delete(originalKey);\n }\n });\n\n let res = await fetch(proxied).catch((e) => new Error(e.toString()));\n if (res instanceof Error) {\n return Response.json(`[Proxy] Failed to proxy request: ${res.message}`, {\n status: 500,\n });\n }\n\n if (overrides?.response) {\n res = overrides.response(res);\n }\n\n const headers = new Headers(res.headers);\n headers.forEach((_value, originalKey) => {\n const key = originalKey.toLowerCase();\n\n if (key.startsWith('access-control-')) {\n headers.delete(originalKey);\n }\n });\n headers.set('X-Forwarded-Host', res.url);\n\n return new Response(res.body, {\n status: res.status,\n statusText: res.statusText,\n headers,\n });\n }\n\n for (const key of keys) {\n handlers[key] = handler;\n }\n\n return handlers as Proxy;\n}\n"],"mappings":";AAAA,MAAM,OAAO;CAAC;CAAO;CAAQ;CAAO;CAAU;CAAS;CAAO;AAmC9D,SAAgB,YAAY,UAA8B,EAAE,EAA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,MACjB,QAAO,SAAS,KAAK,oCAAoC,IAAI,WAAW,EACtE,QAAQ,KACT,CAAC;AAGJ,MAAI,WAAW,SACb,OAAM,UAAU,SAAS,IAAI;EAG/B,MAAM,UAAU,IAAI,QAAQ,IAAI,QAAQ;AACxC,UAAQ,SAAS,QAAQ,gBAAgB;AAGvC,OAFY,YAAY,aAAa,CAE7B,WAAW,kBAAkB,CACnC,SAAQ,OAAO,YAAY;IAE7B;AACF,UAAQ,IAAI,oBAAoB,IAAI,IAAI;AAExC,SAAO,IAAI,SAAS,IAAI,MAAM;GAC5B,QAAQ,IAAI;GACZ,YAAY,IAAI;GAChB;GACD,CAAC;;AAGJ,MAAK,MAAM,OAAO,KAChB,UAAS,OAAO;AAGlB,QAAO"}
1
+ {"version":3,"file":"proxy.js","names":[],"sources":["../../src/server/proxy.ts"],"sourcesContent":["const keys = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'] as const;\n\ntype Proxy = {\n [K in (typeof keys)[number]]: (req: Request) => Promise<Response>;\n};\n\ninterface CreateProxyOptions {\n /**\n * Filter by prefixes of request url\n *\n * @deprecated Use `allowedOrigins` for filtering origins, or `filterRequest` for more detailed rules.\n */\n allowedUrls?: string[];\n\n /**\n * List of allowed origins to proxy to.\n */\n allowedOrigins?: string[];\n\n /**\n * Determine if the proxied request is allowed.\n *\n * @returns true if allowed, otherwise forbidden.\n */\n filterRequest?: (request: Request) => boolean;\n\n /**\n * Override proxied request/response with yours\n */\n overrides?: {\n request?: (request: Request) => Request;\n response?: (response: Response) => Response;\n };\n}\n\nexport function createProxy(options: CreateProxyOptions = {}): Proxy {\n const {\n allowedOrigins,\n allowedUrls,\n filterRequest = (req) => {\n return !allowedUrls || allowedUrls.some((item) => req.url.startsWith(item));\n },\n overrides,\n } = options;\n const handlers: Partial<Proxy> = {};\n\n async function handler(req: Request): Promise<Response> {\n const searchParams = new URL(req.url).searchParams;\n const url = searchParams.get('url');\n\n if (!url)\n return Response.json('[Proxy] A `url` query parameter is required for proxy url', {\n status: 400,\n });\n\n const parsedUrl = URL.parse(url);\n if (!parsedUrl)\n return Response.json('[Proxy] Invalid `url` parameter value.', {\n status: 400,\n });\n\n if (allowedOrigins && !allowedOrigins.includes(parsedUrl.origin)) {\n return Response.json(`[Proxy] The origin \"${parsedUrl.origin}\" is not allowed.`, {\n status: 400,\n });\n }\n\n const contentLength = req.headers.get('content-length');\n const hasBody = contentLength && parseInt(contentLength) > 0;\n\n let proxied = new Request(parsedUrl, {\n method: req.method,\n cache: 'no-cache',\n headers: req.headers,\n body:\n hasBody && ['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method.toUpperCase())\n ? await req.arrayBuffer()\n : undefined,\n });\n\n if (overrides?.request) {\n proxied = overrides.request(proxied);\n }\n\n if (!filterRequest(proxied)) {\n return Response.json('[Proxy] The proxied request is not allowed', {\n status: 403,\n });\n }\n\n proxied.headers.forEach((_value, originalKey) => {\n const key = originalKey.toLowerCase();\n\n if (key === 'origin') {\n proxied.headers.delete(originalKey);\n }\n });\n\n let res = await fetch(proxied).catch((e) => new Error(e.toString()));\n if (res instanceof Error) {\n return Response.json(`[Proxy] Failed to proxy request: ${res.message}`, {\n status: 500,\n });\n }\n\n if (overrides?.response) {\n res = overrides.response(res);\n }\n\n const headers = new Headers(res.headers);\n headers.forEach((_value, originalKey) => {\n const key = originalKey.toLowerCase();\n\n if (key.startsWith('access-control-')) {\n headers.delete(originalKey);\n }\n });\n headers.set('X-Forwarded-Host', res.url);\n\n return new Response(res.body, {\n status: res.status,\n statusText: res.statusText,\n headers,\n });\n }\n\n for (const key of keys) {\n handlers[key] = handler;\n }\n\n return handlers as Proxy;\n}\n"],"mappings":";AAAA,MAAM,OAAO;CAAC;CAAO;CAAQ;CAAO;CAAU;CAAS;CAAO;AAmC9D,SAAgB,YAAY,UAA8B,EAAE,EAAS;CACnE,MAAM,EACJ,gBACA,aACA,iBAAiB,QAAQ;AACvB,SAAO,CAAC,eAAe,YAAY,MAAM,SAAS,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WAAW,SACb,OAAM,UAAU,SAAS,IAAI;EAG/B,MAAM,UAAU,IAAI,QAAQ,IAAI,QAAQ;AACxC,UAAQ,SAAS,QAAQ,gBAAgB;AAGvC,OAFY,YAAY,aAAa,CAE7B,WAAW,kBAAkB,CACnC,SAAQ,OAAO,YAAY;IAE7B;AACF,UAAQ,IAAI,oBAAoB,IAAI,IAAI;AAExC,SAAO,IAAI,SAAS,IAAI,MAAM;GAC5B,QAAQ,IAAI;GACZ,YAAY,IAAI;GAChB;GACD,CAAC;;AAGJ,MAAK,MAAM,OAAO,KAChB,UAAS,OAAO;AAGlB,QAAO"}
@@ -1,6 +1,5 @@
1
1
  import { MethodLabel } from "../ui/components/method-label.js";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
-
4
3
  //#region src/server/source-api.tsx
5
4
  /**
6
5
  * Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
@@ -82,7 +81,7 @@ async function openapiSource(server, options = {}) {
82
81
  function transformerOpenAPI() {
83
82
  return openapiPlugin().transformPageTree;
84
83
  }
85
-
86
84
  //#endregion
87
85
  export { openapiPlugin, openapiSource, transformerOpenAPI };
86
+
88
87
  //# sourceMappingURL=source-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.js","names":[],"sources":["../../src/server/source-api.tsx"],"sourcesContent":["import { MethodLabel } from '@/ui/components/method-label';\nimport type {\n LoaderPlugin,\n PageData,\n PageTreeTransformer,\n Source,\n VirtualFile,\n} from 'fumadocs-core/source';\nimport type { OpenAPIServer } from '@/server/create';\nimport type { SchemaToPagesOptions } from '@/utils/pages/preset-auto';\nimport type { ApiPageProps } from '@/ui/api-page';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { ProcessedDocument } from '@/utils/process-document';\n\ndeclare module 'fumadocs-core/source' {\n export interface PageData {\n /**\n * Added by Fumadocs OpenAPI\n */\n _openapi?: InternalOpenAPIMeta;\n }\n}\n\nexport interface InternalOpenAPIMeta {\n method?: string;\n webhook?: boolean;\n}\n\n/**\n * Fumadocs Source API integration, pass this to `plugins` array in `loader()`.\n */\nexport function openapiPlugin(): LoaderPlugin {\n return {\n name: 'fumadocs:openapi',\n enforce: 'pre',\n transformPageTree: {\n file(node, filePath) {\n if (!filePath) return node;\n const file = this.storage.read(filePath);\n if (!file || file.format !== 'page') return node;\n\n const openApiData = file.data._openapi;\n if (!openApiData || typeof openApiData !== 'object') return node;\n\n if (openApiData.webhook) {\n node.name = (\n <>\n {node.name}{' '}\n <span className=\"ms-auto border border-current px-1 rounded-lg text-xs text-nowrap font-mono\">\n Webhook\n </span>\n </>\n );\n } else if (openApiData.method) {\n node.name = (\n <>\n {node.name}{' '}\n <MethodLabel className=\"ms-auto text-xs text-nowrap\">\n {openApiData.method}\n </MethodLabel>\n </>\n );\n }\n\n return node;\n },\n },\n };\n}\n\ninterface OpenAPIPageData extends PageData {\n getAPIPageProps: () => ApiPageProps;\n getSchema: () => { id: string } & ProcessedDocument;\n structuredData: StructuredData;\n toc: TOCItemType[];\n}\n\n/**\n * Generate virtual pages for Fumadocs Source API\n */\nexport async function openapiSource(\n server: OpenAPIServer,\n options: SchemaToPagesOptions & {\n baseDir?: string;\n } = {},\n): Promise<\n Source<{\n metaData: never;\n pageData: OpenAPIPageData;\n }>\n> {\n const { baseDir = '' } = options;\n const { createAutoPreset } = await import('@/utils/pages/preset-auto');\n const { fromServer } = await import('@/utils/pages/builder');\n const { toBody } = await import('@/utils/pages/to-body');\n const { toStaticData } = await import('@/utils/pages/to-static-data');\n const files: VirtualFile<{\n pageData: OpenAPIPageData;\n metaData: never;\n }>[] = [];\n\n const entries = await fromServer(server, createAutoPreset(options));\n for (const [schemaId, list] of Object.entries(entries)) {\n const processed = await server.getSchema(schemaId);\n for (const entry of list) {\n const props = toBody(entry);\n props.showDescription ??= true;\n\n files.push({\n type: 'page',\n path: `${baseDir}/${entry.path}`,\n data: {\n ...entry.info,\n getAPIPageProps() {\n return props;\n },\n getSchema() {\n return {\n id: schemaId,\n ...processed,\n };\n },\n ...toStaticData(props, processed.dereferenced),\n _openapi: {\n method:\n entry.type === 'operation' || entry.type === 'webhook'\n ? entry.item.method\n : undefined,\n webhook: entry.type === 'webhook',\n },\n },\n });\n }\n }\n\n return {\n files,\n };\n}\n\n/**\n * @deprecated use `openapiPlugin()`\n */\nexport function transformerOpenAPI(): PageTreeTransformer {\n return openapiPlugin().transformPageTree!;\n}\n"],"mappings":";;;;;;;AAgCA,SAAgB,gBAA8B;AAC5C,QAAO;EACL,MAAM;EACN,SAAS;EACT,mBAAmB,EACjB,KAAK,MAAM,UAAU;AACnB,OAAI,CAAC,SAAU,QAAO;GACtB,MAAM,OAAO,KAAK,QAAQ,KAAK,SAAS;AACxC,OAAI,CAAC,QAAQ,KAAK,WAAW,OAAQ,QAAO;GAE5C,MAAM,cAAc,KAAK,KAAK;AAC9B,OAAI,CAAC,eAAe,OAAO,gBAAgB,SAAU,QAAO;AAE5D,OAAI,YAAY,QACd,MAAK,OACH;IACG,KAAK;IAAM;IACZ,oBAAC;KAAK,WAAU;eAA8E;MAEvF;OACN;YAEI,YAAY,OACrB,MAAK,OACH;IACG,KAAK;IAAM;IACZ,oBAAC;KAAY,WAAU;eACpB,YAAY;MACD;OACb;AAIP,UAAO;KAEV;EACF;;;;;AAaH,eAAsB,cACpB,QACA,UAEI,EAAE,EAMN;CACA,MAAM,EAAE,UAAU,OAAO;CACzB,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,EAAE,eAAe,MAAM,OAAO;CACpC,MAAM,EAAE,WAAW,MAAM,OAAO;CAChC,MAAM,EAAE,iBAAiB,MAAM,OAAO;CACtC,MAAM,QAGC,EAAE;CAET,MAAM,UAAU,MAAM,WAAW,QAAQ,iBAAiB,QAAQ,CAAC;AACnE,MAAK,MAAM,CAAC,UAAU,SAAS,OAAO,QAAQ,QAAQ,EAAE;EACtD,MAAM,YAAY,MAAM,OAAO,UAAU,SAAS;AAClD,OAAK,MAAM,SAAS,MAAM;GACxB,MAAM,QAAQ,OAAO,MAAM;AAC3B,SAAM,oBAAoB;AAE1B,SAAM,KAAK;IACT,MAAM;IACN,MAAM,GAAG,QAAQ,GAAG,MAAM;IAC1B,MAAM;KACJ,GAAG,MAAM;KACT,kBAAkB;AAChB,aAAO;;KAET,YAAY;AACV,aAAO;OACL,IAAI;OACJ,GAAG;OACJ;;KAEH,GAAG,aAAa,OAAO,UAAU,aAAa;KAC9C,UAAU;MACR,QACE,MAAM,SAAS,eAAe,MAAM,SAAS,YACzC,MAAM,KAAK,SACX;MACN,SAAS,MAAM,SAAS;MACzB;KACF;IACF,CAAC;;;AAIN,QAAO,EACL,OACD;;;;;AAMH,SAAgB,qBAA0C;AACxD,QAAO,eAAe,CAAC"}
1
+ {"version":3,"file":"source-api.js","names":[],"sources":["../../src/server/source-api.tsx"],"sourcesContent":["import { MethodLabel } from '@/ui/components/method-label';\nimport type {\n LoaderPlugin,\n PageData,\n PageTreeTransformer,\n Source,\n VirtualFile,\n} from 'fumadocs-core/source';\nimport type { OpenAPIServer } from '@/server/create';\nimport type { SchemaToPagesOptions } from '@/utils/pages/preset-auto';\nimport type { ApiPageProps } from '@/ui/api-page';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { ProcessedDocument } from '@/utils/process-document';\n\ndeclare module 'fumadocs-core/source' {\n export interface PageData {\n /**\n * Added by Fumadocs OpenAPI\n */\n _openapi?: InternalOpenAPIMeta;\n }\n}\n\nexport interface InternalOpenAPIMeta {\n method?: string;\n webhook?: boolean;\n}\n\n/**\n * Fumadocs Source API integration, pass this to `plugins` array in `loader()`.\n */\nexport function openapiPlugin(): LoaderPlugin {\n return {\n name: 'fumadocs:openapi',\n enforce: 'pre',\n transformPageTree: {\n file(node, filePath) {\n if (!filePath) return node;\n const file = this.storage.read(filePath);\n if (!file || file.format !== 'page') return node;\n\n const openApiData = file.data._openapi;\n if (!openApiData || typeof openApiData !== 'object') return node;\n\n if (openApiData.webhook) {\n node.name = (\n <>\n {node.name}{' '}\n <span className=\"ms-auto border border-current px-1 rounded-lg text-xs text-nowrap font-mono\">\n Webhook\n </span>\n </>\n );\n } else if (openApiData.method) {\n node.name = (\n <>\n {node.name}{' '}\n <MethodLabel className=\"ms-auto text-xs text-nowrap\">\n {openApiData.method}\n </MethodLabel>\n </>\n );\n }\n\n return node;\n },\n },\n };\n}\n\ninterface OpenAPIPageData extends PageData {\n getAPIPageProps: () => ApiPageProps;\n getSchema: () => { id: string } & ProcessedDocument;\n structuredData: StructuredData;\n toc: TOCItemType[];\n}\n\n/**\n * Generate virtual pages for Fumadocs Source API\n */\nexport async function openapiSource(\n server: OpenAPIServer,\n options: SchemaToPagesOptions & {\n baseDir?: string;\n } = {},\n): Promise<\n Source<{\n metaData: never;\n pageData: OpenAPIPageData;\n }>\n> {\n const { baseDir = '' } = options;\n const { createAutoPreset } = await import('@/utils/pages/preset-auto');\n const { fromServer } = await import('@/utils/pages/builder');\n const { toBody } = await import('@/utils/pages/to-body');\n const { toStaticData } = await import('@/utils/pages/to-static-data');\n const files: VirtualFile<{\n pageData: OpenAPIPageData;\n metaData: never;\n }>[] = [];\n\n const entries = await fromServer(server, createAutoPreset(options));\n for (const [schemaId, list] of Object.entries(entries)) {\n const processed = await server.getSchema(schemaId);\n for (const entry of list) {\n const props = toBody(entry);\n props.showDescription ??= true;\n\n files.push({\n type: 'page',\n path: `${baseDir}/${entry.path}`,\n data: {\n ...entry.info,\n getAPIPageProps() {\n return props;\n },\n getSchema() {\n return {\n id: schemaId,\n ...processed,\n };\n },\n ...toStaticData(props, processed.dereferenced),\n _openapi: {\n method:\n entry.type === 'operation' || entry.type === 'webhook'\n ? entry.item.method\n : undefined,\n webhook: entry.type === 'webhook',\n },\n },\n });\n }\n }\n\n return {\n files,\n };\n}\n\n/**\n * @deprecated use `openapiPlugin()`\n */\nexport function transformerOpenAPI(): PageTreeTransformer {\n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J,GAAG,MAAM;KACT,kBAAkB;AAChB,aAAO;;KAET,YAAY;AACV,aAAO;OACL,IAAI;OACJ,GAAG;OACJ;;KAEH,GAAG,aAAa,OAAO,UAAU,aAAa;KAC9C,UAAU;MACR,QACE,MAAM,SAAS,eAAe,MAAM,SAAS,YACzC,MAAM,KAAK,SACX,KAAA;MACN,SAAS,MAAM,SAAS;MACzB;KACF;IACF,CAAC;;;AAIN,QAAO,EACL,OACD;;;;;AAMH,SAAgB,qBAA0C;AACxD,QAAO,eAAe,CAAC"}
@@ -2,7 +2,6 @@ import { createMethod } from "../utils/schema.js";
2
2
  import { ApiProviderLazy, ServerProviderLazy } from "./contexts/api.lazy.js";
3
3
  import { Operation } from "./operation/index.js";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
-
6
5
  //#region src/ui/api-page.tsx
7
6
  async function APIPage({ showTitle: hasHead = false, showDescription, operations, webhooks, ctx }) {
8
7
  const { dereferenced } = ctx.schema;
@@ -57,7 +56,7 @@ async function APIPage({ showTitle: hasHead = false, showDescription, operations
57
56
  })
58
57
  });
59
58
  }
60
-
61
59
  //#endregion
62
60
  export { APIPage };
61
+
63
62
  //# sourceMappingURL=api-page.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-page.js","names":[],"sources":["../../src/ui/api-page.tsx"],"sourcesContent":["import { Operation } from '@/ui/operation';\nimport type { HttpMethods, RenderContext } from '@/types';\nimport { createMethod } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { ApiProviderLazy, ServerProviderLazy } from './contexts/api.lazy';\n\nexport interface ApiPageProps {\n document: Promise<ProcessedDocument> | string | ProcessedDocument;\n showTitle?: boolean;\n showDescription?: boolean;\n\n /**\n * An array of operations\n */\n operations?: OperationItem[];\n\n webhooks?: WebhookItem[];\n}\n\nexport interface WebhookItem {\n /**\n * webhook name in `webhooks`\n */\n name: string;\n method: HttpMethods;\n}\n\nexport interface OperationItem {\n /**\n * the path of operation in `paths`\n */\n path: string;\n /**\n * the HTTP method of operation\n */\n method: HttpMethods;\n}\n\nexport async function APIPage({\n showTitle: hasHead = false,\n showDescription,\n operations,\n webhooks,\n ctx,\n}: Omit<ApiPageProps, 'document'> & {\n ctx: RenderContext;\n}) {\n const { dereferenced } = ctx.schema;\n let { renderPageLayout } = ctx.content ?? {};\n renderPageLayout ??= (slots) => (\n <div className=\"flex flex-col gap-24 text-sm @container\">\n {slots.operations?.map((op) => op.children)}\n {slots.webhooks?.map((op) => op.children)}\n </div>\n );\n\n const content = await renderPageLayout(\n {\n operations: operations?.map((item) => {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem)\n throw new Error(`[Fumadocs OpenAPI] Path not found in OpenAPI schema: ${item.path}`);\n\n const operation = pathItem[item.method];\n if (!operation)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in operation: ${item.path}`,\n );\n\n const method = createMethod(item.method, pathItem, operation);\n\n return {\n item,\n children: (\n <Operation\n key={`${item.path}:${item.method}`}\n method={method}\n path={item.path}\n ctx={ctx}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n webhooks: webhooks?.map((item) => {\n const webhook = dereferenced.webhooks?.[item.name];\n if (!webhook)\n throw new Error(`[Fumadocs OpenAPI] Webhook not found in OpenAPI schema: ${item.name}`);\n\n const hook = webhook[item.method];\n if (!hook)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`,\n );\n\n return {\n item,\n children: (\n <Operation\n type=\"webhook\"\n key={`${item.name}:${item.method}`}\n method={createMethod(item.method, webhook, hook)}\n ctx={ctx}\n path={`/${item.name}`}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n },\n ctx,\n );\n let servers = ctx.schema.dereferenced.servers;\n if (!servers || servers.length === 0) servers = [{ url: '/' }];\n\n return (\n <ApiProviderLazy shikiOptions={ctx.shikiOptions} client={ctx.client ?? {}}>\n <ServerProviderLazy servers={servers}>{content}</ServerProviderLazy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OAAO,aAAa;AACtC,KAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,WAAU,CAAC,EAAE,KAAK,KAAK,CAAC;AAE9D,QACE,oBAAC;EAAgB,cAAc,IAAI;EAAc,QAAQ,IAAI,UAAU,EAAE;YACvE,oBAAC;GAA4B;aAAU;IAA6B;GACpD"}
1
+ {"version":3,"file":"api-page.js","names":[],"sources":["../../src/ui/api-page.tsx"],"sourcesContent":["import { Operation } from '@/ui/operation';\nimport type { HttpMethods, RenderContext } from '@/types';\nimport { createMethod } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { ApiProviderLazy, ServerProviderLazy } from './contexts/api.lazy';\n\nexport interface ApiPageProps {\n document: Promise<ProcessedDocument> | string | ProcessedDocument;\n showTitle?: boolean;\n showDescription?: boolean;\n\n /**\n * An array of operations\n */\n operations?: OperationItem[];\n\n webhooks?: WebhookItem[];\n}\n\nexport interface WebhookItem {\n /**\n * webhook name in `webhooks`\n */\n name: string;\n method: HttpMethods;\n}\n\nexport interface OperationItem {\n /**\n * the path of operation in `paths`\n */\n path: string;\n /**\n * the HTTP method of operation\n */\n method: HttpMethods;\n}\n\nexport async function APIPage({\n showTitle: hasHead = false,\n showDescription,\n operations,\n webhooks,\n ctx,\n}: Omit<ApiPageProps, 'document'> & {\n ctx: RenderContext;\n}) {\n const { dereferenced } = ctx.schema;\n let { renderPageLayout } = ctx.content ?? {};\n renderPageLayout ??= (slots) => (\n <div className=\"flex flex-col gap-24 text-sm @container\">\n {slots.operations?.map((op) => op.children)}\n {slots.webhooks?.map((op) => op.children)}\n </div>\n );\n\n const content = await renderPageLayout(\n {\n operations: operations?.map((item) => {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem)\n throw new Error(`[Fumadocs OpenAPI] Path not found in OpenAPI schema: ${item.path}`);\n\n const operation = pathItem[item.method];\n if (!operation)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in operation: ${item.path}`,\n );\n\n const method = createMethod(item.method, pathItem, operation);\n\n return {\n item,\n children: (\n <Operation\n key={`${item.path}:${item.method}`}\n method={method}\n path={item.path}\n ctx={ctx}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n webhooks: webhooks?.map((item) => {\n const webhook = dereferenced.webhooks?.[item.name];\n if (!webhook)\n throw new Error(`[Fumadocs OpenAPI] Webhook not found in OpenAPI schema: ${item.name}`);\n\n const hook = webhook[item.method];\n if (!hook)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`,\n );\n\n return {\n item,\n children: (\n <Operation\n type=\"webhook\"\n key={`${item.name}:${item.method}`}\n method={createMethod(item.method, webhook, hook)}\n ctx={ctx}\n path={`/${item.name}`}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n },\n ctx,\n );\n let servers = ctx.schema.dereferenced.servers;\n if (!servers || servers.length === 0) servers = [{ url: '/' }];\n\n return (\n <ApiProviderLazy shikiOptions={ctx.shikiOptions} client={ctx.client ?? {}}>\n <ServerProviderLazy servers={servers}>{content}</ServerProviderLazy>\n </ApiProviderLazy>\n );\n}\n"],"mappings":";;;;;AAsCA,eAAsB,QAAQ,EAC5B,WAAW,UAAU,OACrB,iBACA,YACA,UACA,OAGC;CACD,MAAM,EAAE,iBAAiB,IAAI;CAC7B,IAAI,EAAE,qBAAqB,IAAI,WAAW,EAAE;AAC5C,uBAAsB,UACpB,qBAAC,OAAD;EAAK,WAAU;YAAf,CACG,MAAM,YAAY,KAAK,OAAO,GAAG,SAAS,EAC1C,MAAM,UAAU,KAAK,OAAO,GAAG,SAAS,CACrC;;CAGR,MAAM,UAAU,MAAM,iBACpB;EACE,YAAY,YAAY,KAAK,SAAS;GACpC,MAAM,WAAW,aAAa,QAAQ,KAAK;AAC3C,OAAI,CAAC,SACH,OAAM,IAAI,MAAM,wDAAwD,KAAK,OAAO;GAEtF,MAAM,YAAY,SAAS,KAAK;AAChC,OAAI,CAAC,UACH,OAAM,IAAI,MACR,6BAA6B,KAAK,OAAO,2BAA2B,KAAK,OAC1E;AAIH,UAAO;IACL;IACA,UACE,oBAAC,WAAD;KAEE,QAPS,aAAa,KAAK,QAAQ,UAAU,UAAU;KAQvD,MAAM,KAAK;KACN;KACL,WAAW;KACM;KACjB,EANK,GAAG,KAAK,KAAK,GAAG,KAAK,SAM1B;IAEL;IACD;EACF,UAAU,UAAU,KAAK,SAAS;GAChC,MAAM,UAAU,aAAa,WAAW,KAAK;AAC7C,OAAI,CAAC,QACH,OAAM,IAAI,MAAM,2DAA2D,KAAK,OAAO;GAEzF,MAAM,OAAO,QAAQ,KAAK;AAC1B,OAAI,CAAC,KACH,OAAM,IAAI,MACR,6BAA6B,KAAK,OAAO,yBAAyB,KAAK,OACxE;AAEH,UAAO;IACL;IACA,UACE,oBAAC,WAAD;KACE,MAAK;KAEL,QAAQ,aAAa,KAAK,QAAQ,SAAS,KAAK;KAC3C;KACL,MAAM,IAAI,KAAK;KACf,WAAW;KACM;KACjB,EANK,GAAG,KAAK,KAAK,GAAG,KAAK,SAM1B;IAEL;IACD;EACH,EACD,IACD;CACD,IAAI,UAAU,IAAI,OAAO,aAAa;AACtC,KAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,WAAU,CAAC,EAAE,KAAK,KAAK,CAAC;AAE9D,QACE,oBAAC,iBAAD;EAAiB,cAAc,IAAI;EAAc,QAAQ,IAAI,UAAU,EAAE;YACvE,oBAAC,oBAAD;GAA6B;aAAU;GAA6B,CAAA;EACpD,CAAA"}
package/dist/ui/base.js CHANGED
@@ -12,7 +12,6 @@ import { remark } from "remark";
12
12
  import remarkRehype from "remark-rehype";
13
13
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
14
14
  import { CodeBlock, Pre } from "fumadocs-ui/components/codeblock";
15
-
16
15
  //#region src/ui/base.tsx
17
16
  function createAPIPage(server, options) {
18
17
  let processor;
@@ -95,7 +94,7 @@ function createAPIPage(server, options) {
95
94
  });
96
95
  };
97
96
  }
98
-
99
97
  //#endregion
100
98
  export { createAPIPage };
99
+
101
100
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","names":[],"sources":["../../src/ui/base.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport Slugger from 'github-slugger';\nimport type { Awaitable, DistributiveOmit, MethodInformation, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters, MediaAdapter } from '@/requests/media/adapter';\nimport type { FC, HTMLAttributes, ReactNode } from 'react';\nimport { highlight, type CoreHighlightOptions } from 'fumadocs-core/highlight/core';\nimport type { OpenAPIServer } from '@/server';\nimport type { APIPageClientOptions } from './client';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { createRehypeCode } from 'fumadocs-core/mdx-plugins/rehype-code.core';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';\nimport type { SchemaUIOptions } from './schema';\nimport type { ResponseTab } from './operation/response-tabs';\nimport type { ExampleRequestItem } from './operation/request-tabs';\nimport type { ResolvedShikiConfig } from 'fumadocs-core/highlight/config';\nimport { APIPage, type ApiPageProps, type OperationItem, type WebhookItem } from './api-page';\nimport type { CodeUsageGeneratorRegistry, InlineCodeUsageGenerator } from '@/requests/generators';\nimport type { JSONSchema } from 'json-schema-typed';\n\nexport interface GenerateTypeScriptDefinitionsContext extends RenderContext {\n operation: NoReference<MethodInformation>;\n readOnly: boolean;\n writeOnly: boolean;\n /** @deprecated */\n _internal_legacy?: {\n statusCode: string;\n contentType: string;\n };\n}\n\nexport interface CreateAPIPageOptions {\n /**\n * Generate TypeScript definitions from response schema.\n *\n * Pass `false` to disable it.\n *\n * @param method - the operation object\n * @param statusCode - status code\n * @deprecated use `generateTypeScriptDefinitions` instead.\n */\n generateTypeScriptSchema?:\n | ((\n method: NoReference<MethodInformation>,\n statusCode: string,\n contentType: string,\n ctx: RenderContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate TypeScript definitions from JSON schema.\n *\n * Pass `false` to disable it.\n */\n generateTypeScriptDefinitions?: (\n schema: JSONSchema,\n ctx: GenerateTypeScriptDefinitionsContext,\n ) => Awaitable<string | undefined>;\n\n /**\n * Generate example code usage for all endpoints.\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n\n /**\n * Generate example code usage for each endpoint.\n */\n generateCodeSamples?: (method: MethodInformation) => Awaitable<InlineCodeUsageGenerator[]>;\n\n shiki: ResolvedShikiConfig;\n renderMarkdown?: (md: string) => ReactNode;\n shikiOptions?: DistributiveOmit<CoreHighlightOptions, 'config' | 'lang' | 'components'>;\n\n /**\n * Show full response schema instead of only example response & Typescript definitions.\n *\n * @default true\n */\n showResponseSchema?: boolean;\n\n /**\n * Support other media types (for server-side generation).\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * Customise page content\n */\n content?: {\n renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => Awaitable<ReactNode>;\n\n renderRequestTabs?: (\n items: ExampleRequestItem[],\n ctx: RenderContext & {\n route: string;\n operation: NoReference<MethodInformation>;\n },\n ) => Awaitable<ReactNode>;\n\n renderAPIExampleLayout?: (\n slots: {\n selector: ReactNode;\n usageTabs: ReactNode;\n responseTabs: ReactNode;\n },\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n /**\n * @param generators - codegens for API example usages\n */\n renderAPIExampleUsageTabs?: (\n generators: CodeUsageGeneratorRegistry,\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n /**\n * renderer of the entire page's layout (containing all operations & webhooks UI)\n */\n renderPageLayout?: (\n slots: {\n operations?: {\n item: OperationItem;\n children: ReactNode;\n }[];\n webhooks?: {\n item: WebhookItem;\n children: ReactNode;\n }[];\n },\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n renderOperationLayout?: (\n slots: {\n header: ReactNode;\n description: ReactNode;\n apiExample: ReactNode;\n apiPlayground: ReactNode;\n\n authSchemes: ReactNode;\n paremeters: ReactNode;\n body: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n },\n ctx: RenderContext,\n method: NoReference<MethodInformation>,\n ) => Awaitable<ReactNode>;\n\n renderWebhookLayout?: (slots: {\n header: ReactNode;\n description: ReactNode;\n authSchemes: ReactNode;\n paremeters: ReactNode;\n body: ReactNode;\n requests: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n }) => Awaitable<ReactNode>;\n };\n\n /**\n * Info UI for JSON schemas\n */\n schemaUI?: {\n render?: (options: SchemaUIOptions, ctx: RenderContext) => Awaitable<ReactNode>;\n\n /**\n * Show examples under the generated content of JSON schemas.\n *\n * @defaultValue false\n */\n showExample?: boolean;\n };\n\n /**\n * Customise API playground\n */\n playground?: {\n /**\n * @defaultValue true\n */\n enabled?: boolean;\n /**\n * replace the server-side renderer\n */\n render?: (props: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n }) => Awaitable<ReactNode>;\n };\n\n renderHeading?: (\n props: HTMLAttributes<HTMLHeadingElement>,\n depth: number,\n ) => Awaitable<ReactNode>;\n renderCodeBlock?: (props: { lang: string; code: string }) => Awaitable<ReactNode>;\n\n client?: APIPageClientOptions;\n}\n\nexport function createAPIPage(\n server: OpenAPIServer,\n options: CreateAPIPageOptions,\n): FC<ApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: defaultMdxComponents,\n });\n };\n }\n\n return remark()\n .use(remarkGfm)\n .use(remarkRehype)\n .use(createRehypeCode(options.shiki), {\n langs: [],\n lazy: true,\n })\n .use(rehypeReact);\n }\n\n return async function APIPageWrapper({ document, ...props }) {\n let processed: ProcessedDocument;\n if (typeof document === 'string') {\n processed = await server.getSchema(document);\n } else {\n processed = await document;\n }\n\n const slugger = new Slugger();\n\n const ctx: RenderContext = {\n schema: processed,\n proxyUrl: server.options.proxyUrl,\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n slugger,\n async renderHeading(depth, text, props) {\n const id = slugger.slug(text);\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n generateTypeScriptDefinitions(schema, ctx) {\n const { generateTypeScriptSchema, generateTypeScriptDefinitions } = options;\n if (generateTypeScriptSchema && ctx._internal_legacy) {\n const { statusCode, contentType } = ctx._internal_legacy;\n return generateTypeScriptSchema(ctx.operation, statusCode, contentType, ctx);\n }\n\n return generateTypeScriptDefinitions?.(schema, ctx);\n },\n async renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n const out = await processor.process({\n value: text,\n });\n\n return out.result as ReactNode;\n },\n async renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n const rendered = await highlight(code, {\n lang,\n ...options.shikiOptions,\n config: options.shiki,\n components: {\n pre: Pre,\n },\n });\n\n return <CodeBlock className=\"my-0\">{rendered}</CodeBlock>;\n },\n };\n\n return <APIPage {...props} ctx={ctx} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmNA,SAAgB,cACd,QACA,SACkB;CAClB,IAAI;CAEJ,SAAS,0BAA0B;EACjC,SAAS,cAAuB;AAC9B,QAAK,YAAY,MAAW,SAAc;AACxC,WAAO,aAAa,MAAM;KACxB,aAAa;KACb,UAAU,KAAK;KAC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,WAAU;eATX,MAAM,UAAU,MAAM;MACrC;MACA,GAAG,QAAQ;MACX,QAAQ,QAAQ;MAChB,YAAY,EACV,KAAK,KACN;MACF,CAAC;MAEuD;;GAE5D;AAED,SAAO,oBAAC;GAAQ,GAAI;GAAY;IAAO"}
1
+ {"version":3,"file":"base.js","names":[],"sources":["../../src/ui/base.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport Slugger from 'github-slugger';\nimport type { Awaitable, DistributiveOmit, MethodInformation, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters, MediaAdapter } from '@/requests/media/adapter';\nimport type { FC, HTMLAttributes, ReactNode } from 'react';\nimport { highlight, type CoreHighlightOptions } from 'fumadocs-core/highlight/core';\nimport type { OpenAPIServer } from '@/server';\nimport type { APIPageClientOptions } from './client';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { createRehypeCode } from 'fumadocs-core/mdx-plugins/rehype-code.core';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';\nimport type { SchemaUIOptions } from './schema';\nimport type { ResponseTab } from './operation/response-tabs';\nimport type { ExampleRequestItem } from './operation/request-tabs';\nimport type { ResolvedShikiConfig } from 'fumadocs-core/highlight/config';\nimport { APIPage, type ApiPageProps, type OperationItem, type WebhookItem } from './api-page';\nimport type { CodeUsageGeneratorRegistry, InlineCodeUsageGenerator } from '@/requests/generators';\nimport type { JSONSchema } from 'json-schema-typed';\n\nexport interface GenerateTypeScriptDefinitionsContext extends RenderContext {\n operation: NoReference<MethodInformation>;\n readOnly: boolean;\n writeOnly: boolean;\n /** @deprecated */\n _internal_legacy?: {\n statusCode: string;\n contentType: string;\n };\n}\n\nexport interface CreateAPIPageOptions {\n /**\n * Generate TypeScript definitions from response schema.\n *\n * Pass `false` to disable it.\n *\n * @param method - the operation object\n * @param statusCode - status code\n * @deprecated use `generateTypeScriptDefinitions` instead.\n */\n generateTypeScriptSchema?:\n | ((\n method: NoReference<MethodInformation>,\n statusCode: string,\n contentType: string,\n ctx: RenderContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate TypeScript definitions from JSON schema.\n *\n * Pass `false` to disable it.\n */\n generateTypeScriptDefinitions?: (\n schema: JSONSchema,\n ctx: GenerateTypeScriptDefinitionsContext,\n ) => Awaitable<string | undefined>;\n\n /**\n * Generate example code usage for all endpoints.\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n\n /**\n * Generate example code usage for each endpoint.\n */\n generateCodeSamples?: (method: MethodInformation) => Awaitable<InlineCodeUsageGenerator[]>;\n\n shiki: ResolvedShikiConfig;\n renderMarkdown?: (md: string) => ReactNode;\n shikiOptions?: DistributiveOmit<CoreHighlightOptions, 'config' | 'lang' | 'components'>;\n\n /**\n * Show full response schema instead of only example response & Typescript definitions.\n *\n * @default true\n */\n showResponseSchema?: boolean;\n\n /**\n * Support other media types (for server-side generation).\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * Customise page content\n */\n content?: {\n renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => Awaitable<ReactNode>;\n\n renderRequestTabs?: (\n items: ExampleRequestItem[],\n ctx: RenderContext & {\n route: string;\n operation: NoReference<MethodInformation>;\n },\n ) => Awaitable<ReactNode>;\n\n renderAPIExampleLayout?: (\n slots: {\n selector: ReactNode;\n usageTabs: ReactNode;\n responseTabs: ReactNode;\n },\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n /**\n * @param generators - codegens for API example usages\n */\n renderAPIExampleUsageTabs?: (\n generators: CodeUsageGeneratorRegistry,\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n /**\n * renderer of the entire page's layout (containing all operations & webhooks UI)\n */\n renderPageLayout?: (\n slots: {\n operations?: {\n item: OperationItem;\n children: ReactNode;\n }[];\n webhooks?: {\n item: WebhookItem;\n children: ReactNode;\n }[];\n },\n ctx: RenderContext,\n ) => Awaitable<ReactNode>;\n\n renderOperationLayout?: (\n slots: {\n header: ReactNode;\n description: ReactNode;\n apiExample: ReactNode;\n apiPlayground: ReactNode;\n\n authSchemes: ReactNode;\n paremeters: ReactNode;\n body: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n },\n ctx: RenderContext,\n method: NoReference<MethodInformation>,\n ) => Awaitable<ReactNode>;\n\n renderWebhookLayout?: (slots: {\n header: ReactNode;\n description: ReactNode;\n authSchemes: ReactNode;\n paremeters: ReactNode;\n body: ReactNode;\n requests: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n }) => Awaitable<ReactNode>;\n };\n\n /**\n * Info UI for JSON schemas\n */\n schemaUI?: {\n render?: (options: SchemaUIOptions, ctx: RenderContext) => Awaitable<ReactNode>;\n\n /**\n * Show examples under the generated content of JSON schemas.\n *\n * @defaultValue false\n */\n showExample?: boolean;\n };\n\n /**\n * Customise API playground\n */\n playground?: {\n /**\n * @defaultValue true\n */\n enabled?: boolean;\n /**\n * replace the server-side renderer\n */\n render?: (props: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n }) => Awaitable<ReactNode>;\n };\n\n renderHeading?: (\n props: HTMLAttributes<HTMLHeadingElement>,\n depth: number,\n ) => Awaitable<ReactNode>;\n renderCodeBlock?: (props: { lang: string; code: string }) => Awaitable<ReactNode>;\n\n client?: APIPageClientOptions;\n}\n\nexport function createAPIPage(\n server: OpenAPIServer,\n options: CreateAPIPageOptions,\n): FC<ApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: defaultMdxComponents,\n });\n };\n }\n\n return remark()\n .use(remarkGfm)\n .use(remarkRehype)\n .use(createRehypeCode(options.shiki), {\n langs: [],\n lazy: true,\n })\n .use(rehypeReact);\n }\n\n return async function APIPageWrapper({ document, ...props }) {\n let processed: ProcessedDocument;\n if (typeof document === 'string') {\n processed = await server.getSchema(document);\n } else {\n processed = await document;\n }\n\n const slugger = new Slugger();\n\n const ctx: RenderContext = {\n schema: processed,\n proxyUrl: server.options.proxyUrl,\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n slugger,\n async renderHeading(depth, text, props) {\n const id = slugger.slug(text);\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n generateTypeScriptDefinitions(schema, ctx) {\n const { generateTypeScriptSchema, generateTypeScriptDefinitions } = options;\n if (generateTypeScriptSchema && ctx._internal_legacy) {\n const { statusCode, contentType } = ctx._internal_legacy;\n return generateTypeScriptSchema(ctx.operation, statusCode, contentType, ctx);\n }\n\n return generateTypeScriptDefinitions?.(schema, ctx);\n },\n async renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n const out = await processor.process({\n value: text,\n });\n\n return out.result as ReactNode;\n },\n async renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n const rendered = await highlight(code, {\n lang,\n ...options.shikiOptions,\n config: options.shiki,\n components: {\n pre: Pre,\n },\n });\n\n return <CodeBlock className=\"my-0\">{rendered}</CodeBlock>;\n },\n };\n\n return <APIPage {...props} ctx={ctx} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmNA,SAAgB,cACd,QACA,SACkB;CAClB,IAAI;CAEJ,SAAS,0BAA0B;EACjC,SAAS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AM,MAAM;AAChC,QAAI,QAAQ,gBACV,QAAO,QAAQ,gBAAgB;KAAE;KAAM;KAAM,CAAC;AAYhD,WAAO,oBAAC,WAAD;KAAW,WAAU;eATX,MAAM,UAAU,MAAM;MACrC;MACA,GAAG,QAAQ;MACX,QAAQ,QAAQ;MAChB,YAAY,EACV,KAAK,KACN;MACF,CAAC;KAEuD,CAAA;;GAE5D;AAED,SAAO,oBAAC,SAAD;GAAS,GAAI;GAAY;GAAO,CAAA"}
@@ -1,10 +1,9 @@
1
- 'use client';
2
-
1
+ "use client";
3
2
  //#region src/ui/client/index.tsx
4
3
  function defineClientConfig(options = {}) {
5
4
  return options;
6
5
  }
7
-
8
6
  //#endregion
9
7
  export { defineClientConfig };
8
+
10
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/ui/client/index.tsx"],"sourcesContent":["'use client';\nimport type { PlaygroundClientOptions } from '@/playground/client';\nimport type { MediaAdapter } from '@/requests/media/adapter';\nimport type { FC } from 'react';\nimport type { ExampleRequestItem } from '../operation/request-tabs';\nimport type { CodeUsageGeneratorRegistry } from '@/requests/generators';\n\nexport interface APIPageClientOptions {\n playground?: PlaygroundClientOptions;\n operation?: OperationClientOptions;\n\n /**\n * Set a prefix for `localStorage` keys.\n *\n * Useful when using multiple OpenAPI instances to prevent state conflicts.\n *\n * @defaultValue `fumadocs-openapi-`\n */\n storageKeyPrefix?: string;\n\n /**\n * Support other media types (for client-side serialization)\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * generate code usage examples\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n}\n\nexport interface OperationClientOptions {\n APIExampleSelector?: FC<{\n items: ExampleRequestItem[];\n\n value: string | undefined;\n onValueChange: (id: string) => void;\n }>;\n}\n\nexport function defineClientConfig(options: APIPageClientOptions = {}): APIPageClientOptions {\n return options;\n}\n"],"mappings":";;;AAwCA,SAAgB,mBAAmB,UAAgC,EAAE,EAAwB;AAC3F,QAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/ui/client/index.tsx"],"sourcesContent":["'use client';\nimport type { PlaygroundClientOptions } from '@/playground/client';\nimport type { MediaAdapter } from '@/requests/media/adapter';\nimport type { FC } from 'react';\nimport type { ExampleRequestItem } from '../operation/request-tabs';\nimport type { CodeUsageGeneratorRegistry } from '@/requests/generators';\n\nexport interface APIPageClientOptions {\n playground?: PlaygroundClientOptions;\n operation?: OperationClientOptions;\n\n /**\n * Set a prefix for `localStorage` keys.\n *\n * Useful when using multiple OpenAPI instances to prevent state conflicts.\n *\n * @defaultValue `fumadocs-openapi-`\n */\n storageKeyPrefix?: string;\n\n /**\n * Support other media types (for client-side serialization)\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * generate code usage examples\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n}\n\nexport interface OperationClientOptions {\n APIExampleSelector?: FC<{\n items: ExampleRequestItem[];\n\n value: string | undefined;\n onValueChange: (id: string) => void;\n }>;\n}\n\nexport function defineClientConfig(options: APIPageClientOptions = {}): APIPageClientOptions {\n return options;\n}\n"],"mappings":";;AAwCA,SAAgB,mBAAmB,UAAgC,EAAE,EAAwB;AAC3F,QAAO"}
@@ -1,6 +1,5 @@
1
1
  import { useApiContext } from "../contexts/api.js";
2
2
  import { useMemo } from "react";
3
-
4
3
  //#region src/ui/client/storage-key.ts
5
4
  function useStorageKey() {
6
5
  const { storageKeyPrefix } = useApiContext().client;
@@ -12,7 +11,7 @@ function useStorageKey() {
12
11
  function getStorageKey(prefix = "fumadocs-openapi-", name) {
13
12
  return prefix + name;
14
13
  }
15
-
16
14
  //#endregion
17
15
  export { useStorageKey };
16
+
18
17
  //# sourceMappingURL=storage-key.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-key.js","names":[],"sources":["../../../src/ui/client/storage-key.ts"],"sourcesContent":["import type { AuthField } from '@/playground/client';\nimport { useApiContext } from '../contexts/api';\nimport { useMemo } from 'react';\n\ntype KeyName = 'server-url' | `auth-${string}`;\n\nexport function useStorageKey() {\n const { storageKeyPrefix } = useApiContext().client;\n\n return useMemo(\n () => ({\n of: (name: KeyName) => getStorageKey(storageKeyPrefix, name),\n AuthField: (field: AuthField) =>\n getStorageKey(storageKeyPrefix, `auth-${field.original?.id ?? field.fieldName}`),\n }),\n [storageKeyPrefix],\n );\n}\n\nexport function getStorageKey(prefix = 'fumadocs-openapi-', name: KeyName) {\n return prefix + name;\n}\n"],"mappings":";;;;AAMA,SAAgB,gBAAgB;CAC9B,MAAM,EAAE,qBAAqB,eAAe,CAAC;AAE7C,QAAO,eACE;EACL,KAAK,SAAkB,cAAc,kBAAkB,KAAK;EAC5D,YAAY,UACV,cAAc,kBAAkB,QAAQ,MAAM,UAAU,MAAM,MAAM,YAAY;EACnF,GACD,CAAC,iBAAiB,CACnB;;AAGH,SAAgB,cAAc,SAAS,qBAAqB,MAAe;AACzE,QAAO,SAAS"}
1
+ {"version":3,"file":"storage-key.js","names":[],"sources":["../../../src/ui/client/storage-key.ts"],"sourcesContent":["import type { AuthField } from '@/playground/client';\nimport { useApiContext } from '../contexts/api';\nimport { useMemo } from 'react';\n\ntype KeyName = 'server-url' | `auth-${string}`;\n\nexport function useStorageKey() {\n const { storageKeyPrefix } = useApiContext().client;\n\n return useMemo(\n () => ({\n of: (name: KeyName) => getStorageKey(storageKeyPrefix, name),\n AuthField: (field: AuthField) =>\n getStorageKey(storageKeyPrefix, `auth-${field.original?.id ?? field.fieldName}`),\n }),\n [storageKeyPrefix],\n );\n}\n\nexport function getStorageKey(prefix = 'fumadocs-openapi-', name: KeyName) {\n return prefix + name;\n}\n"],"mappings":";;;AAMA,SAAgB,gBAAgB;CAC9B,MAAM,EAAE,qBAAqB,eAAe,CAAC;AAE7C,QAAO,eACE;EACL,KAAK,SAAkB,cAAc,kBAAkB,KAAK;EAC5D,YAAY,UACV,cAAc,kBAAkB,QAAQ,MAAM,UAAU,MAAM,MAAM,YAAY;EACnF,GACD,CAAC,iBAAiB,CACnB;;AAGH,SAAgB,cAAc,SAAS,qBAAqB,MAAe;AACzE,QAAO,SAAS"}
@@ -1,10 +1,8 @@
1
- 'use client';
2
-
1
+ "use client";
3
2
  import { cn } from "../../utils/cn.js";
4
3
  import { jsx, jsxs } from "react/jsx-runtime";
5
4
  import { ChevronRight } from "lucide-react";
6
5
  import * as Primitive from "@radix-ui/react-accordion";
7
-
8
6
  //#region src/ui/components/accordion.tsx
9
7
  function Accordions(props) {
10
8
  return /* @__PURE__ */ jsx(Primitive.Root, {
@@ -40,7 +38,7 @@ function AccordionTrigger(props) {
40
38
  children: [/* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 text-fd-muted-foreground shrink-0 transition-transform group-focus-visible/accordion:text-fd-primary group-data-[state=open]/accordion:rotate-90" }), props.children]
41
39
  });
42
40
  }
43
-
44
41
  //#endregion
45
42
  export { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions };
43
+
46
44
  //# sourceMappingURL=accordion.js.map