fumadocs-openapi 6.3.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/playground/client.d.ts +11 -11
  2. package/dist/playground/client.d.ts.map +1 -1
  3. package/dist/playground/client.js +124 -119
  4. package/dist/playground/fetcher.d.ts +6 -22
  5. package/dist/playground/fetcher.d.ts.map +1 -1
  6. package/dist/playground/fetcher.js +44 -85
  7. package/dist/playground/get-default-values.d.ts +2 -3
  8. package/dist/playground/get-default-values.d.ts.map +1 -1
  9. package/dist/playground/get-default-values.js +8 -4
  10. package/dist/playground/index.d.ts +3 -2
  11. package/dist/playground/index.d.ts.map +1 -1
  12. package/dist/playground/index.js +6 -11
  13. package/dist/playground/inputs.d.ts.map +1 -1
  14. package/dist/playground/inputs.js +46 -32
  15. package/dist/render/operation/api-example.d.ts +18 -4
  16. package/dist/render/operation/api-example.d.ts.map +1 -1
  17. package/dist/render/operation/api-example.js +68 -72
  18. package/dist/render/operation/get-request-data.d.ts +5 -0
  19. package/dist/render/operation/get-request-data.d.ts.map +1 -0
  20. package/dist/render/operation/get-request-data.js +71 -0
  21. package/dist/render/{operation.d.ts → operation/index.d.ts} +4 -4
  22. package/dist/render/operation/index.d.ts.map +1 -0
  23. package/dist/render/{operation.js → operation/index.js} +14 -15
  24. package/dist/render/renderer.d.ts +1 -9
  25. package/dist/render/renderer.d.ts.map +1 -1
  26. package/dist/render/renderer.js +3 -5
  27. package/dist/requests/_shared.d.ts +11 -0
  28. package/dist/requests/_shared.d.ts.map +1 -0
  29. package/dist/requests/_shared.js +4 -0
  30. package/dist/requests/curl.d.ts +2 -2
  31. package/dist/requests/curl.d.ts.map +1 -1
  32. package/dist/requests/curl.js +17 -18
  33. package/dist/requests/go.d.ts +2 -2
  34. package/dist/requests/go.d.ts.map +1 -1
  35. package/dist/requests/go.js +15 -14
  36. package/dist/requests/index.d.ts +3 -0
  37. package/dist/requests/index.d.ts.map +1 -0
  38. package/dist/requests/index.js +26 -0
  39. package/dist/requests/javascript.d.ts +2 -2
  40. package/dist/requests/javascript.d.ts.map +1 -1
  41. package/dist/requests/javascript.js +20 -27
  42. package/dist/requests/python.d.ts +2 -2
  43. package/dist/requests/python.d.ts.map +1 -1
  44. package/dist/requests/python.js +18 -22
  45. package/dist/scalar/client.js +1 -1
  46. package/dist/server/api-page.js +1 -1
  47. package/dist/types.d.ts +5 -6
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/ui/client.d.ts +1 -2
  50. package/dist/ui/client.d.ts.map +1 -1
  51. package/dist/ui/client.js +1 -3
  52. package/dist/ui/components/method-label.d.ts +1 -1
  53. package/dist/ui/contexts/api.d.ts +3 -5
  54. package/dist/ui/contexts/api.d.ts.map +1 -1
  55. package/dist/ui/contexts/api.js +2 -7
  56. package/dist/ui/contexts/code-example.d.ts +25 -0
  57. package/dist/ui/contexts/code-example.d.ts.map +1 -0
  58. package/dist/ui/contexts/code-example.js +104 -0
  59. package/dist/ui/contexts/code-example.lazy.d.ts +12 -0
  60. package/dist/ui/contexts/code-example.lazy.d.ts.map +1 -0
  61. package/dist/ui/contexts/code-example.lazy.js +5 -0
  62. package/dist/ui/server-select.d.ts +6 -1
  63. package/dist/ui/server-select.d.ts.map +1 -1
  64. package/dist/ui/server-select.js +6 -7
  65. package/dist/utils/generate-document.js +1 -1
  66. package/dist/utils/get-pathname-from-input.d.ts +2 -0
  67. package/dist/utils/get-pathname-from-input.d.ts.map +1 -0
  68. package/dist/utils/get-pathname-from-input.js +15 -0
  69. package/dist/utils/get-typescript-schema.d.ts +2 -3
  70. package/dist/utils/get-typescript-schema.d.ts.map +1 -1
  71. package/dist/utils/get-typescript-schema.js +13 -16
  72. package/package.json +9 -9
  73. package/dist/render/operation.d.ts.map +0 -1
  74. package/dist/ui/sample-select.d.ts +0 -4
  75. package/dist/ui/sample-select.d.ts.map +0 -1
  76. package/dist/ui/sample-select.js +0 -19
  77. package/dist/utils/generate-sample.d.ts +0 -40
  78. package/dist/utils/generate-sample.d.ts.map +0 -1
  79. package/dist/utils/generate-sample.js +0 -109
