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.
- package/css/generated/shared.css +1 -0
- package/dist/generate-file.js +1 -2
- package/dist/generate-file.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/playground/client.d.ts +4 -3
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +2 -4
- package/dist/playground/client.js.map +1 -1
- package/dist/playground/components/inputs.js +2 -4
- package/dist/playground/components/inputs.js.map +1 -1
- package/dist/playground/components/oauth-dialog.js +1 -2
- package/dist/playground/components/oauth-dialog.js.map +1 -1
- package/dist/playground/components/server-select.js +2 -4
- package/dist/playground/components/server-select.js.map +1 -1
- package/dist/playground/fetcher.js +1 -2
- package/dist/playground/fetcher.js.map +1 -1
- package/dist/playground/index.d.ts +2 -7
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +23 -3
- package/dist/playground/index.js.map +1 -1
- package/dist/playground/lazy.js +2 -4
- package/dist/playground/lazy.js.map +1 -1
- package/dist/playground/schema.js +1 -2
- package/dist/playground/schema.js.map +1 -1
- package/dist/playground/status-info.js +1 -2
- package/dist/playground/status-info.js.map +1 -1
- package/dist/requests/generators/all.js +1 -2
- package/dist/requests/generators/all.js.map +1 -1
- package/dist/requests/generators/csharp.js +1 -2
- package/dist/requests/generators/csharp.js.map +1 -1
- package/dist/requests/generators/curl.js +1 -2
- package/dist/requests/generators/curl.js.map +1 -1
- package/dist/requests/generators/go.js +1 -2
- package/dist/requests/generators/go.js.map +1 -1
- package/dist/requests/generators/index.js +1 -1
- package/dist/requests/generators/java.js +1 -2
- package/dist/requests/generators/java.js.map +1 -1
- package/dist/requests/generators/javascript.js +1 -2
- package/dist/requests/generators/javascript.js.map +1 -1
- package/dist/requests/generators/python.js +1 -2
- package/dist/requests/generators/python.js.map +1 -1
- package/dist/requests/media/adapter.js +2 -3
- package/dist/requests/media/adapter.js.map +1 -1
- package/dist/requests/media/encode.d.ts.map +1 -1
- package/dist/requests/media/encode.js +1 -2
- package/dist/requests/media/encode.js.map +1 -1
- package/dist/requests/media/resolve-adapter.js +1 -1
- package/dist/requests/media/resolve-adapter.js.map +1 -1
- package/dist/requests/string-utils.js +1 -2
- package/dist/requests/string-utils.js.map +1 -1
- package/dist/requests/to-python-object.js +1 -1
- package/dist/scalar/client.js +2 -4
- package/dist/scalar/client.js.map +1 -1
- package/dist/scalar/index.js +1 -2
- package/dist/scalar/index.js.map +1 -1
- package/dist/server/create.js +1 -2
- package/dist/server/create.js.map +1 -1
- package/dist/server/index.js +1 -2
- package/dist/server/proxy.js +1 -1
- package/dist/server/proxy.js.map +1 -1
- package/dist/server/source-api.js +1 -2
- package/dist/server/source-api.js.map +1 -1
- package/dist/ui/api-page.js +1 -2
- package/dist/ui/api-page.js.map +1 -1
- package/dist/ui/base.js +1 -2
- package/dist/ui/base.js.map +1 -1
- package/dist/ui/client/index.js +2 -3
- package/dist/ui/client/index.js.map +1 -1
- package/dist/ui/client/storage-key.js +1 -2
- package/dist/ui/client/storage-key.js.map +1 -1
- package/dist/ui/components/accordion.js +2 -4
- package/dist/ui/components/accordion.js.map +1 -1
- package/dist/ui/components/dialog.js +3 -5
- package/dist/ui/components/dialog.js.map +1 -1
- package/dist/ui/components/input.js +1 -2
- package/dist/ui/components/input.js.map +1 -1
- package/dist/ui/components/method-label.js +1 -2
- package/dist/ui/components/method-label.js.map +1 -1
- package/dist/ui/components/select.js +2 -3
- package/dist/ui/components/select.js.map +1 -1
- package/dist/ui/contexts/api.js +2 -4
- package/dist/ui/contexts/api.js.map +1 -1
- package/dist/ui/contexts/api.lazy.js +2 -4
- package/dist/ui/contexts/api.lazy.js.map +1 -1
- package/dist/ui/full.client.js +2 -4
- package/dist/ui/full.client.js.map +1 -1
- package/dist/ui/full.js +1 -2
- package/dist/ui/full.js.map +1 -1
- package/dist/ui/index.js +1 -2
- package/dist/ui/operation/client.js +2 -4
- package/dist/ui/operation/client.js.map +1 -1
- package/dist/ui/operation/index.js +1 -2
- package/dist/ui/operation/index.js.map +1 -1
- package/dist/ui/operation/request-tabs.js +1 -2
- package/dist/ui/operation/request-tabs.js.map +1 -1
- package/dist/ui/operation/response-tabs.js +1 -2
- package/dist/ui/operation/response-tabs.js.map +1 -1
- package/dist/ui/operation/usage-tabs/client.js +4 -7
- package/dist/ui/operation/usage-tabs/client.js.map +1 -1
- package/dist/ui/operation/usage-tabs/index.js +1 -2
- package/dist/ui/operation/usage-tabs/index.js.map +1 -1
- package/dist/ui/operation/usage-tabs/lazy.js +2 -4
- package/dist/ui/operation/usage-tabs/lazy.js.map +1 -1
- package/dist/ui/schema/client.js +2 -4
- package/dist/ui/schema/client.js.map +1 -1
- package/dist/ui/schema/index.js +1 -2
- package/dist/ui/schema/index.js.map +1 -1
- package/dist/ui/schema/lazy.js +2 -4
- package/dist/ui/schema/lazy.js.map +1 -1
- package/dist/utils/cn.js +1 -2
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/id-to-title.js +1 -1
- package/dist/utils/lazy.js +1 -2
- package/dist/utils/lazy.js.map +1 -1
- package/dist/utils/merge-schema.js +1 -2
- package/dist/utils/merge-schema.js.map +1 -1
- package/dist/utils/pages/builder.js +1 -2
- package/dist/utils/pages/builder.js.map +1 -1
- package/dist/utils/pages/preset-auto.js +1 -2
- package/dist/utils/pages/preset-auto.js.map +1 -1
- package/dist/utils/pages/to-body.js +1 -1
- package/dist/utils/pages/to-static-data.js +1 -2
- package/dist/utils/pages/to-static-data.js.map +1 -1
- package/dist/utils/pages/to-text.js +1 -2
- package/dist/utils/pages/to-text.js.map +1 -1
- package/dist/utils/process-document.js +3 -5
- package/dist/utils/process-document.js.map +1 -1
- package/dist/utils/remove-undefined.js +1 -1
- package/dist/utils/remove-undefined.js.map +1 -1
- package/dist/utils/schema-to-string.js +1 -1
- package/dist/utils/schema-to-string.js.map +1 -1
- package/dist/utils/schema.js +1 -2
- package/dist/utils/schema.js.map +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/use-query.js +1 -2
- package/dist/utils/use-query.js.map +1 -1
- package/package.json +8 -8
- package/dist/_virtual/_rolldown/runtime.js +0 -5
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js +0 -43
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js +0 -29
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js +0 -42
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js +0 -46
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/types.js +0 -12
- 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":"server-select.js","names":[],"sources":["../../../src/playground/components/server-select.tsx"],"sourcesContent":["'use client';\nimport { useServerContext, useServerSelectContext } from '@/ui/contexts/api';\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@/ui/components/select';\nimport { Input, labelVariants } from '@/ui/components/input';\nimport { useEffect, useState, useRef, type ComponentProps } from 'react';\nimport { cn } from '@/utils/cn';\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from '@/ui/components/dialog';\nimport { resolveServerUrl, withBase } from '@/utils/url';\nimport type { ServerVariableObject } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport { StfProvider, useFieldValue, useListener, useStf } from '@fumari/stf';\nimport { EditIcon } from 'lucide-react';\n\nexport default function ServerSelect(props: ComponentProps<typeof DialogTrigger>) {\n const { servers } = useServerContext();\n const { server, setServer, setServerVariables } = useServerSelectContext();\n const [open, setOpen] = useState(false);\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n if (servers.length <= 0) return;\n const serverSchema = server ? servers.find((obj) => obj.url === server.url) : null;\n\n return (\n <Dialog open={open} onOpenChange={setOpen}>\n <DialogTrigger\n {...props}\n className={cn(\n 'flex items-center gap-2 text-sm text-start px-3 py-2 bg-fd-muted text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground',\n props.className,\n )}\n >\n <span className=\"px-2 py-0.5 -ms-2 font-medium rounded-lg border bg-fd-secondary text-fd-secondary-foreground shadow-sm\">\n {server?.name ?? 'Server URL'}\n </span>\n <code className=\"truncate min-w-0 flex-1\">\n {isMounted\n ? withBase(\n server ? resolveServerUrl(server.url, server.variables) : '/',\n window.location.origin,\n )\n : 'loading...'}\n </code>\n <EditIcon className=\"size-4\" />\n </DialogTrigger>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>Server URL</DialogTitle>\n <DialogDescription>The base URL of your API endpoint.</DialogDescription>\n </DialogHeader>\n <Select value={server?.url} onValueChange={setServer}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {servers.map((item) => (\n <SelectItem key={item.url} value={item.url!}>\n <code className=\"text-[0.8125rem]\">{item.url}</code>\n <p className=\"text-fd-muted-foreground\">{item.description}</p>\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n {server?.variables && serverSchema?.variables && (\n <ServerSelectContent\n key={server.url}\n defaultValues={server.variables}\n schema={serverSchema.variables}\n onChange={setServerVariables}\n />\n )}\n </DialogContent>\n </Dialog>\n );\n}\n\nfunction ServerSelectContent({\n defaultValues,\n onChange,\n schema,\n}: {\n defaultValues: Record<string, string>;\n onChange: (values: Record<string, string>) => void;\n schema: Record<string, NoReference<ServerVariableObject>>;\n}) {\n const stf = useStf({\n defaultValues: () => structuredClone(defaultValues),\n });\n const timerRef = useRef<number | null>(null);\n useListener({\n stf,\n onUpdate() {\n if (timerRef.current !== null) window.clearTimeout(timerRef.current);\n\n timerRef.current = window.setTimeout(\n () => onChange(stf.dataEngine.getData() as Record<string, string>),\n 500,\n );\n },\n });\n\n return (\n <StfProvider value={stf}>\n <div className=\"flex flex-col gap-4\">\n {Object.entries(schema).map(([key, variable]) => {\n return (\n <fieldset key={key} className=\"flex flex-col gap-1\">\n <label className={cn(labelVariants())} htmlFor={key}>\n {key}\n </label>\n <p className=\"text-xs text-fd-muted-foreground empty:hidden\">\n {variable.description}\n </p>\n <Field fieldName={key} variable={variable} />\n </fieldset>\n );\n })}\n </div>\n </StfProvider>\n );\n}\n\nfunction Field({\n fieldName,\n variable,\n}: {\n variable: NoReference<ServerVariableObject>;\n fieldName: string;\n}) {\n const [value, setValue] = useFieldValue([fieldName], {\n compute(currentValue) {\n return typeof currentValue === 'string' ? currentValue : undefined;\n },\n });\n\n if (variable.enum) {\n return (\n <Select value={value} onValueChange={setValue}>\n <SelectTrigger id={fieldName}>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {variable.enum.map((value) => (\n <SelectItem key={value} value={String(value)}>\n {value}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n );\n }\n\n return (\n <Input\n id={fieldName}\n value={value}\n onChange={(e) => setValue(e.target.value)}\n placeholder=\"Enter Value\"\n />\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-select.js","names":[],"sources":["../../../src/playground/components/server-select.tsx"],"sourcesContent":["'use client';\nimport { useServerContext, useServerSelectContext } from '@/ui/contexts/api';\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@/ui/components/select';\nimport { Input, labelVariants } from '@/ui/components/input';\nimport { useEffect, useState, useRef, type ComponentProps } from 'react';\nimport { cn } from '@/utils/cn';\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from '@/ui/components/dialog';\nimport { resolveServerUrl, withBase } from '@/utils/url';\nimport type { ServerVariableObject } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport { StfProvider, useFieldValue, useListener, useStf } from '@fumari/stf';\nimport { EditIcon } from 'lucide-react';\n\nexport default function ServerSelect(props: ComponentProps<typeof DialogTrigger>) {\n const { servers } = useServerContext();\n const { server, setServer, setServerVariables } = useServerSelectContext();\n const [open, setOpen] = useState(false);\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n if (servers.length <= 0) return;\n const serverSchema = server ? servers.find((obj) => obj.url === server.url) : null;\n\n return (\n <Dialog open={open} onOpenChange={setOpen}>\n <DialogTrigger\n {...props}\n className={cn(\n 'flex items-center gap-2 text-sm text-start px-3 py-2 bg-fd-muted text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground',\n props.className,\n )}\n >\n <span className=\"px-2 py-0.5 -ms-2 font-medium rounded-lg border bg-fd-secondary text-fd-secondary-foreground shadow-sm\">\n {server?.name ?? 'Server URL'}\n </span>\n <code className=\"truncate min-w-0 flex-1\">\n {isMounted\n ? withBase(\n server ? resolveServerUrl(server.url, server.variables) : '/',\n window.location.origin,\n )\n : 'loading...'}\n </code>\n <EditIcon className=\"size-4\" />\n </DialogTrigger>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>Server URL</DialogTitle>\n <DialogDescription>The base URL of your API endpoint.</DialogDescription>\n </DialogHeader>\n <Select value={server?.url} onValueChange={setServer}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {servers.map((item) => (\n <SelectItem key={item.url} value={item.url!}>\n <code className=\"text-[0.8125rem]\">{item.url}</code>\n <p className=\"text-fd-muted-foreground\">{item.description}</p>\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n {server?.variables && serverSchema?.variables && (\n <ServerSelectContent\n key={server.url}\n defaultValues={server.variables}\n schema={serverSchema.variables}\n onChange={setServerVariables}\n />\n )}\n </DialogContent>\n </Dialog>\n );\n}\n\nfunction ServerSelectContent({\n defaultValues,\n onChange,\n schema,\n}: {\n defaultValues: Record<string, string>;\n onChange: (values: Record<string, string>) => void;\n schema: Record<string, NoReference<ServerVariableObject>>;\n}) {\n const stf = useStf({\n defaultValues: () => structuredClone(defaultValues),\n });\n const timerRef = useRef<number | null>(null);\n useListener({\n stf,\n onUpdate() {\n if (timerRef.current !== null) window.clearTimeout(timerRef.current);\n\n timerRef.current = window.setTimeout(\n () => onChange(stf.dataEngine.getData() as Record<string, string>),\n 500,\n );\n },\n });\n\n return (\n <StfProvider value={stf}>\n <div className=\"flex flex-col gap-4\">\n {Object.entries(schema).map(([key, variable]) => {\n return (\n <fieldset key={key} className=\"flex flex-col gap-1\">\n <label className={cn(labelVariants())} htmlFor={key}>\n {key}\n </label>\n <p className=\"text-xs text-fd-muted-foreground empty:hidden\">\n {variable.description}\n </p>\n <Field fieldName={key} variable={variable} />\n </fieldset>\n );\n })}\n </div>\n </StfProvider>\n );\n}\n\nfunction Field({\n fieldName,\n variable,\n}: {\n variable: NoReference<ServerVariableObject>;\n fieldName: string;\n}) {\n const [value, setValue] = useFieldValue([fieldName], {\n compute(currentValue) {\n return typeof currentValue === 'string' ? currentValue : undefined;\n },\n });\n\n if (variable.enum) {\n return (\n <Select value={value} onValueChange={setValue}>\n <SelectTrigger id={fieldName}>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {variable.enum.map((value) => (\n <SelectItem key={value} value={String(value)}>\n {value}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n );\n }\n\n return (\n <Input\n id={fieldName}\n value={value}\n onChange={(e) => setValue(e.target.value)}\n placeholder=\"Enter Value\"\n />\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,UACG,SAAS,KAAK,KAAK,UAClB,oBAAC,YAAD;GAAwB,OAAO,OAAO,MAAM;aACzC;GACU,EAFI,MAEJ,CACb,EACY,CAAA,CACT;;AAIb,QACE,oBAAC,OAAD;EACE,IAAI;EACG;EACP,WAAW,MAAM,SAAS,EAAE,OAAO,MAAM;EACzC,aAAY;EACZ,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { resolveMediaAdapter } from "../requests/media/resolve-adapter.js";
|
|
2
2
|
import "../requests/media/adapter.js";
|
|
3
|
-
|
|
4
3
|
//#region src/playground/fetcher.ts
|
|
5
4
|
function createBrowserFetcher(adapters, requestTimeout) {
|
|
6
5
|
return { async fetch(url, options) {
|
|
@@ -62,7 +61,7 @@ function createBrowserFetcher(adapters, requestTimeout) {
|
|
|
62
61
|
});
|
|
63
62
|
} };
|
|
64
63
|
}
|
|
65
|
-
|
|
66
64
|
//#endregion
|
|
67
65
|
export { createBrowserFetcher };
|
|
66
|
+
|
|
68
67
|
//# sourceMappingURL=fetcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.js","names":[],"sources":["../../src/playground/fetcher.ts"],"sourcesContent":["import type { RequestData } from '@/requests/types';\nimport type { MediaAdapter } from '@/requests/media/adapter';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport interface FetchOptions extends RequestData {\n proxyUrl?: string;\n}\n\nexport interface FetchResult {\n status: number;\n type: 'json' | 'html' | 'text';\n data: unknown;\n}\n\nexport interface Fetcher {\n /**\n * This method will not apply the path & search parameters from `options` to given `url`.\n *\n * @param url - The full URL of request.\n */\n fetch: (url: string, options: FetchOptions) => Promise<FetchResult>;\n}\n\nexport function createBrowserFetcher(\n adapters: Record<string, MediaAdapter>,\n requestTimeout: number,\n): Fetcher {\n return {\n async fetch(url, options) {\n const headers = new Headers();\n if (options.bodyMediaType && options.bodyMediaType !== 'multipart/form-data')\n headers.append('Content-Type', options.bodyMediaType);\n\n for (const key in options.header) {\n const param = options.header[key];\n headers.append(key, param.value);\n }\n\n const proxyUrl = options.proxyUrl ? new URL(options.proxyUrl, document.baseURI) : null;\n\n if (proxyUrl) {\n proxyUrl.searchParams.append('url', url);\n url = proxyUrl.toString();\n }\n\n let body: BodyInit | undefined = undefined;\n if (options.bodyMediaType && options.body) {\n const adapter = resolveMediaAdapter(options.bodyMediaType, adapters);\n if (!adapter)\n return {\n status: 400,\n type: 'text',\n data: `[Fumadocs] No adapter for ${options.bodyMediaType}, you need to specify one from 'createOpenAPI()'.`,\n };\n\n body = adapter.encode(options as { body: unknown });\n }\n\n // cookies\n for (const key in options.cookie) {\n const param = options.cookie[key];\n const segs: string[] = [`${key}=${param.value}`];\n\n if (proxyUrl && proxyUrl.origin !== window.location.origin)\n segs.push(`domain=${proxyUrl.host}`);\n segs.push('path=/', 'max-age=30');\n\n document.cookie = segs.join('; ');\n }\n\n return fetch(url, {\n method: options.method,\n cache: 'no-cache',\n headers,\n body,\n signal: AbortSignal.timeout(requestTimeout * 1000),\n })\n .then(async (res) => {\n const contentType = res.headers.get('Content-Type') ?? '';\n let type: FetchResult['type'];\n let data: unknown;\n\n if (contentType.startsWith('application/json')) {\n type = 'json';\n data = await res.json();\n } else {\n type = contentType.startsWith('text/html') ? 'html' : 'text';\n data = await res.text();\n }\n\n return { status: res.status, type, data };\n })\n .catch((e) => {\n const message = e instanceof Error ? `[${e.name}] ${e.message}` : e.toString();\n\n return {\n status: 400,\n type: 'text',\n data: `Client side error: ${message}`,\n };\n });\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetcher.js","names":[],"sources":["../../src/playground/fetcher.ts"],"sourcesContent":["import type { RequestData } from '@/requests/types';\nimport type { MediaAdapter } from '@/requests/media/adapter';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport interface FetchOptions extends RequestData {\n proxyUrl?: string;\n}\n\nexport interface FetchResult {\n status: number;\n type: 'json' | 'html' | 'text';\n data: unknown;\n}\n\nexport interface Fetcher {\n /**\n * This method will not apply the path & search parameters from `options` to given `url`.\n *\n * @param url - The full URL of request.\n */\n fetch: (url: string, options: FetchOptions) => Promise<FetchResult>;\n}\n\nexport function createBrowserFetcher(\n adapters: Record<string, MediaAdapter>,\n requestTimeout: number,\n): Fetcher {\n return {\n async fetch(url, options) {\n const headers = new Headers();\n if (options.bodyMediaType && options.bodyMediaType !== 'multipart/form-data')\n headers.append('Content-Type', options.bodyMediaType);\n\n for (const key in options.header) {\n const param = options.header[key];\n headers.append(key, param.value);\n }\n\n const proxyUrl = options.proxyUrl ? new URL(options.proxyUrl, document.baseURI) : null;\n\n if (proxyUrl) {\n proxyUrl.searchParams.append('url', url);\n url = proxyUrl.toString();\n }\n\n let body: BodyInit | undefined = undefined;\n if (options.bodyMediaType && options.body) {\n const adapter = resolveMediaAdapter(options.bodyMediaType, adapters);\n if (!adapter)\n return {\n status: 400,\n type: 'text',\n data: `[Fumadocs] No adapter for ${options.bodyMediaType}, you need to specify one from 'createOpenAPI()'.`,\n };\n\n body = adapter.encode(options as { body: unknown });\n }\n\n // cookies\n for (const key in options.cookie) {\n const param = options.cookie[key];\n const segs: string[] = [`${key}=${param.value}`];\n\n if (proxyUrl && proxyUrl.origin !== window.location.origin)\n segs.push(`domain=${proxyUrl.host}`);\n segs.push('path=/', 'max-age=30');\n\n document.cookie = segs.join('; ');\n }\n\n return fetch(url, {\n method: options.method,\n cache: 'no-cache',\n headers,\n body,\n signal: AbortSignal.timeout(requestTimeout * 1000),\n })\n .then(async (res) => {\n const contentType = res.headers.get('Content-Type') ?? '';\n let type: FetchResult['type'];\n let data: unknown;\n\n if (contentType.startsWith('application/json')) {\n type = 'json';\n data = await res.json();\n } else {\n type = contentType.startsWith('text/html') ? 'html' : 'text';\n data = await res.text();\n }\n\n return { status: res.status, type, data };\n })\n .catch((e) => {\n const message = e instanceof Error ? `[${e.name}] ${e.message}` : e.toString();\n\n return {\n status: 400,\n type: 'text',\n data: `Client side error: ${message}`,\n };\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AE;AAC9C,WAAO;AACP,WAAO,MAAM,IAAI,MAAM;UAClB;AACL,WAAO,YAAY,WAAW,YAAY,GAAG,SAAS;AACtD,WAAO,MAAM,IAAI,MAAM;;AAGzB,UAAO;IAAE,QAAQ,IAAI;IAAQ;IAAM;IAAM;IACzC,CACD,OAAO,MAAM;AAGZ,UAAO;IACL,QAAQ;IACR,MAAM;IACN,MAAM,sBALQ,aAAa,QAAQ,IAAI,EAAE,KAAK,IAAI,EAAE,YAAY,EAAE,UAAU;IAM7E;IACD;IAEP"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MethodInformation, ParameterObject, RenderContext, SecuritySchemeObject } from "../types.js";
|
|
1
|
+
import { MethodInformation, RenderContext, SecuritySchemeObject } from "../types.js";
|
|
3
2
|
import * as react from "react";
|
|
4
3
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
4
|
|
|
6
5
|
//#region src/playground/index.d.ts
|
|
7
|
-
type ParameterField = NoReference<ParameterObject> & {
|
|
8
|
-
schema: ParsedSchema;
|
|
9
|
-
in: 'cookie' | 'header' | 'query' | 'path';
|
|
10
|
-
};
|
|
11
6
|
interface APIPlaygroundProps {
|
|
12
7
|
path: string;
|
|
13
8
|
method: MethodInformation;
|
|
@@ -23,5 +18,5 @@ declare function APIPlayground({
|
|
|
23
18
|
ctx
|
|
24
19
|
}: APIPlaygroundProps): Promise<string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<react.ReactNode> | null | undefined>;
|
|
25
20
|
//#endregion
|
|
26
|
-
export { APIPlayground, APIPlaygroundProps,
|
|
21
|
+
export { APIPlayground, APIPlaygroundProps, SecurityEntry };
|
|
27
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/playground/index.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/playground/index.tsx"],"mappings":";;;;;UAiBiB,kBAAA;EACf,IAAA;EACA,MAAA,EAAQ,iBAAA;EACR,GAAA,EAAK,aAAA;AAAA;AAAA,KAGK,aAAA,GAAgB,oBAAA;EAC1B,MAAA;EACA,EAAA;AAAA;AAAA,iBAGoB,aAAA,CAAA;EAAgB,IAAA;EAAM,MAAA;EAAQ;AAAA,GAAO,kBAAA,GAAkB,OAAA,sCAAA,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAA,QAAA,CAAA,KAAA,CAAA,SAAA"}
|
package/dist/playground/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getPreferredType } from "../utils/schema.js";
|
|
2
2
|
import { ClientLazy } from "./lazy.js";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
4
|
//#region src/playground/index.tsx
|
|
6
5
|
async function APIPlayground({ path, method, ctx }) {
|
|
7
6
|
if (ctx.playground?.render) return ctx.playground.render({
|
|
@@ -30,7 +29,28 @@ async function APIPlayground({ path, method, ctx }) {
|
|
|
30
29
|
securities: parseSecurities(method, ctx),
|
|
31
30
|
method: method.method,
|
|
32
31
|
route: path,
|
|
33
|
-
parameters: method.parameters
|
|
32
|
+
parameters: method.parameters?.map((param) => {
|
|
33
|
+
if (param.schema !== void 0) return {
|
|
34
|
+
...param,
|
|
35
|
+
schema: writeReferences(param.schema, context)
|
|
36
|
+
};
|
|
37
|
+
if (param.content !== void 0) {
|
|
38
|
+
const content = {};
|
|
39
|
+
for (const k in param.content) {
|
|
40
|
+
const original = param.content[k];
|
|
41
|
+
if (!original || original.schema === void 0) continue;
|
|
42
|
+
content[k] = {
|
|
43
|
+
...original,
|
|
44
|
+
schema: writeReferences(original.schema, context)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
...param,
|
|
49
|
+
content
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return param;
|
|
53
|
+
}),
|
|
34
54
|
body: bodyContent && mediaType ? {
|
|
35
55
|
schema: writeReferences(bodyContent[mediaType].schema, context),
|
|
36
56
|
mediaType
|
|
@@ -92,7 +112,7 @@ function parseSecurities(method, { schema: { dereferenced } }) {
|
|
|
92
112
|
}
|
|
93
113
|
return result;
|
|
94
114
|
}
|
|
95
|
-
|
|
96
115
|
//#endregion
|
|
97
116
|
export { APIPlayground };
|
|
117
|
+
|
|
98
118
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/playground/index.tsx"],"sourcesContent":["import type {\n MethodInformation,\n ParameterObject,\n RenderContext,\n SecuritySchemeObject,\n} from '@/types';\nimport { getPreferredType,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/playground/index.tsx"],"sourcesContent":["import type {\n MediaTypeObject,\n MethodInformation,\n ParameterObject,\n RenderContext,\n SecuritySchemeObject,\n} from '@/types';\nimport { getPreferredType, NoReference, type ParsedSchema } from '@/utils/schema';\nimport { type PlaygroundClientProps } from './client';\nimport { ClientLazy } from './lazy';\n\ninterface Context {\n references: Record<string, ParsedSchema>;\n registered: WeakMap<Exclude<ParsedSchema, boolean>, string>;\n id: (schema?: object) => string;\n}\n\nexport interface APIPlaygroundProps {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n}\n\nexport type SecurityEntry = SecuritySchemeObject & {\n scopes: string[];\n id: string;\n};\n\nexport async function APIPlayground({ path, method, ctx }: APIPlaygroundProps) {\n if (ctx.playground?.render) {\n return ctx.playground.render({ path, method, ctx });\n }\n\n const bodyContent = method.requestBody?.content;\n const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;\n const takenIds = new Map<string, number>();\n\n const context: Context = {\n references: {},\n id(schema) {\n let name = 'r';\n if (schema) {\n const ref = ctx.schema.getRawRef(schema)?.split('/');\n if (ref && ref.length > 0) name = ref[ref.length - 1];\n }\n\n const count = takenIds.get(name) ?? 0;\n takenIds.set(name, count + 1);\n return count === 0 ? name : `${name}${count}`;\n },\n registered: new WeakMap(),\n };\n\n const props: PlaygroundClientProps = {\n securities: parseSecurities(method, ctx),\n method: method.method,\n route: path,\n parameters: method.parameters?.map((param: NoReference<ParameterObject>): ParameterObject => {\n if (param.schema !== undefined) {\n return {\n ...param,\n schema: writeReferences(param.schema, context),\n } as ParameterObject;\n }\n\n if (param.content !== undefined) {\n const content: Record<string, MediaTypeObject> = {};\n\n for (const k in param.content) {\n const original = param.content[k] as NoReference<MediaTypeObject>;\n if (!original || original.schema === undefined) continue;\n\n content[k] = {\n ...original,\n schema: writeReferences(original.schema, context),\n } as MediaTypeObject;\n }\n\n return {\n ...param,\n content,\n } as ParameterObject;\n }\n\n return param;\n }),\n body:\n bodyContent && mediaType\n ? ({\n schema: writeReferences(bodyContent[mediaType].schema as ParsedSchema, context),\n mediaType,\n } as PlaygroundClientProps['body'])\n : undefined,\n references: context.references,\n proxyUrl: ctx.proxyUrl,\n writeOnly: true,\n readOnly: false,\n };\n\n return <ClientLazy {...props} />;\n}\n\nfunction writeReferences(\n schema: ParsedSchema,\n ctx: Context,\n stack: WeakMap<object, object> = new WeakMap(),\n): ParsedSchema {\n if (typeof schema !== 'object' || !schema) return schema;\n if (stack.has(schema)) {\n const out = stack.get(schema)!;\n const id = ctx.id(schema);\n ctx.references[id] = out;\n\n return {\n $ref: `#/${id}`,\n };\n }\n\n const output = { ...schema };\n stack.set(schema, output);\n for (const _n in output) {\n const name = _n as keyof typeof output;\n if (!output[name]) continue;\n\n switch (name) {\n case 'oneOf':\n case 'allOf':\n case 'anyOf':\n output[name] = output[name].map((item) => writeReferences(item, ctx, stack));\n continue;\n case 'items':\n case 'additionalProperties':\n case 'not':\n output[name] = writeReferences(output[name], ctx, stack);\n continue;\n case 'properties':\n case 'patternProperties':\n output[name] = { ...output[name] };\n\n for (const key in output[name]) {\n output[name][key] = writeReferences(output[name][key], ctx, stack);\n }\n }\n }\n\n return output;\n}\n\nfunction parseSecurities(\n method: MethodInformation,\n { schema: { dereferenced } }: RenderContext,\n): PlaygroundClientProps['securities'] {\n const result: PlaygroundClientProps['securities'] = [];\n const security = method.security ?? dereferenced.security ?? [];\n if (security.length === 0) return result;\n\n for (const map of security) {\n const list: PlaygroundClientProps['securities'][number] = [];\n\n for (const [key, scopes] of Object.entries(map)) {\n const scheme = dereferenced.components?.securitySchemes?.[key];\n if (!scheme) continue;\n\n list.push({\n ...scheme,\n scopes,\n id: key,\n });\n }\n\n if (list.length > 0) result.push(list);\n }\n\n return result;\n}\n"],"mappings":";;;;AA4BA,eAAsB,cAAc,EAAE,MAAM,QAAQ,OAA2B;AAC7E,KAAI,IAAI,YAAY,OAClB,QAAO,IAAI,WAAW,OAAO;EAAE;EAAM;EAAQ;EAAK,CAAC;CAGrD,MAAM,cAAc,OAAO,aAAa;CACxC,MAAM,YAAY,cAAc,iBAAiB,YAAY,GAAG,KAAA;CAChE,MAAM,2BAAW,IAAI,KAAqB;CAE1C,MAAM,UAAmB;EACvB,YAAY,EAAE;EACd,GAAG,QAAQ;GACT,IAAI,OAAO;AACX,OAAI,QAAQ;IACV,MAAM,MAAM,IAAI,OAAO,UAAU,OAAO,EAAE,MAAM,IAAI;AACpD,QAAI,OAAO,IAAI,SAAS,EAAG,QAAO,IAAI,IAAI,SAAS;;GAGrD,MAAM,QAAQ,SAAS,IAAI,KAAK,IAAI;AACpC,YAAS,IAAI,MAAM,QAAQ,EAAE;AAC7B,UAAO,UAAU,IAAI,OAAO,GAAG,OAAO;;EAExC,4BAAY,IAAI,SAAS;EAC1B;AAgDD,QAAO,oBAAC,YAAD;EA7CL,YAAY,gBAAgB,QAAQ,IAAI;EACxC,QAAQ,OAAO;EACf,OAAO;EACP,YAAY,OAAO,YAAY,KAAK,UAAyD;AAC3F,OAAI,MAAM,WAAW,KAAA,EACnB,QAAO;IACL,GAAG;IACH,QAAQ,gBAAgB,MAAM,QAAQ,QAAQ;IAC/C;AAGH,OAAI,MAAM,YAAY,KAAA,GAAW;IAC/B,MAAM,UAA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QAAO;;AAGT,SAAS,gBACP,QACA,EAAE,QAAQ,EAAE,kBACyB;CACrC,MAAM,SAA8C,EAAE;CACtD,MAAM,WAAW,OAAO,YAAY,aAAa,YAAY,EAAE;AAC/D,KAAI,SAAS,WAAW,EAAG,QAAO;AAElC,MAAK,MAAM,OAAO,UAAU;EAC1B,MAAM,OAAoD,EAAE;AAE5D,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,EAAE;GAC/C,MAAM,SAAS,aAAa,YAAY,kBAAkB;AAC1D,OAAI,CAAC,OAAQ;AAEb,QAAK,KAAK;IACR,GAAG;IACH;IACA,IAAI;IACL,CAAC;;AAGJ,MAAI,KAAK,SAAS,EAAG,QAAO,KAAK,KAAK;;AAGxC,QAAO"}
|
package/dist/playground/lazy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","names":[],"sources":["../../src/playground/lazy.ts"],"sourcesContent":["'use client';\nimport { wrapLazy } from '../utils/lazy';\n\nexport const ClientLazy = wrapLazy(() => import('./client'));\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"lazy.js","names":[],"sources":["../../src/playground/lazy.ts"],"sourcesContent":["'use client';\nimport { wrapLazy } from '../utils/lazy';\n\nexport const ClientLazy = wrapLazy(() => import('./client'));\n"],"mappings":";;;AAGA,MAAa,aAAa,eAAe,OAAO,eAAY"}
|
|
@@ -6,7 +6,6 @@ import { Ajv2020 } from "ajv/dist/2020";
|
|
|
6
6
|
import { useDataEngine, useFieldValue, useNamespace } from "@fumari/stf";
|
|
7
7
|
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
8
8
|
import { sample } from "openapi-sampler";
|
|
9
|
-
|
|
10
9
|
//#region src/playground/schema.tsx
|
|
11
10
|
const SchemaContext = createContext(void 0);
|
|
12
11
|
const anyFields = {
|
|
@@ -152,7 +151,7 @@ function getUnion(schema) {
|
|
|
152
151
|
if (schema.anyOf) return [schema.anyOf, "anyOf"];
|
|
153
152
|
if (schema.oneOf) return [schema.oneOf, "oneOf"];
|
|
154
153
|
}
|
|
155
|
-
|
|
156
154
|
//#endregion
|
|
157
155
|
export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaScope, useSchemaUtils };
|
|
156
|
+
|
|
158
157
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/playground/schema.tsx"],"sourcesContent":["import { Ajv2020 } from 'ajv/dist/2020';\nimport { createContext, ReactNode, use, useMemo } from 'react';\nimport type { ParsedSchema, ResolvedSchema } from '@/utils/schema';\nimport { mergeAllOf } from '@/utils/merge-schema';\nimport { FieldKey, useDataEngine, useFieldValue, useNamespace } from '@fumari/stf';\nimport { stringifyFieldKey } from '@fumari/stf/lib/utils';\nimport { sample } from 'openapi-sampler';\nimport { FormatFlags, schemaToString } from '@/utils/schema-to-string';\n\ninterface SchemaContextType extends SchemaScope {\n references: Record<string, ParsedSchema>;\n ajv: Ajv2020;\n}\n\nexport interface SchemaScope {\n /**\n * show write only fields\n */\n writeOnly: boolean;\n\n /**\n * show read only fields\n */\n readOnly: boolean;\n}\n\ntype UnionField = 'anyOf' | 'oneOf';\n\nexport interface FieldInfo {\n selectedType?: string;\n oneOf: number;\n\n /**\n * The actual field that represents union members.\n */\n unionField?: UnionField;\n}\n\nconst SchemaContext = createContext<SchemaContextType | undefined>(undefined);\nexport const anyFields = {\n type: ['string', 'number', 'boolean', 'array', 'object'],\n items: true,\n additionalProperties: true,\n} satisfies ParsedSchema;\n\nexport function SchemaProvider({\n references,\n readOnly,\n writeOnly,\n children,\n}: Omit<SchemaContextType, 'ajv'> & { children: ReactNode }) {\n const ajv = useMemo(\n () =>\n new Ajv2020({\n strict: false,\n validateSchema: false,\n validateFormats: false,\n }),\n [],\n );\n\n return (\n <SchemaContext.Provider\n value={useMemo(\n () => ({ references, ajv, readOnly, writeOnly }),\n [references, ajv, readOnly, writeOnly],\n )}\n >\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport function useSchemaScope(): SchemaScope {\n return use(SchemaContext)!;\n}\n\n/**\n * A hook to store dynamic info of a field, such as selected schema of `oneOf`.\n *\n * @param fieldName - field name of form.\n * @param schema - The **resolved** JSON Schema to generate initial values.\n * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).\n */\nexport function useFieldInfo(\n fieldName: FieldKey,\n schema: Exclude<ParsedSchema, boolean>,\n depth = 0,\n): {\n info: FieldInfo;\n schema: Exclude<ParsedSchema, boolean>;\n updateInfo: (value: Partial<FieldInfo>) => void;\n} {\n const { ajv, references } = use(SchemaContext)!;\n const engine = useDataEngine();\n const { generateDefault } = useSchemaUtils();\n const fieldData = useNamespace({\n namespace: `field-info:${depth}:${stringifyFieldKey(fieldName)}`,\n initial(): FieldInfo {\n const value = engine.get(fieldName);\n const out: FieldInfo = {\n oneOf: -1,\n };\n const union = getUnion(schema);\n if (union) {\n const [members, field] = union;\n\n out.oneOf = members.findIndex((item) =>\n ajv.validate(typeof item === 'object' ? { ...item, ...references } : item, value),\n );\n if (out.oneOf === -1) out.oneOf = 0;\n out.unionField = field;\n }\n\n if (Array.isArray(schema.type)) {\n const types = schema.type;\n\n out.selectedType =\n types.find((type) => {\n return ajv.validate({ ...schema, ...references, type }, value);\n }) ?? types[0];\n }\n\n return out;\n },\n });\n const [info, setInfo] = useFieldValue<FieldInfo>([], {\n stf: fieldData,\n });\n\n return {\n info,\n schema,\n updateInfo(value) {\n const updated = {\n ...info,\n ...value,\n };\n\n if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;\n\n setInfo(updated);\n\n let valueSchema: ParsedSchema = schema;\n if (updated.unionField) {\n valueSchema = schema[updated.unionField]![updated.oneOf];\n } else if (updated.selectedType) {\n // must remove to `examples` to avoid invalid default values\n valueSchema = { ...schema, type: updated.selectedType, examples: undefined };\n }\n\n engine.update(fieldName, generateDefault(valueSchema));\n },\n };\n}\n\nexport function useSchemaUtils() {\n const { references } = use(SchemaContext)!;\n\n return {\n generateDefault(schema: ParsedSchema): unknown {\n return sample(\n schema as never,\n { skipNonRequired: true, skipReadOnly: true, quiet: true },\n references,\n );\n },\n schemaToString(value: ResolvedSchema, flags?: FormatFlags) {\n return schemaToString(\n value,\n (s) => ({ dereferenced: dereference(s, references), raw: s }),\n flags,\n );\n },\n };\n}\n\n/**\n * resolve $ref & merge `allOf`.\n */\nexport function useResolvedSchema(raw: ParsedSchema): Exclude<ParsedSchema, boolean> {\n const { references } = use(SchemaContext)!;\n\n return useMemo(() => {\n const schema = dereference(raw, references);\n if (typeof schema === 'boolean') return anyFields;\n\n if (schema.allOf) {\n return fallbackAny(\n mergeAllOf(schema, {\n dereference(schema) {\n return dereference(schema, references);\n },\n }),\n );\n }\n\n return schema;\n }, [raw, references]);\n}\n\nfunction dereference(schema: ParsedSchema, references: Record<string, ParsedSchema>): ParsedSchema {\n if (typeof schema === 'boolean') return schema;\n\n let ref = schema.$ref;\n if (ref) {\n // use swallow resolution as it is already preprocessed in `playground/index.tsx`\n const prefix = '#/';\n if (ref.startsWith(prefix)) ref = ref.slice(prefix.length);\n if (ref in references) return references[ref];\n }\n\n return schema;\n}\n\nfunction fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n return typeof schema === 'boolean' ? anyFields : schema;\n}\n\nfunction getUnion(\n schema: Exclude<ParsedSchema, boolean>,\n): [readonly ParsedSchema[], UnionField] | undefined {\n if (schema.anyOf) {\n return [schema.anyOf, 'anyOf'];\n }\n\n if (schema.oneOf) return [schema.oneOf, 'oneOf'];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/playground/schema.tsx"],"sourcesContent":["import { Ajv2020 } from 'ajv/dist/2020';\nimport { createContext, ReactNode, use, useMemo } from 'react';\nimport type { ParsedSchema, ResolvedSchema } from '@/utils/schema';\nimport { mergeAllOf } from '@/utils/merge-schema';\nimport { FieldKey, useDataEngine, useFieldValue, useNamespace } from '@fumari/stf';\nimport { stringifyFieldKey } from '@fumari/stf/lib/utils';\nimport { sample } from 'openapi-sampler';\nimport { FormatFlags, schemaToString } from '@/utils/schema-to-string';\n\ninterface SchemaContextType extends SchemaScope {\n references: Record<string, ParsedSchema>;\n ajv: Ajv2020;\n}\n\nexport interface SchemaScope {\n /**\n * show write only fields\n */\n writeOnly: boolean;\n\n /**\n * show read only fields\n */\n readOnly: boolean;\n}\n\ntype UnionField = 'anyOf' | 'oneOf';\n\nexport interface FieldInfo {\n selectedType?: string;\n oneOf: number;\n\n /**\n * The actual field that represents union members.\n */\n unionField?: UnionField;\n}\n\nconst SchemaContext = createContext<SchemaContextType | undefined>(undefined);\nexport const anyFields = {\n type: ['string', 'number', 'boolean', 'array', 'object'],\n items: true,\n additionalProperties: true,\n} satisfies ParsedSchema;\n\nexport function SchemaProvider({\n references,\n readOnly,\n writeOnly,\n children,\n}: Omit<SchemaContextType, 'ajv'> & { children: ReactNode }) {\n const ajv = useMemo(\n () =>\n new Ajv2020({\n strict: false,\n validateSchema: false,\n validateFormats: false,\n }),\n [],\n );\n\n return (\n <SchemaContext.Provider\n value={useMemo(\n () => ({ references, ajv, readOnly, writeOnly }),\n [references, ajv, readOnly, writeOnly],\n )}\n >\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport function useSchemaScope(): SchemaScope {\n return use(SchemaContext)!;\n}\n\n/**\n * A hook to store dynamic info of a field, such as selected schema of `oneOf`.\n *\n * @param fieldName - field name of form.\n * @param schema - The **resolved** JSON Schema to generate initial values.\n * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).\n */\nexport function useFieldInfo(\n fieldName: FieldKey,\n schema: Exclude<ParsedSchema, boolean>,\n depth = 0,\n): {\n info: FieldInfo;\n schema: Exclude<ParsedSchema, boolean>;\n updateInfo: (value: Partial<FieldInfo>) => void;\n} {\n const { ajv, references } = use(SchemaContext)!;\n const engine = useDataEngine();\n const { generateDefault } = useSchemaUtils();\n const fieldData = useNamespace({\n namespace: `field-info:${depth}:${stringifyFieldKey(fieldName)}`,\n initial(): FieldInfo {\n const value = engine.get(fieldName);\n const out: FieldInfo = {\n oneOf: -1,\n };\n const union = getUnion(schema);\n if (union) {\n const [members, field] = union;\n\n out.oneOf = members.findIndex((item) =>\n ajv.validate(typeof item === 'object' ? { ...item, ...references } : item, value),\n );\n if (out.oneOf === -1) out.oneOf = 0;\n out.unionField = field;\n }\n\n if (Array.isArray(schema.type)) {\n const types = schema.type;\n\n out.selectedType =\n types.find((type) => {\n return ajv.validate({ ...schema, ...references, type }, value);\n }) ?? types[0];\n }\n\n return out;\n },\n });\n const [info, setInfo] = useFieldValue<FieldInfo>([], {\n stf: fieldData,\n });\n\n return {\n info,\n schema,\n updateInfo(value) {\n const updated = {\n ...info,\n ...value,\n };\n\n if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;\n\n setInfo(updated);\n\n let valueSchema: ParsedSchema = schema;\n if (updated.unionField) {\n valueSchema = schema[updated.unionField]![updated.oneOf];\n } else if (updated.selectedType) {\n // must remove to `examples` to avoid invalid default values\n valueSchema = { ...schema, type: updated.selectedType, examples: undefined };\n }\n\n engine.update(fieldName, generateDefault(valueSchema));\n },\n };\n}\n\nexport function useSchemaUtils() {\n const { references } = use(SchemaContext)!;\n\n return {\n generateDefault(schema: ParsedSchema): unknown {\n return sample(\n schema as never,\n { skipNonRequired: true, skipReadOnly: true, quiet: true },\n references,\n );\n },\n schemaToString(value: ResolvedSchema, flags?: FormatFlags) {\n return schemaToString(\n value,\n (s) => ({ dereferenced: dereference(s, references), raw: s }),\n flags,\n );\n },\n };\n}\n\n/**\n * resolve $ref & merge `allOf`.\n */\nexport function useResolvedSchema(raw: ParsedSchema): Exclude<ParsedSchema, boolean> {\n const { references } = use(SchemaContext)!;\n\n return useMemo(() => {\n const schema = dereference(raw, references);\n if (typeof schema === 'boolean') return anyFields;\n\n if (schema.allOf) {\n return fallbackAny(\n mergeAllOf(schema, {\n dereference(schema) {\n return dereference(schema, references);\n },\n }),\n );\n }\n\n return schema;\n }, [raw, references]);\n}\n\nfunction dereference(schema: ParsedSchema, references: Record<string, ParsedSchema>): ParsedSchema {\n if (typeof schema === 'boolean') return schema;\n\n let ref = schema.$ref;\n if (ref) {\n // use swallow resolution as it is already preprocessed in `playground/index.tsx`\n const prefix = '#/';\n if (ref.startsWith(prefix)) ref = ref.slice(prefix.length);\n if (ref in references) return references[ref];\n }\n\n return schema;\n}\n\nfunction fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n return typeof schema === 'boolean' ? anyFields : schema;\n}\n\nfunction getUnion(\n schema: Exclude<ParsedSchema, boolean>,\n): [readonly ParsedSchema[], UnionField] | undefined {\n if (schema.anyOf) {\n return [schema.anyOf, 'anyOf'];\n }\n\n if (schema.oneOf) return [schema.oneOf, 'oneOf'];\n}\n"],"mappings":";;;;;;;;;AAsCA,MAAM,gBAAgB,cAA6C,KAAA,EAAU;AAC7E,MAAa,YAAY;CACvB,MAAM;EAAC;EAAU;EAAU;EAAW;EAAS;EAAS;CACxD,OAAO;CACP,sBAAsB;CACvB;AAED,SAAgB,eAAe,EAC7B,YACA,UACA,WACA,YAC2D;CAC3D,MAAM,MAAM,cAER,IAAI,QAAQ;EACV,QAAQ;EACR,gBAAgB;EAChB,iBAAiB;EAClB,CAAC,EACJ,EAAE,CACH;AAED,QACE,oBAAC,cAAc,UAAf;EACE,OAAO,eACE;GAAE;GAAY;GAAK;GAAU;GAAW,GAC/C;GAAC;GAAY;GAAK;GAAU;GAAU,CACvC;EAEA;EACsB,CAAA;;AAI7B,SAAgB,iBAA8B;AAC5C,QAAO,IAAI,cAAc;;;;;;;;;AAU3B,SAAgB,aACd,WACA,QACA,QAAQ,GAKR;CACA,MAAM,EAAE,KAAK,eAAe,IAAI,cAAc;CAC9C,MAAM,SAAS,eAAe;CAC9B,MAAM,EAAE,oBAAoB,gBAAgB;CA+B5C,MAAM,CAAC,MAAM,WAAW,cAAyB,EAAE,EAAE,E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,OAAqB;AACzD,UAAO,eACL,QACC,OAAO;IAAE,cAAc,YAAY,GAAG,WAAW;IAAE,KAAK;IAAG,GAC5D,MACD;;EAEJ;;;;;AAMH,SAAgB,kBAAkB,KAAmD;CACnF,MAAM,EAAE,eAAe,IAAI,cAAc;AAEzC,QAAO,cAAc;EACnB,MAAM,SAAS,YAAY,KAAK,WAAW;AAC3C,MAAI,OAAO,WAAW,UAAW,QAAO;AAExC,MAAI,OAAO,MACT,QAAO,YACL,WAAW,QAAQ,EACjB,YAAY,QAAQ;AAClB,UAAO,YAAY,QAAQ,WAAW;KAEzC,CAAC,CACH;AAGH,SAAO;IACN,CAAC,KAAK,WAAW,CAAC;;AAGvB,SAAS,YAAY,QAAsB,YAAwD;AACjG,KAAI,OAAO,WAAW,UAAW,QAAO;CAExC,IAAI,MAAM,OAAO;AACjB,KAAI,KAAK;AAGP,MAAI,IAAI,WADO,KACW,CAAE,OAAM,IAAI,MAAM,EAAc;AAC1D,MAAI,OAAO,WAAY,QAAO,WAAW;;AAG3C,QAAO;;AAGT,SAAS,YAAY,QAAsD;AACzE,QAAO,OAAO,WAAW,YAAY,YAAY;;AAGnD,SAAS,SACP,QACmD;AACnD,KAAI,OAAO,MACT,QAAO,CAAC,OAAO,OAAO,QAAQ;AAGhC,KAAI,OAAO,MAAO,QAAO,CAAC,OAAO,OAAO,QAAQ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CircleCheck, CircleX } from "lucide-react";
|
|
2
|
-
|
|
3
2
|
//#region src/playground/status-info.tsx
|
|
4
3
|
const statusMap = {
|
|
5
4
|
400: {
|
|
@@ -46,7 +45,7 @@ function getStatusInfo(status) {
|
|
|
46
45
|
icon: CircleX
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
//#endregion
|
|
51
49
|
export { getStatusInfo };
|
|
50
|
+
|
|
52
51
|
//# sourceMappingURL=status-info.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-info.js","names":[],"sources":["../../src/playground/status-info.tsx"],"sourcesContent":["import { CircleCheck, CircleX } from 'lucide-react';\n\ninterface StatusInfo {\n description: string;\n color: string;\n icon: React.ElementType;\n}\n\nconst statusMap: Record<number, StatusInfo> = {\n 400: { description: 'Bad Request', color: 'text-red-500', icon: CircleX },\n 401: {\n description: 'Unauthorized',\n color: 'text-red-500',\n icon: CircleX,\n },\n 403: { description: 'Forbidden', color: 'text-red-500', icon: CircleX },\n 404: {\n description: 'Not Found',\n color: 'text-fd-muted-foreground',\n icon: CircleX,\n },\n 500: {\n description: 'Internal Server Error',\n color: 'text-red-500',\n icon: CircleX,\n },\n};\n\nexport function getStatusInfo(status: number): StatusInfo {\n if (status in statusMap) {\n return statusMap[status];\n }\n\n if (status >= 200 && status < 300) {\n return {\n description: 'Successful',\n color: 'text-green-500',\n icon: CircleCheck,\n };\n }\n\n if (status >= 400) {\n return { description: 'Error', color: 'text-red-500', icon: CircleX };\n }\n\n return {\n description: 'No Description',\n color: 'text-fd-muted-foreground',\n icon: CircleX,\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"status-info.js","names":[],"sources":["../../src/playground/status-info.tsx"],"sourcesContent":["import { CircleCheck, CircleX } from 'lucide-react';\n\ninterface StatusInfo {\n description: string;\n color: string;\n icon: React.ElementType;\n}\n\nconst statusMap: Record<number, StatusInfo> = {\n 400: { description: 'Bad Request', color: 'text-red-500', icon: CircleX },\n 401: {\n description: 'Unauthorized',\n color: 'text-red-500',\n icon: CircleX,\n },\n 403: { description: 'Forbidden', color: 'text-red-500', icon: CircleX },\n 404: {\n description: 'Not Found',\n color: 'text-fd-muted-foreground',\n icon: CircleX,\n },\n 500: {\n description: 'Internal Server Error',\n color: 'text-red-500',\n icon: CircleX,\n },\n};\n\nexport function getStatusInfo(status: number): StatusInfo {\n if (status in statusMap) {\n return statusMap[status];\n }\n\n if (status >= 200 && status < 300) {\n return {\n description: 'Successful',\n color: 'text-green-500',\n icon: CircleCheck,\n };\n }\n\n if (status >= 400) {\n return { description: 'Error', color: 'text-red-500', icon: CircleX };\n }\n\n return {\n description: 'No Description',\n color: 'text-fd-muted-foreground',\n icon: CircleX,\n };\n}\n"],"mappings":";;AAQA,MAAM,YAAwC;CAC5C,KAAK;EAAE,aAAa;EAAe,OAAO;EAAgB,MAAM;EAAS;CACzE,KAAK;EACH,aAAa;EACb,OAAO;EACP,MAAM;EACP;CACD,KAAK;EAAE,aAAa;EAAa,OAAO;EAAgB,MAAM;EAAS;CACvE,KAAK;EACH,aAAa;EACb,OAAO;EACP,MAAM;EACP;CACD,KAAK;EACH,aAAa;EACb,OAAO;EACP,MAAM;EACP;CACF;AAED,SAAgB,cAAc,QAA4B;AACxD,KAAI,UAAU,UACZ,QAAO,UAAU;AAGnB,KAAI,UAAU,OAAO,SAAS,IAC5B,QAAO;EACL,aAAa;EACb,OAAO;EACP,MAAM;EACP;AAGH,KAAI,UAAU,IACZ,QAAO;EAAE,aAAa;EAAS,OAAO;EAAgB,MAAM;EAAS;AAGvE,QAAO;EACL,aAAa;EACb,OAAO;EACP,MAAM;EACP"}
|
|
@@ -4,7 +4,6 @@ import { go } from "./go.js";
|
|
|
4
4
|
import { java } from "./java.js";
|
|
5
5
|
import { javascript } from "./javascript.js";
|
|
6
6
|
import { python } from "./python.js";
|
|
7
|
-
|
|
8
7
|
//#region src/requests/generators/all.ts
|
|
9
8
|
function registerDefault(registry) {
|
|
10
9
|
registry.add("curl", curl);
|
|
@@ -14,7 +13,7 @@ function registerDefault(registry) {
|
|
|
14
13
|
registry.add("java", java);
|
|
15
14
|
registry.add("csharp", csharp);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
17
|
export { registerDefault };
|
|
18
|
+
|
|
20
19
|
//# sourceMappingURL=all.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.js","names":[],"sources":["../../../src/requests/generators/all.ts"],"sourcesContent":["import type { CodeUsageGeneratorRegistry } from '.';\nimport { csharp } from './csharp';\nimport { curl } from './curl';\nimport { go } from './go';\nimport { java } from './java';\nimport { javascript } from './javascript';\nimport { python } from './python';\n\nexport function registerDefault(registry: CodeUsageGeneratorRegistry) {\n registry.add('curl', curl);\n registry.add('js', javascript);\n registry.add('go', go);\n registry.add('python', python);\n registry.add('java', java);\n registry.add('csharp', csharp);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"all.js","names":[],"sources":["../../../src/requests/generators/all.ts"],"sourcesContent":["import type { CodeUsageGeneratorRegistry } from '.';\nimport { csharp } from './csharp';\nimport { curl } from './curl';\nimport { go } from './go';\nimport { java } from './java';\nimport { javascript } from './javascript';\nimport { python } from './python';\n\nexport function registerDefault(registry: CodeUsageGeneratorRegistry) {\n registry.add('curl', curl);\n registry.add('js', javascript);\n registry.add('go', go);\n registry.add('python', python);\n registry.add('java', java);\n registry.add('csharp', csharp);\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,gBAAgB,UAAsC;AACpE,UAAS,IAAI,QAAQ,KAAK;AAC1B,UAAS,IAAI,MAAM,WAAW;AAC9B,UAAS,IAAI,MAAM,GAAG;AACtB,UAAS,IAAI,UAAU,OAAO;AAC9B,UAAS,IAAI,QAAQ,KAAK;AAC1B,UAAS,IAAI,UAAU,OAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
2
2
|
import "../media/adapter.js";
|
|
3
|
-
|
|
4
3
|
//#region src/requests/generators/csharp.ts
|
|
5
4
|
const csharp = {
|
|
6
5
|
label: "C#",
|
|
@@ -38,7 +37,7 @@ const csharp = {
|
|
|
38
37
|
return s.join("\n");
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
|
-
|
|
42
40
|
//#endregion
|
|
43
41
|
export { csharp };
|
|
42
|
+
|
|
44
43
|
//# sourceMappingURL=csharp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.js","names":[],"sources":["../../../src/requests/generators/csharp.ts"],"sourcesContent":["import type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const csharp: CodeUsageGenerator = {\n label: 'C#',\n lang: 'csharp',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const imports = new Set<string>(['System', 'System.Net.Http', 'System.Text']);\n const headers = { ...data.header };\n\n // Handle request body\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'csharp',\n addImport(from) {\n imports.add(from);\n },\n });\n }\n\n for (const specifier of imports) {\n s.push(`using ${specifier};`);\n }\n\n s.push('');\n\n if (body) {\n s.push(body, '');\n }\n\n s.push('var client = new HttpClient();');\n const headerLines: string[] = [];\n\n function addHeader(key: string, value: string) {\n headerLines.push(`client.DefaultRequestHeaders.Add(\"${key}\", ${JSON.stringify(value)});`);\n }\n for (const k in headers) {\n addHeader(k, headers[k].value);\n }\n\n // Add cookie header if cookies are present\n if (Object.keys(data.cookie).length > 0) {\n const cookie = Object.entries(data.cookie)\n .map(([key, param]) => `${key}=${param.value}`)\n .join('; ');\n\n addHeader('cookie', cookie);\n }\n\n s.push(...headerLines);\n\n // Build the request\n const method = data.method[0].toUpperCase() + data.method.slice(1).toLowerCase() + 'Async';\n\n if (body) {\n s.push(`var response = await client.${method}(\"${url}\", body);`);\n } else {\n s.push(`var response = await client.${method}(\"${url}\");`);\n }\n\n // Add response handling\n s.push('var responseBody = await response.Content.ReadAsStringAsync();');\n\n return s.join('\\n');\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"csharp.js","names":[],"sources":["../../../src/requests/generators/csharp.ts"],"sourcesContent":["import type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const csharp: CodeUsageGenerator = {\n label: 'C#',\n lang: 'csharp',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const imports = new Set<string>(['System', 'System.Net.Http', 'System.Text']);\n const headers = { ...data.header };\n\n // Handle request body\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'csharp',\n addImport(from) {\n imports.add(from);\n },\n });\n }\n\n for (const specifier of imports) {\n s.push(`using ${specifier};`);\n }\n\n s.push('');\n\n if (body) {\n s.push(body, '');\n }\n\n s.push('var client = new HttpClient();');\n const headerLines: string[] = [];\n\n function addHeader(key: string, value: string) {\n headerLines.push(`client.DefaultRequestHeaders.Add(\"${key}\", ${JSON.stringify(value)});`);\n }\n for (const k in headers) {\n addHeader(k, headers[k].value);\n }\n\n // Add cookie header if cookies are present\n if (Object.keys(data.cookie).length > 0) {\n const cookie = Object.entries(data.cookie)\n .map(([key, param]) => `${key}=${param.value}`)\n .join('; ');\n\n addHeader('cookie', cookie);\n }\n\n s.push(...headerLines);\n\n // Build the request\n const method = data.method[0].toUpperCase() + data.method.slice(1).toLowerCase() + 'Async';\n\n if (body) {\n s.push(`var response = await client.${method}(\"${url}\", body);`);\n } else {\n s.push(`var response = await client.${method}(\"${url}\");`);\n }\n\n // Add response handling\n s.push('var responseBody = await response.Content.ReadAsStringAsync();');\n\n return s.join('\\n');\n },\n};\n"],"mappings":";;;AAGA,MAAa,SAA6B;CACxC,OAAO;CACP,MAAM;CACN,SAAS,KAAK,MAAM,EAAE,iBAAiB;EACrC,MAAM,IAAc,EAAE;EACtB,MAAM,UAAU,IAAI,IAAY;GAAC;GAAU;GAAmB;GAAc,CAAC;EAC7E,MAAM,UAAU,EAAE,GAAG,KAAK,QAAQ;EAGlC,IAAI;AACJ,MAAI,KAAK,QAAQ,KAAK,cAEpB,QADgB,oBAAoB,KAAK,eAAe,cAAc,EACtD,gBAAgB,MAA2B;GACzD,MAAM;GACN,UAAU,MAAM;AACd,YAAQ,IAAI,KAAK;;GAEpB,CAAC;AAGJ,OAAK,MAAM,aAAa,QACtB,GAAE,KAAK,SAAS,UAAU,GAAG;AAG/B,IAAE,KAAK,GAAG;AAEV,MAAI,KACF,GAAE,KAAK,MAAM,GAAG;AAGlB,IAAE,KAAK,iCAAiC;EACxC,MAAM,cAAwB,EAAE;EAEhC,SAAS,UAAU,KAAa,OAAe;AAC7C,eAAY,KAAK,qCAAqC,IAAI,KAAK,KAAK,UAAU,MAAM,CAAC,IAAI;;AAE3F,OAAK,MAAM,KAAK,QACd,WAAU,GAAG,QAAQ,GAAG,MAAM;AAIhC,MAAI,OAAO,KAAK,KAAK,OAAO,CAAC,SAAS,EAKpC,WAAU,UAJK,OAAO,QAAQ,KAAK,OAAO,CACvC,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,MAAM,QAAQ,CAC9C,KAAK,KAAK,CAEc;AAG7B,IAAE,KAAK,GAAG,YAAY;EAGtB,MAAM,SAAS,KAAK,OAAO,GAAG,aAAa,GAAG,KAAK,OAAO,MAAM,EAAE,CAAC,aAAa,GAAG;AAEnF,MAAI,KACF,GAAE,KAAK,+BAA+B,OAAO,IAAI,IAAI,WAAW;MAEhE,GAAE,KAAK,+BAA+B,OAAO,IAAI,IAAI,KAAK;AAI5D,IAAE,KAAK,iEAAiE;AAExE,SAAO,EAAE,KAAK,KAAK;;CAEtB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { escapeString, ident, inputToString } from "../string-utils.js";
|
|
2
|
-
|
|
3
2
|
//#region src/requests/generators/curl.ts
|
|
4
3
|
const curl = {
|
|
5
4
|
label: "cURL",
|
|
@@ -26,7 +25,7 @@ const curl = {
|
|
|
26
25
|
return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(" \\\n");
|
|
27
26
|
}
|
|
28
27
|
};
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
29
|
export { curl };
|
|
30
|
+
|
|
32
31
|
//# sourceMappingURL=curl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.js","names":[],"sources":["../../../src/requests/generators/curl.ts"],"sourcesContent":["import { escapeString, ident, inputToString } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\n\nexport const curl: CodeUsageGenerator = {\n label: 'cURL',\n lang: 'bash',\n generate(url, data) {\n const s: string[] = [];\n s.push(`curl -X ${data.method} \"${url}\"`);\n\n for (const header in data.header) {\n const value = `${header}: ${data.header[header].value}`;\n\n s.push(`-H \"${value}\"`);\n }\n\n for (const k in data.cookie) {\n const param = data.cookie[k];\n\n s.push(`--cookie ${JSON.stringify(`${k}=${param.value}`)}`);\n }\n\n if (data.body && data.bodyMediaType === 'multipart/form-data') {\n if (typeof data.body !== 'object') throw new Error('[CURL] request body must be an object.');\n\n for (const [key, value] of Object.entries(data.body)) {\n s.push(`-F ${key}=${JSON.stringify(inputToString(value))}`);\n }\n } else if (data.body && data.bodyMediaType) {\n const escaped = escapeString(\n inputToString(\n data.body,\n // @ts-expect-error -- assume the body media type is supported\n data.bodyMediaType,\n ),\n \"'\",\n );\n\n s.push(`-H \"Content-Type: ${data.bodyMediaType}\"`);\n s.push(`-d ${escaped}`);\n }\n\n return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(' \\\\\\n');\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"curl.js","names":[],"sources":["../../../src/requests/generators/curl.ts"],"sourcesContent":["import { escapeString, ident, inputToString } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\n\nexport const curl: CodeUsageGenerator = {\n label: 'cURL',\n lang: 'bash',\n generate(url, data) {\n const s: string[] = [];\n s.push(`curl -X ${data.method} \"${url}\"`);\n\n for (const header in data.header) {\n const value = `${header}: ${data.header[header].value}`;\n\n s.push(`-H \"${value}\"`);\n }\n\n for (const k in data.cookie) {\n const param = data.cookie[k];\n\n s.push(`--cookie ${JSON.stringify(`${k}=${param.value}`)}`);\n }\n\n if (data.body && data.bodyMediaType === 'multipart/form-data') {\n if (typeof data.body !== 'object') throw new Error('[CURL] request body must be an object.');\n\n for (const [key, value] of Object.entries(data.body)) {\n s.push(`-F ${key}=${JSON.stringify(inputToString(value))}`);\n }\n } else if (data.body && data.bodyMediaType) {\n const escaped = escapeString(\n inputToString(\n data.body,\n // @ts-expect-error -- assume the body media type is supported\n data.bodyMediaType,\n ),\n \"'\",\n );\n\n s.push(`-H \"Content-Type: ${data.bodyMediaType}\"`);\n s.push(`-d ${escaped}`);\n }\n\n return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(' \\\\\\n');\n },\n};\n"],"mappings":";;AAGA,MAAa,OAA2B;CACtC,OAAO;CACP,MAAM;CACN,SAAS,KAAK,MAAM;EAClB,MAAM,IAAc,EAAE;AACtB,IAAE,KAAK,WAAW,KAAK,OAAO,IAAI,IAAI,GAAG;AAEzC,OAAK,MAAM,UAAU,KAAK,QAAQ;GAChC,MAAM,QAAQ,GAAG,OAAO,IAAI,KAAK,OAAO,QAAQ;AAEhD,KAAE,KAAK,OAAO,MAAM,GAAG;;AAGzB,OAAK,MAAM,KAAK,KAAK,QAAQ;GAC3B,MAAM,QAAQ,KAAK,OAAO;AAE1B,KAAE,KAAK,YAAY,KAAK,UAAU,GAAG,EAAE,GAAG,MAAM,QAAQ,GAAG;;AAG7D,MAAI,KAAK,QAAQ,KAAK,kBAAkB,uBAAuB;AAC7D,OAAI,OAAO,KAAK,SAAS,SAAU,OAAM,IAAI,MAAM,yCAAyC;AAE5F,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,CAClD,GAAE,KAAK,MAAM,IAAI,GAAG,KAAK,UAAU,cAAc,MAAM,CAAC,GAAG;aAEpD,KAAK,QAAQ,KAAK,eAAe;GAC1C,MAAM,UAAU,aACd,cACE,KAAK,MAEL,KAAK,cACN,EACD,IACD;AAED,KAAE,KAAK,qBAAqB,KAAK,cAAc,GAAG;AAClD,KAAE,KAAK,MAAM,UAAU;;AAGzB,SAAO,EAAE,SAAS,GAAG,MAAM,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,QAAQ;;CAEpE"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ident } from "../string-utils.js";
|
|
2
2
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
3
3
|
import "../media/adapter.js";
|
|
4
|
-
|
|
5
4
|
//#region src/requests/generators/go.ts
|
|
6
5
|
const go = {
|
|
7
6
|
label: "Go",
|
|
@@ -49,7 +48,7 @@ ${ident(Array.from(headers.entries()).map(([key, value]) => `req.Header.Add("${k
|
|
|
49
48
|
}`;
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
|
-
|
|
53
51
|
//#endregion
|
|
54
52
|
export { go };
|
|
53
|
+
|
|
55
54
|
//# sourceMappingURL=go.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.js","names":[],"sources":["../../../src/requests/generators/go.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const go: CodeUsageGenerator = {\n label: 'Go',\n lang: 'go',\n generate(url, data, { mediaAdapters }) {\n const imports = ['fmt', 'net/http', 'io/ioutil'];\n const headers = new Map<string, string>();\n const variables = new Map<string, string>();\n variables.set('url', JSON.stringify(url));\n\n for (const header in data.header) {\n headers.set(header, JSON.stringify(data.header[header].value));\n }\n\n const cookies = Object.entries(data.cookie);\n if (cookies.length > 0) {\n headers.set(\n 'Cookie',\n JSON.stringify(cookies.map(([k, param]) => `${k}=${param.value}`).join('; ')),\n );\n }\n\n let body: string | undefined;\n\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n headers.set('Content-Type', `\"${data.bodyMediaType}\"`);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'go',\n addImport(from) {\n imports.push(from);\n },\n });\n }\n\n return `package main\n\nimport (\n${ident(imports.map((v) => `\"${v}\"`).join('\\n'))}\n)\n\nfunc main() {\n${Array.from(variables.entries())\n .map(([k, v]) => ident(`${k} := ${v}`))\n .join('\\n')}\n${body ? ident(body) : ''}\n req, _ := http.NewRequest(\"${data.method}\", url, ${body ? 'body' : 'nil'})\n${ident(\n Array.from(headers.entries())\n .map(([key, value]) => `req.Header.Add(\"${key}\", ${value})`)\n .join('\\n'),\n)}\n res, _ := http.DefaultClient.Do(req)\n defer res.Body.Close()\n body, _ := ioutil.ReadAll(res.Body)\n\n fmt.Println(res)\n fmt.Println(string(body))\n}`;\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"go.js","names":[],"sources":["../../../src/requests/generators/go.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const go: CodeUsageGenerator = {\n label: 'Go',\n lang: 'go',\n generate(url, data, { mediaAdapters }) {\n const imports = ['fmt', 'net/http', 'io/ioutil'];\n const headers = new Map<string, string>();\n const variables = new Map<string, string>();\n variables.set('url', JSON.stringify(url));\n\n for (const header in data.header) {\n headers.set(header, JSON.stringify(data.header[header].value));\n }\n\n const cookies = Object.entries(data.cookie);\n if (cookies.length > 0) {\n headers.set(\n 'Cookie',\n JSON.stringify(cookies.map(([k, param]) => `${k}=${param.value}`).join('; ')),\n );\n }\n\n let body: string | undefined;\n\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n headers.set('Content-Type', `\"${data.bodyMediaType}\"`);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'go',\n addImport(from) {\n imports.push(from);\n },\n });\n }\n\n return `package main\n\nimport (\n${ident(imports.map((v) => `\"${v}\"`).join('\\n'))}\n)\n\nfunc main() {\n${Array.from(variables.entries())\n .map(([k, v]) => ident(`${k} := ${v}`))\n .join('\\n')}\n${body ? ident(body) : ''}\n req, _ := http.NewRequest(\"${data.method}\", url, ${body ? 'body' : 'nil'})\n${ident(\n Array.from(headers.entries())\n .map(([key, value]) => `req.Header.Add(\"${key}\", ${value})`)\n .join('\\n'),\n)}\n res, _ := http.DefaultClient.Do(req)\n defer res.Body.Close()\n body, _ := ioutil.ReadAll(res.Body)\n\n fmt.Println(res)\n fmt.Println(string(body))\n}`;\n },\n};\n"],"mappings":";;;;AAIA,MAAa,KAAyB;CACpC,OAAO;CACP,MAAM;CACN,SAAS,KAAK,MAAM,EAAE,iBAAiB;EACrC,MAAM,UAAU;GAAC;GAAO;GAAY;GAAY;EAChD,MAAM,0BAAU,IAAI,KAAqB;EACzC,MAAM,4BAAY,IAAI,KAAqB;AAC3C,YAAU,IAAI,OAAO,KAAK,UAAU,IAAI,CAAC;AAEzC,OAAK,MAAM,UAAU,KAAK,OACxB,SAAQ,IAAI,QAAQ,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,CAAC;EAGhE,MAAM,UAAU,OAAO,QAAQ,KAAK,OAAO;AAC3C,MAAI,QAAQ,SAAS,EACnB,SAAQ,IACN,UACA,KAAK,UAAU,QAAQ,KAAK,CAAC,GAAG,WAAW,GAAG,EAAE,GAAG,MAAM,QAAQ,CAAC,KAAK,KAAK,CAAC,CAC9E;EAGH,IAAI;AAEJ,MAAI,KAAK,QAAQ,KAAK,eAAe;GACnC,MAAM,UAAU,oBAAoB,KAAK,eAAe,cAAc;AACtE,WAAQ,IAAI,gBAAgB,IAAI,KAAK,cAAc,GAAG;AACtD,UAAO,SAAS,gBAAgB,MAA2B;IACzD,MAAM;IACN,UAAU,MAAM;AACd,aAAQ,KAAK,KAAK;;IAErB,CAAC;;AAGJ,SAAO;;;EAGT,MAAM,QAAQ,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC;;;;EAI/C,MAAM,KAAK,UAAU,SAAS,CAAC,CAC9B,KAAK,CAAC,GAAG,OAAO,MAAM,GAAG,EAAE,MAAM,IAAI,CAAC,CACtC,KAAK,KAAK,CAAC;EACZ,OAAO,MAAM,KAAK,GAAG,GAAG;+BACK,KAAK,OAAO,UAAU,OAAO,SAAS,MAAM;EACzE,MACA,MAAM,KAAK,QAAQ,SAAS,CAAC,CAC1B,KAAK,CAAC,KAAK,WAAW,mBAAmB,IAAI,KAAK,MAAM,GAAG,CAC3D,KAAK,KAAK,CACd,CAAC;;;;;;;;;CASD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ident } from "../string-utils.js";
|
|
2
2
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
3
3
|
import "../media/adapter.js";
|
|
4
|
-
|
|
5
4
|
//#region src/requests/generators/java.ts
|
|
6
5
|
const java = {
|
|
7
6
|
label: "Java",
|
|
@@ -54,7 +53,7 @@ const java = {
|
|
|
54
53
|
return s.join("\n");
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
|
-
|
|
58
56
|
//#endregion
|
|
59
57
|
export { java };
|
|
58
|
+
|
|
60
59
|
//# sourceMappingURL=java.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"java.js","names":[],"sources":["../../../src/requests/generators/java.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const java: CodeUsageGenerator = {\n label: 'Java',\n lang: 'java',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const headers = { ...data.header };\n const imports = new Set<string>([\n 'java.net.URI',\n 'java.net.http.HttpClient',\n 'java.net.http.HttpRequest',\n 'java.net.http.HttpResponse',\n 'java.net.http.HttpResponse.BodyHandlers',\n 'java.time.Duration',\n ]);\n\n // Handle body if present\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'java',\n addImport(specifier) {\n imports.add(specifier);\n },\n });\n }\n\n for (const value of imports.values()) {\n s.push(`import ${value};`);\n }\n s.push('');\n\n if (body) {\n s.push(body);\n }\n\n // Create HttpClient\n s.push('HttpClient client = HttpClient.newBuilder()');\n s.push(ident('.connectTimeout(Duration.ofSeconds(10))'));\n s.push(ident('.build();'));\n s.push('');\n\n // Build request\n s.push('HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()');\n s.push(ident(`.uri(URI.create(${JSON.stringify(url)}))`));\n\n // Add headers\n for (const [key, param] of Object.entries(headers)) {\n s.push(ident(`.header(${JSON.stringify(key)}, ${JSON.stringify(param.value)})`));\n }\n\n if (data.bodyMediaType) {\n s.push(ident(`.header(\"Content-Type\", \"${data.bodyMediaType}\")`));\n }\n\n // Add cookies if present\n const cookies = Object.entries(data.cookie);\n\n if (cookies.length > 0) {\n const cookieString = cookies.map(([key, param]) => `${key}=${param.value}`).join('; ');\n\n s.push(ident(`.header(\"Cookie\", ${JSON.stringify(cookieString)})`));\n }\n\n const arg = body ? 'body' : '';\n s.push(ident(`.${data.method.toUpperCase()}(${arg})`));\n s.push(ident('.build();'));\n s.push('');\n\n // Add response handling\n s.push('try {');\n s.push(\n ident(\n 'HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());',\n ),\n );\n s.push(ident('System.out.println(\"Status code: \" + response.statusCode());'));\n s.push(ident('System.out.println(\"Response body: \" + response.body());'));\n s.push('} catch (Exception e) {');\n s.push(ident('e.printStackTrace();'));\n s.push('}');\n\n return s.join('\\n');\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"java.js","names":[],"sources":["../../../src/requests/generators/java.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const java: CodeUsageGenerator = {\n label: 'Java',\n lang: 'java',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const headers = { ...data.header };\n const imports = new Set<string>([\n 'java.net.URI',\n 'java.net.http.HttpClient',\n 'java.net.http.HttpRequest',\n 'java.net.http.HttpResponse',\n 'java.net.http.HttpResponse.BodyHandlers',\n 'java.time.Duration',\n ]);\n\n // Handle body if present\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'java',\n addImport(specifier) {\n imports.add(specifier);\n },\n });\n }\n\n for (const value of imports.values()) {\n s.push(`import ${value};`);\n }\n s.push('');\n\n if (body) {\n s.push(body);\n }\n\n // Create HttpClient\n s.push('HttpClient client = HttpClient.newBuilder()');\n s.push(ident('.connectTimeout(Duration.ofSeconds(10))'));\n s.push(ident('.build();'));\n s.push('');\n\n // Build request\n s.push('HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()');\n s.push(ident(`.uri(URI.create(${JSON.stringify(url)}))`));\n\n // Add headers\n for (const [key, param] of Object.entries(headers)) {\n s.push(ident(`.header(${JSON.stringify(key)}, ${JSON.stringify(param.value)})`));\n }\n\n if (data.bodyMediaType) {\n s.push(ident(`.header(\"Content-Type\", \"${data.bodyMediaType}\")`));\n }\n\n // Add cookies if present\n const cookies = Object.entries(data.cookie);\n\n if (cookies.length > 0) {\n const cookieString = cookies.map(([key, param]) => `${key}=${param.value}`).join('; ');\n\n s.push(ident(`.header(\"Cookie\", ${JSON.stringify(cookieString)})`));\n }\n\n const arg = body ? 'body' : '';\n s.push(ident(`.${data.method.toUpperCase()}(${arg})`));\n s.push(ident('.build();'));\n s.push('');\n\n // Add response handling\n s.push('try {');\n s.push(\n ident(\n 'HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());',\n ),\n );\n s.push(ident('System.out.println(\"Status code: \" + response.statusCode());'));\n s.push(ident('System.out.println(\"Response body: \" + response.body());'));\n s.push('} catch (Exception e) {');\n s.push(ident('e.printStackTrace();'));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BAAqB,KAAK,UAAU,aAAa,CAAC,GAAG,CAAC;;EAGrE,MAAM,MAAM,OAAO,SAAS;AAC5B,IAAE,KAAK,MAAM,IAAI,KAAK,OAAO,aAAa,CAAC,GAAG,IAAI,GAAG,CAAC;AACtD,IAAE,KAAK,MAAM,YAAY,CAAC;AAC1B,IAAE,KAAK,GAAG;AAGV,IAAE,KAAK,QAAQ;AACf,IAAE,KACA,MACE,gGACD,CACF;AACD,IAAE,KAAK,MAAM,iEAA+D,CAAC;AAC7E,IAAE,KAAK,MAAM,6DAA2D,CAAC;AACzE,IAAE,KAAK,0BAA0B;AACjC,IAAE,KAAK,MAAM,uBAAuB,CAAC;AACrC,IAAE,KAAK,IAAI;AAEX,SAAO,EAAE,KAAK,KAAK;;CAEtB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ident } from "../string-utils.js";
|
|
2
2
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
3
3
|
import "../media/adapter.js";
|
|
4
|
-
|
|
5
4
|
//#region src/requests/generators/javascript.ts
|
|
6
5
|
const javascript = {
|
|
7
6
|
label: "JavaScript",
|
|
@@ -36,7 +35,7 @@ const javascript = {
|
|
|
36
35
|
return s.join("\n\n");
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
|
-
|
|
40
38
|
//#endregion
|
|
41
39
|
export { javascript };
|
|
40
|
+
|
|
42
41
|
//# sourceMappingURL=javascript.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.js","names":[],"sources":["../../../src/requests/generators/javascript.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const javascript: CodeUsageGenerator = {\n label: 'JavaScript',\n lang: 'js',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const options = new Map<string, string>();\n const headers: Record<string, string> = {};\n\n options.set('method', JSON.stringify(data.method));\n if (data.bodyMediaType) {\n headers['Content-Type'] = data.bodyMediaType;\n }\n\n for (const [k, v] of Object.entries(data.header)) {\n headers[k] = v.value;\n }\n\n const cookies = Object.entries(data.cookie);\n if (cookies.length > 0) {\n headers['cookie'] = cookies.map(([key, param]) => `${key}=${param.value}`).join('; ');\n }\n\n if (Object.keys(headers).length > 0) {\n options.set('headers', JSON.stringify(headers, null, 2));\n }\n\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'js',\n addImport(from, name) {\n s.unshift(`import { ${name} } from \"${from}\"`);\n },\n });\n }\n\n if (body) {\n s.push(body);\n options.set('body', 'body');\n }\n\n const params = [JSON.stringify(url)];\n if (options.size > 0) {\n const str = Array.from(options.entries())\n .map(([k, v]) => ident(k === v ? k : `${k}: ${v}`))\n .join(',\\n');\n\n params.push(`{\\n${str}\\n}`);\n }\n\n s.push(`fetch(${params.join(', ')})`);\n\n return s.join('\\n\\n');\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"javascript.js","names":[],"sources":["../../../src/requests/generators/javascript.ts"],"sourcesContent":["import { ident } from '@/requests/string-utils';\nimport type { CodeUsageGenerator } from '@/requests/generators';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const javascript: CodeUsageGenerator = {\n label: 'JavaScript',\n lang: 'js',\n generate(url, data, { mediaAdapters }) {\n const s: string[] = [];\n const options = new Map<string, string>();\n const headers: Record<string, string> = {};\n\n options.set('method', JSON.stringify(data.method));\n if (data.bodyMediaType) {\n headers['Content-Type'] = data.bodyMediaType;\n }\n\n for (const [k, v] of Object.entries(data.header)) {\n headers[k] = v.value;\n }\n\n const cookies = Object.entries(data.cookie);\n if (cookies.length > 0) {\n headers['cookie'] = cookies.map(([key, param]) => `${key}=${param.value}`).join('; ');\n }\n\n if (Object.keys(headers).length > 0) {\n options.set('headers', JSON.stringify(headers, null, 2));\n }\n\n let body: string | undefined;\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'js',\n addImport(from, name) {\n s.unshift(`import { ${name} } from \"${from}\"`);\n },\n });\n }\n\n if (body) {\n s.push(body);\n options.set('body', 'body');\n }\n\n const params = [JSON.stringify(url)];\n if (options.size > 0) {\n const str = Array.from(options.entries())\n .map(([k, v]) => ident(k === v ? k : `${k}: ${v}`))\n .join(',\\n');\n\n params.push(`{\\n${str}\\n}`);\n }\n\n s.push(`fetch(${params.join(', ')})`);\n\n return s.join('\\n\\n');\n },\n};\n"],"mappings":";;;;AAIA,MAAa,aAAiC;CAC5C,OAAO;CACP,MAAM;CACN,SAAS,KAAK,MAAM,EAAE,iBAAiB;EACrC,MAAM,IAAc,EAAE;EACtB,MAAM,0BAAU,IAAI,KAAqB;EACzC,MAAM,UAAkC,EAAE;AAE1C,UAAQ,IAAI,UAAU,KAAK,UAAU,KAAK,OAAO,CAAC;AAClD,MAAI,KAAK,cACP,SAAQ,kBAAkB,KAAK;AAGjC,OAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,OAAO,CAC9C,SAAQ,KAAK,EAAE;EAGjB,MAAM,UAAU,OAAO,QAAQ,KAAK,OAAO;AAC3C,MAAI,QAAQ,SAAS,EACnB,SAAQ,YAAY,QAAQ,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,KAAK;AAGvF,MAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAChC,SAAQ,IAAI,WAAW,KAAK,UAAU,SAAS,MAAM,EAAE,CAAC;EAG1D,IAAI;AACJ,MAAI,KAAK,QAAQ,KAAK,cAEpB,QADgB,oBAAoB,KAAK,eAAe,cAAc,EACtD,gBAAgB,MAA2B;GACzD,MAAM;GACN,UAAU,MAAM,MAAM;AACpB,MAAE,QAAQ,YAAY,KAAK,WAAW,KAAK,GAAG;;GAEjD,CAAC;AAGJ,MAAI,MAAM;AACR,KAAE,KAAK,KAAK;AACZ,WAAQ,IAAI,QAAQ,OAAO;;EAG7B,MAAM,SAAS,CAAC,KAAK,UAAU,IAAI,CAAC;AACpC,MAAI,QAAQ,OAAO,GAAG;GACpB,MAAM,MAAM,MAAM,KAAK,QAAQ,SAAS,CAAC,CACtC,KAAK,CAAC,GAAG,OAAO,MAAM,MAAM,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,CAAC,CAClD,KAAK,MAAM;AAEd,UAAO,KAAK,MAAM,IAAI,KAAK;;AAG7B,IAAE,KAAK,SAAS,OAAO,KAAK,KAAK,CAAC,GAAG;AAErC,SAAO,EAAE,KAAK,OAAO;;CAExB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { resolveMediaAdapter } from "../media/resolve-adapter.js";
|
|
2
2
|
import "../media/adapter.js";
|
|
3
3
|
import { generatePythonObject } from "../to-python-object.js";
|
|
4
|
-
|
|
5
4
|
//#region src/requests/generators/python.ts
|
|
6
5
|
const python = {
|
|
7
6
|
label: "Python",
|
|
@@ -35,7 +34,7 @@ response = requests.request(${params.join(", ")})
|
|
|
35
34
|
print(response.text)`;
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
export { python };
|
|
39
|
+
|
|
41
40
|
//# sourceMappingURL=python.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.js","names":[],"sources":["../../../src/requests/generators/python.ts"],"sourcesContent":["import type { CodeUsageGenerator } from '@/requests/generators';\nimport { generatePythonObject } from '@/requests/to-python-object';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const python: CodeUsageGenerator = {\n label: 'Python',\n lang: 'python',\n generate(url, data, { mediaAdapters }) {\n const headers: Record<string, string> = {};\n const imports = new Set<string>();\n const params = [`\"${data.method}\"`, 'url'];\n let body: string | undefined;\n\n imports.add('requests');\n\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n headers['Content-Type'] = data.bodyMediaType;\n\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'python',\n });\n\n if (body) {\n params.push('data = body');\n }\n }\n\n for (const [k, v] of Object.entries(data.header)) {\n headers[k] = v.value;\n }\n\n if (Object.keys(headers).length > 0) {\n params.push(`headers = ${generatePythonObject(headers, imports)}`);\n }\n\n const inputCookies = Object.entries(data.cookie);\n if (inputCookies.length > 0) {\n const cookies: Record<string, string> = {};\n\n for (const [k, v] of inputCookies) {\n cookies[k] = v.value;\n }\n\n params.push(`cookies = ${generatePythonObject(cookies, imports)}`);\n }\n\n return `${Array.from(imports)\n .map((name) => 'import ' + name)\n .join('\\n')}\n\nurl = ${JSON.stringify(url)}\n${body ?? ''}\nresponse = requests.request(${params.join(', ')})\n\nprint(response.text)`;\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"python.js","names":[],"sources":["../../../src/requests/generators/python.ts"],"sourcesContent":["import type { CodeUsageGenerator } from '@/requests/generators';\nimport { generatePythonObject } from '@/requests/to-python-object';\nimport { resolveMediaAdapter } from '@/requests/media/adapter';\n\nexport const python: CodeUsageGenerator = {\n label: 'Python',\n lang: 'python',\n generate(url, data, { mediaAdapters }) {\n const headers: Record<string, string> = {};\n const imports = new Set<string>();\n const params = [`\"${data.method}\"`, 'url'];\n let body: string | undefined;\n\n imports.add('requests');\n\n if (data.body && data.bodyMediaType) {\n const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);\n headers['Content-Type'] = data.bodyMediaType;\n\n body = adapter?.generateExample(data as { body: unknown }, {\n lang: 'python',\n });\n\n if (body) {\n params.push('data = body');\n }\n }\n\n for (const [k, v] of Object.entries(data.header)) {\n headers[k] = v.value;\n }\n\n if (Object.keys(headers).length > 0) {\n params.push(`headers = ${generatePythonObject(headers, imports)}`);\n }\n\n const inputCookies = Object.entries(data.cookie);\n if (inputCookies.length > 0) {\n const cookies: Record<string, string> = {};\n\n for (const [k, v] of inputCookies) {\n cookies[k] = v.value;\n }\n\n params.push(`cookies = ${generatePythonObject(cookies, imports)}`);\n }\n\n return `${Array.from(imports)\n .map((name) => 'import ' + name)\n .join('\\n')}\n\nurl = ${JSON.stringify(url)}\n${body ?? ''}\nresponse = requests.request(${params.join(', ')})\n\nprint(response.text)`;\n },\n};\n"],"mappings":";;;;AAIA,MAAa,SAA6B;CACxC,OAAO;CACP,MAAM;CACN,SAAS,KAAK,MAAM,EAAE,iBAAiB;EACrC,MAAM,UAAkC,EAAE;EAC1C,MAAM,0BAAU,IAAI,KAAa;EACjC,MAAM,SAAS,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM;EAC1C,IAAI;AAEJ,UAAQ,IAAI,WAAW;AAEvB,MAAI,KAAK,QAAQ,KAAK,eAAe;GACnC,MAAM,UAAU,oBAAoB,KAAK,eAAe,cAAc;AACtE,WAAQ,kBAAkB,KAAK;AAE/B,UAAO,SAAS,gBAAgB,MAA2B,EACzD,MAAM,UACP,CAAC;AAEF,OAAI,KACF,QAAO,KAAK,cAAc;;AAI9B,OAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,OAAO,CAC9C,SAAQ,KAAK,EAAE;AAGjB,MAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAChC,QAAO,KAAK,aAAa,qBAAqB,SAAS,QAAQ,GAAG;EAGpE,MAAM,eAAe,OAAO,QAAQ,KAAK,OAAO;AAChD,MAAI,aAAa,SAAS,GAAG;GAC3B,MAAM,UAAkC,EAAE;AAE1C,QAAK,MAAM,CAAC,GAAG,MAAM,aACnB,SAAQ,KAAK,EAAE;AAGjB,UAAO,KAAK,aAAa,qBAAqB,SAAS,QAAQ,GAAG;;AAGpE,SAAO,GAAG,MAAM,KAAK,QAAQ,CAC1B,KAAK,SAAS,YAAY,KAAK,CAC/B,KAAK,KAAK,CAAC;;QAEV,KAAK,UAAU,IAAI,CAAC;EAC1B,QAAQ,GAAG;8BACiB,OAAO,KAAK,KAAK,CAAC;;;;CAI/C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { escapeString, inputToString } from "../string-utils.js";
|
|
2
|
-
import
|
|
2
|
+
import "./resolve-adapter.js";
|
|
3
3
|
import js2xml from "xml-js/lib/js2xml";
|
|
4
|
-
|
|
5
4
|
//#region src/requests/media/adapter.ts
|
|
6
5
|
const defaultAdapters = {
|
|
7
6
|
"application/json": {
|
|
@@ -119,7 +118,7 @@ function str(init, mediaType, ctx) {
|
|
|
119
118
|
}
|
|
120
119
|
if (ctx.lang === "csharp") return `var body = new StringContent(${escapeString(`\n${inputToString(init, mediaType)}\n`, "\"\"\"")}, Encoding.UTF8, "${mediaType}");`;
|
|
121
120
|
}
|
|
122
|
-
|
|
123
121
|
//#endregion
|
|
124
122
|
export { defaultAdapters };
|
|
123
|
+
|
|
125
124
|
//# sourceMappingURL=adapter.js.map
|