@@ -8,9 +8,10 @@ interface FormValues {
8
8
  username: string;
9
9
  password: string;
10
10
  };
11
- path: Record<string, unknown>;
12
- query: Record<string, unknown>;
13
- header: Record<string, unknown>;
11
+ path: Record<string, string>;
12
+ query: Record<string, string>;
13
+ header: Record<string, string>;
14
+ cookie: Record<string, string>;
14
15
  body: unknown;
15
16
  }
16
17
  export interface CustomField<TName extends FieldPath<FormValues>, Info> {
@@ -28,19 +29,18 @@ export type ClientProps = HTMLAttributes<HTMLFormElement> & {
28
29
  route: string;
29
30
  method: string;
30
31
  authorization?: Security;
31
- path?: PrimitiveRequestField[];
32
- query?: PrimitiveRequestField[];
33
- header?: PrimitiveRequestField[];
32
+ parameters?: PrimitiveRequestField[];
34
33
  body?: RequestSchema & {
35
34
  mediaType: string;
36
35
  };
37
- schemas: Record<string, RequestSchema>;
36
+ /**
37
+ * Resolver for reference schemas you've passed
38
+ */
39
+ references: Record<string, RequestSchema>;
38
40
  proxyUrl?: string;
39
41
  fields?: {
42
+ parameter?: CustomField<`${PrimitiveRequestField['in']}.${string}`, PrimitiveRequestField>;
40
43
  auth?: CustomField<'authorization', RequestSchema>;
41
- path?: CustomField<`path.${string}`, PrimitiveRequestField>;
42
- query?: CustomField<`query.${string}`, PrimitiveRequestField>;
43
- header?: CustomField<`header.${string}`, PrimitiveRequestField>;
44
44
  body?: CustomField<'body', RequestSchema>;
45
45
  };
46
46
  components?: Partial<{
@@ -61,6 +61,6 @@ export type DynamicField = {
61
61
  schema: RequestSchema | ReferenceSchema;
62
62
  };
63
63
  export declare function useSchemaContext(): SchemaContextType;
64
- export declare function Client({ route, method, authorization, path, header, query, body, fields, schemas, proxyUrl, components: { ResultDisplay }, ...props }: ClientProps): import("react/jsx-runtime").JSX.Element;
64
+ export declare function Client({ route, method, authorization, parameters, body, fields, references, proxyUrl, components: { ResultDisplay }, ...props }: ClientProps): import("react/jsx-runtime").JSX.Element;
65
65
  export {};
66
66
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EAInB,KAAK,EAAE,EAGP,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,aAAa,EACd,MAAM,oBAAoB,CAAC;AAa5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMrD,UAAU,UAAU;IAClB,aAAa,EACT,MAAM,GACN;QACE,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACN,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,WAAW,CAAC,KAAK,SAAS,SAAS,CAAC,UAAU,CAAC,EAAE,IAAI;IACpE,MAAM,EAAE,CAAC,KAAK,EAAE;QACd;;WAEG;QACH,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,qBAAqB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAChD,UAAU,EAAE,oBAAoB,CAAC;QACjC,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;KAC3C,KAAK,YAAY,CAAC;CACpB;AAED,MAAM,MAA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M,EAAE,aAAa,CAAC,CAAC;IAC1C,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC;CACzC,CAAC;AAIN,wBAAgB,gBAAgB,IAAI,iBAAiB,CAIpD;AAkBD,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,MAAc,EACd,aAAa,EACb,UAAe,EACf,IAAI,EACJ,MAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EAAE,EAAE,aAAoC,EAAO,EACzD,GAAG,KAAK,EACT,EAAE,WAAW,2CA2Mb"}
@@ -1,10 +1,9 @@
1
1
  'use client';
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo, useRef, useEffect, Fragment, createContext, useContext, } from 'react';
4
- import { Controller, FormProvider, useForm } from 'react-hook-form';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useMemo, useRef, useEffect, Fragment, createContext, useContext, useState, } from 'react';
4
+ import { Controller, FormProvider, useForm, useFormContext, } from 'react-hook-form';
5
5
  import { cn, buttonVariants } from 'fumadocs-ui/components/api';
6
- import { useApiContext } from '../ui/contexts/api.js';
7
- import { getDefaultValue, getDefaultValues } from './get-default-values.js';
6
+ import { useApiContext, useServerSelectContext } from '../ui/contexts/api.js';
8
7
  import { FieldSet, ObjectInput } from './inputs.js';
9
8
  import { getStatusInfo } from './status-info.js';
10
9
  import { getUrl } from '../utils/server-url.js';
@@ -15,6 +14,8 @@ import ServerSelect from '../ui/server-select.js';
15
14
  import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
16
15
  import { ChevronDown } from 'lucide-react';
17
16
  import { OauthDialog, OauthDialogTrigger, } from '../playground/auth/oauth-dialog.js';
17
+ import { useRequestData } from '../ui/contexts/code-example.js';
18
+ import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
18
19
  const SchemaContext = createContext(undefined);
19
20
  export function useSchemaContext() {
20
21
  const ctx = useContext(SchemaContext);
@@ -22,94 +23,64 @@ export function useSchemaContext() {
22
23
  throw new Error('Missing provider');
23
24
  return ctx;
24
25
  }
25
- function defaultAuthValue(auth) {
26
- if (!auth || auth.type === 'apiKey')
27
- return '';
28
- if (auth.type === 'http' && auth.scheme === 'basic') {
26
+ function toRequestData(method, mediaType, value) {
27
+ return {
28
+ path: value.path,
29
+ method,
30
+ header: value.header,
31
+ body: value.body,
32
+ bodyMediaType: mediaType,
33
+ cookie: value.cookie,
34
+ query: value.query,
35
+ };
36
+ }
37
+ export function Client({ route, method = 'GET', authorization, parameters = [], body, fields = {}, references, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...props }) {
38
+ const { servers } = useApiContext();
39
+ const { server, setServer, setServerVariables } = useServerSelectContext();
40
+ const params = useMemo(() => {
29
41
  return {
30
- username: '',
31
- password: '',
42
+ headers: parameters.filter((v) => v.in === 'header'),
43
+ cookies: parameters.filter((v) => v.in === 'cookie'),
44
+ queries: parameters.filter((v) => v.in === 'query'),
45
+ paths: parameters.filter((v) => v.in === 'path'),
32
46
  };
33
- }
34
- return 'Bearer';
35
- }
36
- export function Client({ route, method = 'GET', authorization, path = [], header = [], query = [], body, fields = {}, schemas, proxyUrl, components: { ResultDisplay = DefaultResultDisplay } = {}, ...props }) {
37
- const { serverRef, servers } = useApiContext();
47
+ }, [parameters]);
38
48
  const dynamicRef = useRef(new Map());
49
+ const requestData = useRequestData();
50
+ const authInfo = usePersistentAuthInfo(authorization);
51
+ const defaultValues = useMemo(() => ({
52
+ authorization: authInfo.info,
53
+ path: requestData.data.path,
54
+ query: requestData.data.query,
55
+ header: requestData.data.header,
56
+ body: requestData.data.body,
57
+ cookie: requestData.data.cookie,
58
+ }), [authInfo.info, requestData.data]);
39
59
  const form = useForm({
40
- defaultValues: {
41
- authorization: defaultAuthValue(authorization),
42
- path: getDefaultValues(path, schemas),
43
- query: getDefaultValues(query, schemas),
44
- header: getDefaultValues(header, schemas),
45
- body: body ? getDefaultValue(body, schemas) : undefined,
46
- },
60
+ defaultValues,
47
61
  });
48
62
  const testQuery = useQuery(async (input) => {
49
- const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(body, schemas));
50
- const query = { ...input.query };
51
- const header = { ...input.header };
52
- if (authorization?.type === 'apiKey') {
53
- if (authorization.in === 'header') {
54
- header[authorization.name] = input.authorization;
55
- }
56
- else if (authorization.in === 'query') {
57
- query[authorization.name] = input.authorization;
58
- }
59
- else {
60
- if ('cookie' in header) {
61
- header.Cookie = header.cookie;
62
- delete header.cookie;
63
- }
64
- header.Cookie = [
65
- header.Cookie,
66
- `${authorization.name}=${input.authorization}`,
67
- ]
68
- .filter((s) => s.length > 0)
69
- .join('; ');
70
- }
71
- }
72
- else if (authorization?.type === 'http' &&
73
- authorization.scheme === 'basic') {
74
- if (typeof input.authorization === 'object')
75
- header.Authorization = `Basic ${btoa(`${input.authorization.username}:${input.authorization.password}`)}`;
76
- }
77
- else if (authorization) {
78
- header.Authorization = input.authorization;
79
- }
80
- const serverUrl = serverRef.current
81
- ? getUrl(serverRef.current.url, serverRef.current.variables)
63
+ const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher());
64
+ const serverUrl = server
65
+ ? getUrl(server.url, server.variables)
82
66
  : window.location.origin;
83
- let url = `${serverUrl}${createPathnameFromInput(route, input.path, query)}`;
84
- if (proxyUrl) {
85
- const updated = new URL(proxyUrl, window.location.origin);
86
- updated.searchParams.append('url', url);
87
- url = updated.toString();
88
- }
89
- return fetcher.fetch({
90
- url: url.toString(),
91
- header,
92
- body: body
93
- ? {
94
- mediaType: body.mediaType,
95
- value: input.body,
96
- }
97
- : undefined,
98
- dynamicFields: dynamicRef.current,
99
- method,
67
+ return fetcher.fetch(`${serverUrl}${route}`, {
68
+ proxyUrl,
69
+ ...toRequestData(method, body?.mediaType, input),
100
70
  });
101
71
  });
102
72
  useEffect(() => {
103
- if (!authorization)
104
- return;
105
- const key = `__fumadocs_auth_${JSON.stringify(authorization)}`;
106
- const cached = localStorage.getItem(key);
107
- if (cached)
108
- form.setValue('authorization', JSON.parse(cached));
109
- const subscription = form.watch((value, { name }) => {
110
- if (!name || !name.startsWith('authorization') || !value.authorization)
111
- return;
112
- localStorage.setItem(key, JSON.stringify(value.authorization));
73
+ form.reset(defaultValues);
74
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- update default value
75
+ }, [defaultValues]);
76
+ useEffect(() => {
77
+ const subscription = form.watch((_value) => {
78
+ const value = _value;
79
+ if (authorization && value.authorization) {
80
+ authInfo.saveInfo(value.authorization);
81
+ writeAuthHeader(authorization, value.authorization, value.header, value.query, value.cookie);
82
+ }
83
+ requestData.saveData(toRequestData(method, body?.mediaType, value));
113
84
  });
114
85
  return () => {
115
86
  subscription.unsubscribe();
@@ -125,60 +96,39 @@ export function Client({ route, method = 'GET', authorization, path = [], header
125
96
  }
126
97
  return (_jsx(FieldSet, { name: info.name, fieldName: fieldName, field: info }, key));
127
98
  }
128
- let authField = null;
129
- if (authorization) {
130
- authField = (_jsxs(_Fragment, { children: [renderCustomField('authorization', authorization?.type === 'http' && authorization.scheme === 'basic'
99
+ return (_jsx(FormProvider, { ...form, children: _jsx(SchemaContext.Provider, { value: useMemo(() => ({ references: references, dynamic: dynamicRef }), [references]), children: _jsx(AuthProvider, { authorization: authorization, children: _jsxs("form", { ...props, className: cn('not-prose flex flex-col gap-2 rounded-xl border p-3 shadow-md', props.className), onSubmit: onSubmit, children: [_jsx(FormHeader, { method: method, route: route, isLoading: testQuery.isLoading }), servers.length > 1 ? (_jsx(CollapsiblePanel, { title: "Server URL", children: _jsx(ServerSelect, { server: server, onServerChanged: setServer, onVariablesChanged: setServerVariables }) })) : null, params.headers.length > 0 || authorization ? (_jsxs(CollapsiblePanel, { title: "Headers", children: [authorization ? (_jsx(AuthField, { authorization: authorization })) : null, params.headers.map((field) => renderCustomField(`header.${field.name}`, field, fields.parameter, field.name))] })) : null, params.paths.length > 0 ? (_jsx(CollapsiblePanel, { title: "Path", children: params.paths.map((field) => renderCustomField(`path.${field.name}`, field, fields.parameter, field.name)) })) : null, params.queries.length > 0 ? (_jsx(CollapsiblePanel, { title: "Query", children: params.queries.map((field) => renderCustomField(`query.${field.name}`, field, fields.parameter, field.name)) })) : null, params.cookies.length > 0 ? (_jsx(CollapsiblePanel, { title: "Cookies", children: params.cookies.map((field) => renderCustomField(`cookie.${field.name}`, field, fields.parameter, field.name)) })) : null, body ? (_jsx(CollapsiblePanel, { title: "Body", children: body.type === 'object' && !fields.body ? (_jsx(ObjectInput, { field: body, fieldName: "body" })) : (renderCustomField('body', body, fields.body)) })) : null, testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }) }) }) }));
100
+ }
101
+ function AuthProvider({ authorization, children, }) {
102
+ const form = useFormContext();
103
+ if (!authorization || authorization.type !== 'oauth2')
104
+ return children;
105
+ // only the first one, so it looks simpler :)
106
+ const flow = Object.keys(authorization.flows)[0];
107
+ return (_jsx(OauthDialog, { flow: flow, scheme: authorization, setToken: (token) => form.setValue('authorization', `Bearer ${token}`), children: children }));
108
+ }
109
+ function AuthField({ authorization }) {
110
+ return (_jsxs(_Fragment, { children: [_jsx(FieldSet, { fieldName: "authorization", name: "Authorization", field: authorization?.type === 'http' && authorization.scheme === 'basic'
131
111
  ? {
132
- name: 'Authorization',
133
112
  type: 'object',
134
113
  isRequired: true,
135
114
  properties: {
136
115
  username: {
137
116
  type: 'string',
138
117
  isRequired: true,
139
- defaultValue: '',
140
118
  },
141
119
  password: {
142
120
  type: 'string',
143
121
  isRequired: true,
144
- defaultValue: '',
145
122
  },
146
123
  },
147
124
  }
148
125
  : {
149
- name: 'Authorization',
150
126
  type: 'string',
151
127
  isRequired: true,
152
128
  description: 'The Authorization access token',
153
- defaultValue: '',
154
- }, fields.auth), authorization?.type === 'oauth2' && (_jsx(OauthDialogTrigger, { type: "button", className: cn(buttonVariants({
155
- color: 'secondary',
156
- })), children: "Open" }))] }));
157
- }
158
- let children = (_jsxs("form", { ...props, className: cn('not-prose flex flex-col gap-2 rounded-xl border p-3 shadow-md', props.className), onSubmit: onSubmit, children: [_jsx(FormHeader, { method: method, route: route, isLoading: testQuery.isLoading }), servers.length > 1 ? (_jsx(CollapsiblePanel, { title: "Server URL", children: _jsx(ServerSelect, {}) })) : null, header.length > 0 || authorization ? (_jsxs(CollapsiblePanel, { title: "Headers", children: [authField, header.map((field) => renderCustomField(`header.${field.name}`, field, fields.header, field.name))] })) : null, path.length > 0 ? (_jsx(CollapsiblePanel, { title: "Path", children: path.map((field) => renderCustomField(`path.${field.name}`, field, fields.path, field.name)) })) : null, query.length > 0 ? (_jsx(CollapsiblePanel, { title: "Query", children: query.map((field) => renderCustomField(`query.${field.name}`, field, fields.query, field.name)) })) : null, body ? (_jsx(CollapsiblePanel, { title: "Body", children: body.type === 'object' && !fields.body ? (_jsx(ObjectInput, { field: body, fieldName: "body" })) : (renderCustomField('body', body, fields.body)) })) : null, testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }));
159
- if (authorization?.type === 'oauth2') {
160
- // only the first one, so it looks simpler :)
161
- const flow = Object.keys(authorization.flows)[0];
162
- children = (_jsx(OauthDialog, { flow: flow, scheme: authorization, setToken: (token) => form.setValue('authorization', `Bearer ${token}`), children: children }));
163
- }
164
- return (_jsx(FormProvider, { ...form, children: _jsx(SchemaContext.Provider, { value: useMemo(() => ({ references: schemas, dynamic: dynamicRef }), [schemas]), children: children }) }));
165
- }
166
- function createPathnameFromInput(route, path, query) {
167
- let pathname = route;
168
- for (const key of Object.keys(path)) {
169
- const paramValue = path[key];
170
- if (typeof paramValue === 'string' && paramValue.length > 0)
171
- pathname = pathname.replace(`{${key}}`, paramValue);
172
- }
173
- const searchParams = new URLSearchParams();
174
- for (const key of Object.keys(query)) {
175
- const paramValue = query[key];
176
- if (typeof paramValue === 'string' && paramValue.length > 0)
177
- searchParams.append(key, paramValue);
178
- }
179
- return searchParams.size > 0
180
- ? `${pathname}?${searchParams.toString()}`
181
- : pathname;
129
+ } }), authorization?.type === 'oauth2' && (_jsx(OauthDialogTrigger, { type: "button", className: cn(buttonVariants({
130
+ color: 'secondary',
131
+ })), children: "Open" }))] }));
182
132
  }
183
133
  function Route({ route, ...props }) {
184
134
  const segments = route.split('/').filter((part) => part.length > 0);
@@ -196,6 +146,61 @@ function DefaultResultDisplay({ data }) {
196
146
  ? data.data
197
147
  : JSON.stringify(data.data, null, 2), ...shikiOptions })) : null] }));
198
148
  }
149
+ function usePersistentAuthInfo(authorization) {
150
+ const key = authorization
151
+ ? `__fumadocs_auth_${JSON.stringify(authorization)}`
152
+ : null;
153
+ const [info, setInfo] = useState(() => {
154
+ if (!authorization || authorization.type === 'apiKey')
155
+ return '';
156
+ if (authorization.type === 'http' && authorization.scheme === 'basic') {
157
+ return {
158
+ username: '',
159
+ password: '',
160
+ };
161
+ }
162
+ return 'Bearer';
163
+ });
164
+ useEffect(() => {
165
+ if (!key)
166
+ return;
167
+ const item = localStorage.getItem(key);
168
+ if (item) {
169
+ setInfo(JSON.parse(item));
170
+ }
171
+ }, [key]);
172
+ return {
173
+ info,
174
+ saveInfo: useEffectEvent((value) => {
175
+ if (!key)
176
+ return;
177
+ localStorage.setItem(key, JSON.stringify(value));
178
+ }),
179
+ };
180
+ }
199
181
  function CollapsiblePanel({ title, children, ...props }) {
200
182
  return (_jsxs(Collapsible, { ...props, className: "border rounded-xl bg-fd-card text-fd-card-foreground overflow-hidden", children: [_jsxs(CollapsibleTrigger, { className: "group w-full inline-flex items-center gap-2 justify-between p-3 text-sm font-medium hover:bg-fd-accent", children: [title, _jsx(ChevronDown, { className: "size-4 group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-4 p-3", children: children }) })] }));
201
183
  }
184
+ function writeAuthHeader(authorization, input, header, query, cookie) {
185
+ if (authorization.type === 'apiKey') {
186
+ if (authorization.in === 'header') {
187
+ header[authorization.name] = input;
188
+ }
189
+ if (authorization.in === 'query') {
190
+ query[authorization.name] = input;
191
+ }
192
+ if (authorization.in === 'cookie') {
193
+ cookie[authorization.name] = input;
194
+ }
195
+ return;
196
+ }
197
+ if (authorization.type === 'http' &&
198
+ authorization.scheme === 'basic' &&
199
+ typeof input === 'object') {
200
+ header.Authorization = `Basic ${btoa(`${input.username}:${input.password}`)}`;
201
+ return;
202
+ }
203
+ if (typeof input === 'string') {
204
+ header.Authorization = input;
205
+ }
206
+ }
@@ -1,14 +1,6 @@
1
- import { type RequestSchema } from '../playground/index.js';
2
- import type { DynamicField } from '../playground/client.js';
3
- export interface FetchOptions {
4
- url: string;
5
- method: string;
6
- header: Record<string, unknown>;
7
- body?: {
8
- mediaType: string;
9
- value: unknown;
10
- };
11
- dynamicFields?: Map<string, DynamicField>;
1
+ import { RequestData } from '../requests/_shared.js';
2
+ export interface FetchOptions extends RequestData {
3
+ proxyUrl?: string;
12
4
  }
13
5
  export interface FetchResult {
14
6
  status: number;
@@ -16,19 +8,11 @@ export interface FetchResult {
16
8
  data: unknown;
17
9
  }
18
10
  export interface Fetcher {
19
- /**
20
- * @param input - fetch request inputs
21
- * @param dynamicFields - schema of dynamic fields, given by the playground client
22
- */
23
- fetch: (options: FetchOptions) => Promise<FetchResult>;
11
+ fetch: (route: string, options: FetchOptions) => Promise<FetchResult>;
24
12
  }
25
- /**
26
- * @param bodySchema - schema of body
27
- * @param references - defined references of schemas, needed for resolve cyclic references
28
- */
29
- export declare function createBrowserFetcher(bodySchema: RequestSchema | undefined, references: Record<string, RequestSchema>): Fetcher;
13
+ export declare function createBrowserFetcher(): Fetcher;
30
14
  /**
31
15
  * Create request body from value
32
16
  */
33
- export declare function createBodyFromValue(mediaType: string, value: unknown, schema: RequestSchema, references: Record<string, RequestSchema>, dynamicFields: Map<string, DynamicField>): Promise<string | FormData>;
17
+ export declare function createBodyFromValue(mediaType: Required<RequestData>['bodyMediaType'], value: unknown): Promise<string | FormData>;
34
18
  //# sourceMappingURL=fetcher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEhC,IAAI,CAAC,EAAE;QACL,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,aAAa,GAAG,SAAS,EACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GACxC,OAAO,CAyDT;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EACzC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GACvC,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CA2C5B"}
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACvE;AAED,wBAAgB,oBAAoB,IAAI,OAAO,CAkF9C;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,EACjD,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CAqC5B"}
@@ -1,25 +1,48 @@
1
- import { resolve } from '../playground/resolve.js';
2
- /**
3
- * @param bodySchema - schema of body
4
- * @param references - defined references of schemas, needed for resolve cyclic references
5
- */
6
- export function createBrowserFetcher(bodySchema, references) {
1
+ import { getPathnameFromInput } from '../utils/get-pathname-from-input.js';
2
+ import { js2xml } from 'xml-js';
3
+ export function createBrowserFetcher() {
7
4
  return {
8
- async fetch(options) {
5
+ async fetch(route, options) {
9
6
  const headers = new Headers();
10
- if (options.body && options.body.mediaType !== 'multipart/form-data')
11
- headers.append('Content-Type', options.body.mediaType);
12
- for (const key of Object.keys(options.header)) {
7
+ if (options.bodyMediaType &&
8
+ options.bodyMediaType !== 'multipart/form-data')
9
+ headers.append('Content-Type', options.bodyMediaType);
10
+ for (const key in options.header) {
13
11
  const paramValue = options.header[key];
14
- if (typeof paramValue === 'string' && paramValue.length > 0)
12
+ if (paramValue.length > 0)
15
13
  headers.append(key, paramValue.toString());
16
14
  }
17
- return fetch(options.url, {
15
+ const proxyUrl = options.proxyUrl
16
+ ? new URL(options.proxyUrl, window.location.origin)
17
+ : null;
18
+ if (typeof document !== 'undefined') {
19
+ for (const key in options.cookie) {
20
+ const value = options.cookie[key];
21
+ if (!value)
22
+ continue;
23
+ document.cookie = [
24
+ `${key}=${value}`,
25
+ 'HttpOnly',
26
+ proxyUrl && proxyUrl.origin !== window.location.origin
27
+ ? `domain=${proxyUrl.host}`
28
+ : false,
29
+ 'path=/',
30
+ ]
31
+ .filter(Boolean)
32
+ .join(';');
33
+ }
34
+ }
35
+ let url = getPathnameFromInput(route, options.path, options.query);
36
+ if (proxyUrl) {
37
+ proxyUrl.searchParams.append('url', url);
38
+ url = proxyUrl.toString();
39
+ }
40
+ return fetch(url, {
18
41
  method: options.method,
19
42
  cache: 'no-cache',
20
43
  headers,
21
- body: bodySchema && options.body
22
- ? await createBodyFromValue(options.body.mediaType, options.body.value, bodySchema, references, options.dynamicFields ?? new Map())
44
+ body: options.bodyMediaType && options.body
45
+ ? await createBodyFromValue(options.bodyMediaType, options.body)
23
46
  : undefined,
24
47
  signal: AbortSignal.timeout(10 * 1000),
25
48
  })
@@ -51,24 +74,22 @@ export function createBrowserFetcher(bodySchema, references) {
51
74
  /**
52
75
  * Create request body from value
53
76
  */
54
- export async function createBodyFromValue(mediaType, value, schema, references, dynamicFields) {
55
- const result = convertValue('body', value, schema, references, dynamicFields);
77
+ export async function createBodyFromValue(mediaType, value) {
56
78
  if (mediaType === 'application/json') {
57
- return JSON.stringify(result);
79
+ return JSON.stringify(value);
58
80
  }
59
81
  if (mediaType === 'application/xml') {
60
- const { js2xml } = await import('xml-js');
61
- return js2xml(result, {
82
+ return js2xml(value, {
62
83
  compact: true,
63
84
  spaces: 2,
64
85
  });
65
86
  }
66
87
  const formData = new FormData();
67
- if (typeof result !== 'object' || !result) {
68
- throw new Error(`Unsupported body type: ${typeof result}, expected: object`);
88
+ if (typeof value !== 'object' || !value) {
89
+ throw new Error(`Unsupported body type: ${typeof value}, expected: object`);
69
90
  }
70
- for (const key of Object.keys(result)) {
71
- const prop = result[key];
91
+ for (const key in value) {
92
+ const prop = value[key];
72
93
  if (typeof prop === 'object' && prop instanceof File) {
73
94
  formData.set(key, prop);
74
95
  }
@@ -83,65 +104,3 @@ export async function createBodyFromValue(mediaType, value, schema, references,
83
104
  }
84
105
  return formData;
85
106
  }
86
- /**
87
- * Convert a value (object or string) to the corresponding type of schema
88
- *
89
- * @param fieldName - field name of value
90
- * @param value - the original value
91
- * @param schema - the schema of field
92
- * @param references - schema references
93
- * @param dynamicFields - Dynamic references
94
- */
95
- function convertValue(fieldName, value, schema, references, dynamicFields) {
96
- const isEmpty = value === '' || value === undefined || value === null;
97
- if (isEmpty && schema.isRequired)
98
- return schema.type === 'boolean' ? false : '';
99
- else if (isEmpty)
100
- return undefined;
101
- if (Array.isArray(value) && schema.type === 'array') {
102
- return value.map((item, index) => convertValue(`${fieldName}.${String(index)}`, item, resolve(schema.items, references), references, dynamicFields));
103
- }
104
- if (schema.type === 'switcher') {
105
- return convertValue(fieldName, value, resolve(getDynamicFieldSchema(fieldName, dynamicFields, Object.values(schema.items).at(0)), references), references, dynamicFields);
106
- }
107
- if (typeof value === 'object' && schema.type === 'object') {
108
- const entries = Object.keys(value).map((key) => {
109
- const prop = value[key];
110
- const propFieldName = `${fieldName}.${key}`;
111
- if (key in schema.properties) {
112
- return [
113
- key,
114
- convertValue(propFieldName, prop, resolve(schema.properties[key], references), references, dynamicFields),
115
- ];
116
- }
117
- if (schema.additionalProperties) {
118
- const schema = resolve(getDynamicFieldSchema(propFieldName, dynamicFields), references);
119
- return [
120
- key,
121
- convertValue(propFieldName, prop, schema, references, dynamicFields),
122
- ];
123
- }
124
- console.warn('Could not resolve field', propFieldName, dynamicFields);
125
- return [key, prop];
126
- });
127
- return Object.fromEntries(entries);
128
- }
129
- switch (schema.type) {
130
- case 'number':
131
- return Number(value);
132
- case 'boolean':
133
- return value === 'null' ? undefined : value === 'true';
134
- case 'file':
135
- return value; // file
136
- default:
137
- return String(value);
138
- }
139
- }
140
- function getDynamicFieldSchema(name, dynamicFields, defaultValue) {
141
- const field = dynamicFields.get(name);
142
- if (field?.type === 'field')
143
- return field.schema;
144
- if (defaultValue)
145
- return defaultValue;
146
- return { type: 'null', isRequired: false };
147
- }
@@ -1,4 +1,3 @@
1
- import type { PrimitiveRequestField, RequestSchema } from '../playground/index.js';
2
- export declare function getDefaultValue(item: RequestSchema, references: Record<string, RequestSchema>): unknown;
3
- export declare function getDefaultValues(field: PrimitiveRequestField[], context: Record<string, RequestSchema>): Record<string, unknown>;
1
+ import type { ReferenceSchema, RequestSchema } from '../playground/index.js';
2
+ export declare function getDefaultValue(item: RequestSchema | ReferenceSchema, references: Record<string, RequestSchema>): unknown;
4
3
  //# sourceMappingURL=get-default-values.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-default-values.d.ts","sourceRoot":"","sources":["../../src/playground/get-default-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG/E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,EACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GACxC,OAAO,CAwBT;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,qBAAqB,EAAE,EAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GACrC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIzB"}
1
+ {"version":3,"file":"get-default-values.d.ts","sourceRoot":"","sources":["../../src/playground/get-default-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGzE,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,GAAG,eAAe,EACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GACxC,OAAO,CA2BT"}
@@ -1,5 +1,7 @@
1
1
  import { resolve } from '../playground/resolve.js';
2
2
  export function getDefaultValue(item, references) {
3
+ if (item.type === 'ref')
4
+ return getDefaultValue(resolve(item, references), references);
3
5
  if (item.type === 'object')
4
6
  return Object.fromEntries(Object.entries(item.properties).map(([key, prop]) => [
5
7
  key,
@@ -17,8 +19,10 @@ export function getDefaultValue(item, references) {
17
19
  }
18
20
  if (item.type === 'file')
19
21
  return undefined;
20
- return String(item.defaultValue);
21
- }
22
- export function getDefaultValues(field, context) {
23
- return Object.fromEntries(field.map((p) => [p.name, getDefaultValue(p, context)]));
22
+ if (item.type === 'string')
23
+ return '';
24
+ if (item.type === 'number')
25
+ return 0;
26
+ if (item.type === 'boolean')
27
+ return false;
24
28
  }
@@ -8,10 +8,11 @@ interface BaseSchema {
8
8
  description?: string;
9
9
  isRequired: boolean;
10
10
  }
11
- export type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
11
+ export type PrimitiveRequestField = BaseRequestField & PrimitiveSchema & {
12
+ in: 'cookie' | 'header' | 'query' | 'path';
13
+ };
12
14
  interface PrimitiveSchema extends BaseSchema {
13
15
  type: 'boolean' | 'string' | 'number';
14
- defaultValue: string;
15
16
  }
16
17
  export interface ReferenceSchema extends BaseSchema {
17
18
  type: 'ref';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAEjB,aAAa,EACd,MAAM,SAAS,CAAC;AAOjB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM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