fumadocs-openapi 7.0.14 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-routes.d.ts +1 -1
- package/dist/generate.d.ts +1 -1
- package/dist/playground/auth/oauth-dialog.js +2 -2
- package/dist/playground/client.d.ts +2 -2
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +18 -5
- package/dist/playground/fetcher.d.ts +1 -1
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +9 -0
- package/dist/playground/inputs.d.ts +3 -0
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +16 -1
- package/dist/{server → render}/api-page.d.ts.map +1 -1
- package/dist/render/operation/index.d.ts +1 -1
- package/dist/render/operation/index.d.ts.map +1 -1
- package/dist/render/operation/index.js +4 -2
- package/dist/requests/_shared.d.ts +8 -1
- package/dist/requests/_shared.d.ts.map +1 -1
- package/dist/requests/_shared.js +17 -0
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +4 -9
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +10 -11
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +11 -9
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +10 -10
- package/dist/server/create.d.ts +2 -3
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +5 -4
- package/dist/ui/components/input.js +1 -1
- package/dist/ui/components/select.d.ts.map +1 -1
- package/dist/ui/components/select.js +1 -1
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +5 -10
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/utils/generate-document.d.ts +1 -1
- package/dist/utils/get-pathname-from-input.d.ts.map +1 -1
- package/dist/utils/get-pathname-from-input.js +4 -0
- package/dist/utils/input-to-string.d.ts +1 -1
- package/dist/utils/input-to-string.d.ts.map +1 -1
- package/dist/utils/input-to-string.js +12 -5
- package/package.json +10 -10
- /package/dist/{server → render}/api-page.d.ts +0 -0
- /package/dist/{server → render}/api-page.js +0 -0
package/dist/build-routes.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Document } from './types.js';
|
|
2
2
|
import type { NoReference } from './utils/schema.js';
|
|
3
|
-
import type { OperationItem, WebhookItem } from './
|
|
3
|
+
import type { OperationItem, WebhookItem } from './render/api-page.js';
|
|
4
4
|
export declare const methodKeys: readonly ["get", "post", "patch", "delete", "head", "put"];
|
|
5
5
|
type Result = {
|
|
6
6
|
webhooks: (WebhookItem & {
|
package/dist/generate.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type DocumentContext } from './utils/generate-document.js';
|
|
2
2
|
import type { OperationObject, PathItemObject } from './types.js';
|
|
3
3
|
import type { NoReference } from './utils/schema.js';
|
|
4
|
-
import type { OperationItem, WebhookItem } from './
|
|
4
|
+
import type { OperationItem, WebhookItem } from './render/api-page.js';
|
|
5
5
|
import { type DocumentInput } from './utils/process-document.js';
|
|
6
6
|
export interface GenerateOptions {
|
|
7
7
|
/**
|
|
@@ -28,7 +28,7 @@ export function OauthDialog({ flow, scheme, setToken, children, }) {
|
|
|
28
28
|
redirect_uri: state.redirect_uri,
|
|
29
29
|
client_id: state.client_id,
|
|
30
30
|
client_secret: state.client_secret,
|
|
31
|
-
})
|
|
31
|
+
}),
|
|
32
32
|
});
|
|
33
33
|
if (!res.ok)
|
|
34
34
|
throw new Error(await res.text());
|
|
@@ -75,7 +75,7 @@ export function OauthDialog({ flow, scheme, setToken, children, }) {
|
|
|
75
75
|
body: new URLSearchParams({
|
|
76
76
|
grant_type: 'client_credentials',
|
|
77
77
|
scope: Object.keys(value.scopes).join('+'),
|
|
78
|
-
})
|
|
78
|
+
}),
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
1
|
+
import { type FC, type HTMLAttributes, type ReactElement, type RefObject } from 'react';
|
|
2
|
+
import type { ControllerFieldState, ControllerRenderProps, FieldPath, UseFormStateReturn } from 'react-hook-form';
|
|
3
3
|
import type { FetchResult } from '../playground/fetcher.js';
|
|
4
4
|
import type { PrimitiveRequestField, ReferenceSchema, RequestSchema } from '../playground/index.js';
|
|
5
5
|
import type { Security } from '../utils/get-security.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { createContext, Fragment, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { Controller, FormProvider, useForm, useFormContext, } from 'react-hook-form';
|
|
5
5
|
import { useApiContext, useServerSelectContext } from '../ui/contexts/api.js';
|
|
6
|
-
import { FieldSet, ObjectInput } from './inputs.js';
|
|
6
|
+
import { FieldSet, JsonInput, ObjectInput } from './inputs.js';
|
|
7
7
|
import { getStatusInfo } from './status-info.js';
|
|
8
8
|
import { getUrl } from '../utils/server-url.js';
|
|
9
9
|
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
@@ -17,6 +17,7 @@ import { useRequestData } from '../ui/contexts/code-example.js';
|
|
|
17
17
|
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
18
18
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
19
19
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
20
|
+
import { cva } from 'class-variance-authority';
|
|
20
21
|
const SchemaContext = createContext(undefined);
|
|
21
22
|
export function useSchemaContext() {
|
|
22
23
|
const ctx = useContext(SchemaContext);
|
|
@@ -82,7 +83,7 @@ export default function Client({ route, method = 'GET', authorization, parameter
|
|
|
82
83
|
const onSubmit = form.handleSubmit((value) => {
|
|
83
84
|
testQuery.start(value);
|
|
84
85
|
});
|
|
85
|
-
return (_jsx(FormProvider, { ...form, children: _jsx(SchemaContext.Provider, { value: useMemo(() => ({ references: references, dynamic: dynamicRef }), [references]), children: _jsx(AuthProvider, { authorization: authorization, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border p-3 gap-
|
|
86
|
+
return (_jsx(FormProvider, { ...form, children: _jsx(SchemaContext.Provider, { value: useMemo(() => ({ references: references, dynamic: dynamicRef }), [references]), children: _jsx(AuthProvider, { authorization: authorization, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border p-3 gap-4 shadow-md overflow-hidden bg-fd-card text-fd-card-foreground', rest.className), onSubmit: onSubmit, children: [_jsxs("div", { className: "flex flex-row items-center gap-2 text-sm", children: [_jsx(MethodLabel, { children: method }), _jsx(Route, { route: route, className: "flex-1" }), _jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5'), disabled: testQuery.isLoading, children: testQuery.isLoading ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : ('Send') })] }), _jsx(FormBody, { body: body, fields: fields, parameters: parameters, authorization: authorization }), testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }) }) }) }));
|
|
86
87
|
}
|
|
87
88
|
const paramNames = ['Headers', 'Cookies', 'Query', 'Path'];
|
|
88
89
|
const paramTypes = ['header', 'cookie', 'query', 'path'];
|
|
@@ -135,7 +136,19 @@ function FormBody({ authorization, parameters = [], body, fields = {}, }) {
|
|
|
135
136
|
}
|
|
136
137
|
return renderCustomField(fieldName, field, fields.parameter, field.name);
|
|
137
138
|
})] }, name));
|
|
138
|
-
}), body ? (_jsx(CollapsiblePanel, { title: "Body", children:
|
|
139
|
+
}), body ? (fields.body ? (_jsx(CollapsiblePanel, { title: "Body", children: renderCustomField('body', body, fields.body) })) : (_jsx(BodyInput, { field: body }))) : null] }));
|
|
140
|
+
}
|
|
141
|
+
const bodyTypeVariants = cva('p-1 rounded-lg font-medium text-xs transition-colors', {
|
|
142
|
+
variants: {
|
|
143
|
+
active: {
|
|
144
|
+
true: 'bg-fd-primary/10 text-fd-primary',
|
|
145
|
+
false: 'text-fd-muted-foreground',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
function BodyInput({ field }) {
|
|
150
|
+
const [isJson, setIsJson] = useState(false);
|
|
151
|
+
return (_jsxs(CollapsiblePanel, { title: "Body", children: [_jsxs("div", { className: "grid grid-cols-2 border bg-fd-muted rounded-lg", children: [_jsx("button", { className: cn(bodyTypeVariants({ active: !isJson })), onClick: () => setIsJson(false), type: "button", children: "Simple" }), _jsx("button", { className: cn(bodyTypeVariants({ active: isJson })), onClick: () => setIsJson(true), type: "button", children: "JSON Mode" })] }), isJson ? (_jsx(JsonInput, { fieldName: "body" })) : field.type === 'object' ? (_jsx(ObjectInput, { field: field, fieldName: "body" })) : (_jsx(FieldSet, { field: field, fieldName: "body" }))] }));
|
|
139
152
|
}
|
|
140
153
|
function renderCustomField(fieldName, info, field, key) {
|
|
141
154
|
return (_jsx(Controller, {
|
|
@@ -196,7 +209,7 @@ function usePersistentAuthInfo(authorization) {
|
|
|
196
209
|
};
|
|
197
210
|
}
|
|
198
211
|
function CollapsiblePanel({ title, children, ...props }) {
|
|
199
|
-
return (_jsxs(Collapsible, { ...props, className: "
|
|
212
|
+
return (_jsxs(Collapsible, { ...props, className: "border-b -m-2 last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-2 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-2", children: children }) })] }));
|
|
200
213
|
}
|
|
201
214
|
function writeAuthHeader(authorization, input, header, query, cookie) {
|
|
202
215
|
if (authorization.type === 'apiKey') {
|
|
@@ -14,5 +14,5 @@ export declare function createBrowserFetcher(): Fetcher;
|
|
|
14
14
|
/**
|
|
15
15
|
* Create request body from value
|
|
16
16
|
*/
|
|
17
|
-
export declare function createBodyFromValue(mediaType: Required<RequestData>['bodyMediaType'], value: unknown): Promise<
|
|
17
|
+
export declare function createBodyFromValue(mediaType: Required<RequestData>['bodyMediaType'], value: unknown): Promise<BodyInit>;
|
|
18
18
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QAAQ,CAAC,CAgDnB"}
|
|
@@ -84,6 +84,15 @@ export async function createBodyFromValue(mediaType, value) {
|
|
|
84
84
|
spaces: 2,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
if (mediaType === 'application/x-www-form-urlencoded') {
|
|
88
|
+
if (typeof value !== 'object')
|
|
89
|
+
throw new Error(`Input value must be object, received: ${typeof value}`);
|
|
90
|
+
const params = new URLSearchParams();
|
|
91
|
+
for (const key in value) {
|
|
92
|
+
params.set(key, String(value[key]));
|
|
93
|
+
}
|
|
94
|
+
return params;
|
|
95
|
+
}
|
|
87
96
|
const formData = new FormData();
|
|
88
97
|
if (typeof value !== 'object' || !value) {
|
|
89
98
|
throw new Error(`Unsupported body type: ${typeof value}, expected: object`);
|
|
@@ -7,6 +7,9 @@ export declare function ObjectInput({ field, fieldName, ...props }: {
|
|
|
7
7
|
field: FieldOfType<'object'>;
|
|
8
8
|
fieldName: string;
|
|
9
9
|
} & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function JsonInput({ fieldName }: {
|
|
11
|
+
fieldName: string;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
10
13
|
export declare function FieldInput({ field, fieldName, ...props }: HTMLAttributes<HTMLElement> & {
|
|
11
14
|
field: Exclude<RequestSchema, {
|
|
12
15
|
type: 'switcher';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQxD,KAAK,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AA6BhE,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,cAAc,CAAC,2CAqBjC;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CAuB7D;AA+ID,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB,kDAmGA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,kDAgGA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useState, } from 'react';
|
|
4
4
|
import { Plus, Trash2 } from 'lucide-react';
|
|
5
|
-
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
|
5
|
+
import { Controller, useController, useFieldArray, useFormContext, } from 'react-hook-form';
|
|
6
6
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
|
|
7
7
|
import { resolve } from '../playground/resolve.js';
|
|
8
8
|
import { Input, labelVariants } from '../ui/components/input.js';
|
|
@@ -17,6 +17,21 @@ export function ObjectInput({ field, fieldName, ...props }) {
|
|
|
17
17
|
const { references } = useSchemaContext();
|
|
18
18
|
return (_jsxs("div", { ...props, className: cn('flex flex-col gap-6', props.className), children: [Object.entries(field.properties).map(([key, child]) => (_jsx(FieldSet, { name: key, field: resolve(child, references), fieldName: `${fieldName}.${key}` }, key))), field.additionalProperties ? (_jsx(AdditionalProperties, { fieldName: fieldName, type: field.additionalProperties })) : null] }));
|
|
19
19
|
}
|
|
20
|
+
export function JsonInput({ fieldName }) {
|
|
21
|
+
const controller = useController({
|
|
22
|
+
name: fieldName,
|
|
23
|
+
});
|
|
24
|
+
const [value, setValue] = useState(() => JSON.stringify(controller.field.value, null, 2));
|
|
25
|
+
return (_jsx("textarea", { ...controller.field, value: value, className: "w-full h-[400px] resize-none rounded-lg border p-2 bg-fd-secondary text-fd-secondary-foreground focus-visible:outline-none", onChange: (v) => {
|
|
26
|
+
setValue(v.target.value);
|
|
27
|
+
try {
|
|
28
|
+
controller.field.onChange(JSON.parse(v.target.value));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// ignore
|
|
32
|
+
}
|
|
33
|
+
} }));
|
|
34
|
+
}
|
|
20
35
|
function AdditionalProperties({ fieldName, type, }) {
|
|
21
36
|
const { control, setValue, getValues } = useFormContext();
|
|
22
37
|
const { references } = useSchemaContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/render/api-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,KAAK,mBAAmB,GAAG,IAAI,CAC7B,OAAO,CAAC,aAAa,CAAC,EACpB,cAAc,GACd,0BAA0B,GAC1B,qBAAqB,GACrB,UAAU,GACV,oBAAoB,GACpB,mBAAmB,CACtB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IAEjB,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,oDA0DhD;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,mBAAmB,GAAG;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzB,GACL,OAAO,CAAC,aAAa,CAAC,CA+BxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
3
|
-
import
|
|
3
|
+
import { RequestData } from '../../requests/_shared.js';
|
|
4
4
|
export interface CodeSample {
|
|
5
5
|
lang: string;
|
|
6
6
|
label: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAC;AAEtE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EACH,MAAM,GACN,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC,GACxD,KAAK,CAAC;CACX;AASD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CA4Lf"}
|
|
@@ -10,6 +10,7 @@ import { createMethod } from '../../server/create-method.js';
|
|
|
10
10
|
import { methodKeys } from '../../build-routes.js';
|
|
11
11
|
import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
|
|
12
12
|
import { MethodLabel } from '../../ui/components/method-label.js';
|
|
13
|
+
import { supportedMediaTypes } from '../../requests/_shared.js';
|
|
13
14
|
const ParamTypes = {
|
|
14
15
|
path: 'Path Parameters',
|
|
15
16
|
query: 'Query Parameters',
|
|
@@ -30,8 +31,9 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
30
31
|
}
|
|
31
32
|
if (body) {
|
|
32
33
|
const type = getPreferredType(body.content);
|
|
33
|
-
if (!type
|
|
34
|
-
|
|
34
|
+
if (!type ||
|
|
35
|
+
!supportedMediaTypes.includes(String(type)))
|
|
36
|
+
throw new Error(`No supported media type for body content: ${path}, received: ${type}`);
|
|
35
37
|
bodyNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Request Body', ctx), _jsxs("div", { className: "mb-8 flex flex-row items-center justify-between gap-2", children: [_jsx("code", { children: type }), _jsx("span", { children: body.required ? 'Required' : 'Optional' })] }), body.description ? _jsx(Markdown, { text: body.description }) : null, _jsx(Schema, { name: "body", schema: body.content[type].schema ?? {}, ctx: {
|
|
36
38
|
readOnly: method.method === 'GET',
|
|
37
39
|
writeOnly: method.method !== 'GET',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const supportedMediaTypes: readonly ["multipart/form-data", "application/json", "application/xml", "application/x-www-form-urlencoded"];
|
|
1
2
|
export interface RequestData {
|
|
2
3
|
method: string;
|
|
3
4
|
path: Record<string, string>;
|
|
@@ -5,7 +6,13 @@ export interface RequestData {
|
|
|
5
6
|
header: Record<string, string>;
|
|
6
7
|
cookie: Record<string, string>;
|
|
7
8
|
body?: unknown;
|
|
8
|
-
bodyMediaType?:
|
|
9
|
+
bodyMediaType?: (typeof supportedMediaTypes)[number];
|
|
9
10
|
}
|
|
11
|
+
export declare const MediaTypeFormatMap: {
|
|
12
|
+
readonly 'application/json': "json";
|
|
13
|
+
readonly 'application/xml': "xml";
|
|
14
|
+
readonly 'application/x-www-form-urlencoded': "url";
|
|
15
|
+
};
|
|
10
16
|
export declare function getUrl(url: string, data: RequestData): string;
|
|
17
|
+
export declare function ident(code: string, tab?: number): string;
|
|
11
18
|
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,8GAKtB,CAAC;AAEX,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,aAAa,CAAC,EAAE,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;CACtD;AAED,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAC;AAEX,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAE7D;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,UAKlD"}
|
package/dist/requests/_shared.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { getPathnameFromInput } from '../utils/get-pathname-from-input.js';
|
|
2
|
+
export const supportedMediaTypes = [
|
|
3
|
+
'multipart/form-data',
|
|
4
|
+
'application/json',
|
|
5
|
+
'application/xml',
|
|
6
|
+
'application/x-www-form-urlencoded',
|
|
7
|
+
];
|
|
8
|
+
export const MediaTypeFormatMap = {
|
|
9
|
+
'application/json': 'json',
|
|
10
|
+
'application/xml': 'xml',
|
|
11
|
+
'application/x-www-form-urlencoded': 'url',
|
|
12
|
+
};
|
|
2
13
|
export function getUrl(url, data) {
|
|
3
14
|
return getPathnameFromInput(url, data.path, data.query);
|
|
4
15
|
}
|
|
16
|
+
export function ident(code, tab = 1) {
|
|
17
|
+
return code
|
|
18
|
+
.split('\n')
|
|
19
|
+
.map((v) => ' '.repeat(tab) + v)
|
|
20
|
+
.join('\n');
|
|
21
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAmCvE"}
|
package/dist/requests/curl.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
-
import { getUrl } from '../requests/_shared.js';
|
|
3
|
+
import { getUrl, ident, MediaTypeFormatMap, } from '../requests/_shared.js';
|
|
4
4
|
export function getSampleRequest(url, data) {
|
|
5
5
|
const s = [];
|
|
6
6
|
s.push(`curl -X ${data.method} "${getUrl(url, data)}"`);
|
|
@@ -19,14 +19,9 @@ export function getSampleRequest(url, data) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
else if (data.body) {
|
|
22
|
+
else if (data.body && data.bodyMediaType) {
|
|
23
23
|
s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
|
|
24
|
-
s.push(`-d ${inputToString(data.body, data.bodyMediaType, 'single-quote')}`);
|
|
24
|
+
s.push(`-d ${inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'single-quote')}`);
|
|
25
25
|
}
|
|
26
|
-
return s
|
|
27
|
-
.flatMap((v, i) => v
|
|
28
|
-
.split('\n')
|
|
29
|
-
.map((line) => (i > 0 ? ` ${line}` : line))
|
|
30
|
-
.join('\n'))
|
|
31
|
-
.join(' \\\n');
|
|
26
|
+
return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(' \\\n');
|
|
32
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAuEvE"}
|
package/dist/requests/go.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
-
import { getUrl } from '../requests/_shared.js';
|
|
3
|
+
import { getUrl, ident, MediaTypeFormatMap, } from '../requests/_shared.js';
|
|
4
4
|
export function getSampleRequest(url, data) {
|
|
5
5
|
const imports = ['fmt', 'net/http', 'io/ioutil'];
|
|
6
6
|
const headers = new Map();
|
|
@@ -14,37 +14,36 @@ export function getSampleRequest(url, data) {
|
|
|
14
14
|
const cookies = Object.keys(data.cookie);
|
|
15
15
|
if (cookies.length > 0)
|
|
16
16
|
headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p}=${data.cookie[p]}`).join('; ')));
|
|
17
|
-
if (data.body) {
|
|
17
|
+
if (data.body && data.bodyMediaType) {
|
|
18
18
|
headers.set('Content-Type', `"${data.bodyMediaType}"`);
|
|
19
|
-
if (data.bodyMediaType === 'multipart/form-data'
|
|
20
|
-
typeof data.body === 'object') {
|
|
19
|
+
if (data.bodyMediaType === 'multipart/form-data') {
|
|
21
20
|
imports.push('mime/multipart', 'bytes');
|
|
22
21
|
variables.set('payload', `new(bytes.Buffer)`);
|
|
23
22
|
variables.set('mp', 'multipart.NewWriter(payload)');
|
|
24
23
|
for (const [key, value] of Object.entries(data.body)) {
|
|
25
|
-
additional.push(`mp.WriteField("${key}", ${inputToString(value,
|
|
24
|
+
additional.push(`mp.WriteField("${key}", ${inputToString(value, 'json', 'backtick')})`);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
else {
|
|
29
28
|
imports.push('strings');
|
|
30
|
-
variables.set('payload', `strings.NewReader(${inputToString(data.body, data.bodyMediaType, 'backtick')
|
|
29
|
+
variables.set('payload', `strings.NewReader(${inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'backtick')})`);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
return `package main
|
|
34
33
|
|
|
35
34
|
import (
|
|
36
|
-
${imports.map((v) => `
|
|
35
|
+
${ident(imports.map((v) => `"${v}"`).join('\n'))}
|
|
37
36
|
)
|
|
38
37
|
|
|
39
38
|
func main() {
|
|
40
39
|
${Array.from(variables.entries())
|
|
41
|
-
.map(([k, v]) =>
|
|
40
|
+
.map(([k, v]) => ident(`${k} := ${v}`))
|
|
42
41
|
.join('\n')}
|
|
43
|
-
|
|
42
|
+
${ident(additional.join('\n'))}
|
|
44
43
|
req, _ := http.NewRequest("${data.method}", url, ${variables.has('payload') ? 'payload' : 'nil'})
|
|
45
|
-
|
|
44
|
+
${ident(Array.from(headers.entries())
|
|
46
45
|
.map(([key, value]) => `req.Header.Add("${key}", ${value})`)
|
|
47
|
-
.join('\n
|
|
46
|
+
.join('\n'))}
|
|
48
47
|
res, _ := http.DefaultClient.Do(req)
|
|
49
48
|
defer res.Body.Close()
|
|
50
49
|
body, _ := ioutil.ReadAll(res.Body)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAErE,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAoDvE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
-
import { getUrl } from '../requests/_shared.js';
|
|
3
|
+
import { getUrl, ident } from '../requests/_shared.js';
|
|
4
4
|
export function getSampleRequest(url, data) {
|
|
5
5
|
const s = [];
|
|
6
6
|
const options = new Map();
|
|
@@ -11,31 +11,33 @@ export function getSampleRequest(url, data) {
|
|
|
11
11
|
.join('; ');
|
|
12
12
|
}
|
|
13
13
|
if (Object.keys(headers).length > 0) {
|
|
14
|
-
options.set('headers', JSON.stringify(headers, null, 2)
|
|
14
|
+
options.set('headers', JSON.stringify(headers, null, 2));
|
|
15
15
|
}
|
|
16
|
-
if (data.bodyMediaType === 'multipart/form-data' &&
|
|
17
|
-
typeof data.body === 'object' &&
|
|
18
|
-
data.body) {
|
|
16
|
+
if (data.bodyMediaType === 'multipart/form-data' && data.body) {
|
|
19
17
|
s.push(`const formData = new FormData();`);
|
|
20
18
|
for (const [key, value] of Object.entries(data.body))
|
|
21
19
|
s.push(`formData.set(${key}, ${inputToString(value)})`);
|
|
22
20
|
options.set('body', 'formData');
|
|
23
21
|
}
|
|
22
|
+
else if (data.body &&
|
|
23
|
+
data.bodyMediaType === 'application/x-www-form-urlencoded') {
|
|
24
|
+
options.set('body', `new URLSearchParams(${JSON.stringify(data.body, null, 2)})`);
|
|
25
|
+
}
|
|
24
26
|
else if (data.body) {
|
|
25
27
|
let code;
|
|
26
28
|
if (data.bodyMediaType === 'application/json') {
|
|
27
29
|
code =
|
|
28
30
|
typeof data.body === 'string'
|
|
29
|
-
? inputToString(data.body,
|
|
31
|
+
? inputToString(data.body, 'json', 'backtick')
|
|
30
32
|
: `JSON.stringify(${JSON.stringify(data.body, null, 2)})`;
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
33
|
-
code = inputToString(data.body,
|
|
35
|
+
code = inputToString(data.body, 'xml', 'backtick');
|
|
34
36
|
}
|
|
35
|
-
options.set('body', code
|
|
37
|
+
options.set('body', code);
|
|
36
38
|
}
|
|
37
39
|
const optionsStr = Array.from(options.entries())
|
|
38
|
-
.map(([k, v]) =>
|
|
40
|
+
.map(([k, v]) => ident(`${k}: ${v}`))
|
|
39
41
|
.join(',\n');
|
|
40
42
|
s.push(`fetch(${JSON.stringify(getUrl(url, data))}, {\n${optionsStr}\n});`);
|
|
41
43
|
return s.join('\n\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAkDvE"}
|
package/dist/requests/python.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
3
|
-
import { getUrl } from '../requests/_shared.js';
|
|
3
|
+
import { getUrl, MediaTypeFormatMap, } from '../requests/_shared.js';
|
|
4
4
|
export function getSampleRequest(url, data) {
|
|
5
5
|
const variables = new Map();
|
|
6
6
|
const headers = { ...data.header };
|
|
7
|
-
if (data.body) {
|
|
7
|
+
if (data.body && data.bodyMediaType) {
|
|
8
8
|
switch (data.bodyMediaType) {
|
|
9
9
|
case 'application/json':
|
|
10
10
|
variables.set('json', JSON.stringify(data.body, null, 2));
|
|
@@ -14,9 +14,8 @@ export function getSampleRequest(url, data) {
|
|
|
14
14
|
variables.set('data', JSON.stringify(data.body, null, 2));
|
|
15
15
|
break;
|
|
16
16
|
default:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
variables.set('data', inputToString(data.body, data.bodyMediaType, 'python'));
|
|
17
|
+
headers['Content-Type'] = data.bodyMediaType;
|
|
18
|
+
variables.set('data', inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'python'));
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
if (Object.keys(headers).length > 0) {
|
|
@@ -25,17 +24,18 @@ export function getSampleRequest(url, data) {
|
|
|
25
24
|
if (Object.keys(data.cookie).length > 0) {
|
|
26
25
|
variables.set('cookies', JSON.stringify(data.cookie, null, 2));
|
|
27
26
|
}
|
|
27
|
+
const params = [
|
|
28
|
+
`"${data.method}"`,
|
|
29
|
+
'url',
|
|
30
|
+
...Array.from(variables.keys()).map((k) => `${k}=${k}`),
|
|
31
|
+
];
|
|
28
32
|
return `import requests
|
|
29
33
|
|
|
30
34
|
url = ${JSON.stringify(getUrl(url, data))}
|
|
31
35
|
${Array.from(variables.entries())
|
|
32
36
|
.map(([k, v]) => `${k} = ${v}`)
|
|
33
37
|
.join('\n')}
|
|
34
|
-
response = requests.request(
|
|
35
|
-
? `, ${Array.from(variables.keys())
|
|
36
|
-
.map((k) => `${k}=${k}`)
|
|
37
|
-
.join(', ')}`
|
|
38
|
-
: ''})
|
|
38
|
+
response = requests.request(${params.join(', ')})
|
|
39
39
|
|
|
40
40
|
print(response.text)`;
|
|
41
41
|
}
|
package/dist/server/create.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type ApiPageProps } from '../server/api-page.js';
|
|
1
|
+
import type { ApiPageProps } from '../render/api-page.js';
|
|
3
2
|
import type { DocumentInput } from '../utils/process-document.js';
|
|
4
3
|
import { createProxy } from '../server/proxy.js';
|
|
5
4
|
export interface OpenAPIOptions extends Omit<Partial<ApiPageProps>, 'document'> {
|
|
@@ -9,7 +8,7 @@ export interface OpenAPIOptions extends Omit<Partial<ApiPageProps>, 'document'>
|
|
|
9
8
|
documentOrPath?: DocumentInput;
|
|
10
9
|
}
|
|
11
10
|
export interface OpenAPIServer {
|
|
12
|
-
|
|
11
|
+
getAPIPageProps: (from: ApiPageProps) => ApiPageProps;
|
|
13
12
|
createProxy: typeof createProxy;
|
|
14
13
|
}
|
|
15
14
|
export declare function createOpenAPI(options?: OpenAPIOptions): OpenAPIServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC;IAC/C;;OAEG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,YAAY,CAAC;IACtD,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CAUzE"}
|
package/dist/server/create.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { APIPage } from '../server/api-page.js';
|
|
3
1
|
import { createProxy } from '../server/proxy.js';
|
|
4
2
|
export function createOpenAPI(options = {}) {
|
|
5
3
|
return {
|
|
6
4
|
createProxy,
|
|
7
|
-
|
|
8
|
-
return
|
|
5
|
+
getAPIPageProps(props) {
|
|
6
|
+
return {
|
|
7
|
+
...options,
|
|
8
|
+
...props,
|
|
9
|
+
};
|
|
9
10
|
},
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
4
4
|
import { cva } from 'class-variance-authority';
|
|
5
|
-
export const labelVariants = cva('text-
|
|
5
|
+
export const labelVariants = cva('text-xs font-medium text-fd-foreground/80 peer-disabled:cursor-not-allowed peer-disabled:opacity-70');
|
|
6
6
|
const Input = React.forwardRef(({ className, type, ...props }, ref) => {
|
|
7
7
|
return (_jsx("input", { type: type, className: cn('flex h-9 w-full rounded-md border bg-fd-secondary px-2 py-1.5 text-[13px] text-fd-secondary-foreground transition-colors placeholder:text-fd-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className), ref: ref, ...props }));
|
|
8
8
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../src/ui/components/select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,QAAA,MAAM,MAAM,uCAAuB,CAAC;AAEpC,QAAA,MAAM,WAAW,yGAAwB,CAAC;AAE1C,QAAA,MAAM,WAAW,0GAAwB,CAAC;AAE1C,QAAA,MAAM,aAAa,oKAiBjB,CAAC;AAGH,QAAA,MAAM,oBAAoB,qKAWxB,CAAC;AAGH,QAAA,MAAM,sBAAsB,uKAW1B,CAAC;AAIH,QAAA,MAAM,aAAa,8JAqBjB,CAAC;AAGH,QAAA,MAAM,WAAW,4JASf,CAAC;AAGH,QAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../src/ui/components/select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,QAAA,MAAM,MAAM,uCAAuB,CAAC;AAEpC,QAAA,MAAM,WAAW,yGAAwB,CAAC;AAE1C,QAAA,MAAM,WAAW,0GAAwB,CAAC;AAE1C,QAAA,MAAM,aAAa,oKAiBjB,CAAC;AAGH,QAAA,MAAM,oBAAoB,qKAWxB,CAAC;AAGH,QAAA,MAAM,sBAAsB,uKAW1B,CAAC;AAIH,QAAA,MAAM,aAAa,8JAqBjB,CAAC;AAGH,QAAA,MAAM,WAAW,4JASf,CAAC;AAGH,QAAA,MAAM,UAAU,2JAiBd,CAAC;AAGH,QAAA,MAAM,eAAe,gKASnB,CAAC;AAGH,OAAO,EACL,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,sBAAsB,GACvB,CAAC"}
|
|
@@ -17,7 +17,7 @@ const SelectContent = forwardRef(({ className, children, position, ...props }, r
|
|
|
17
17
|
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
18
18
|
const SelectLabel = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.Label, { ref: ref, className: cn('py-1.5 pe-2 ps-6 text-sm font-semibold', className), ...props })));
|
|
19
19
|
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
20
|
-
const SelectItem = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Item, { ref: ref, className: cn('flex select-none flex-row items-center rounded-md py-1.5
|
|
20
|
+
const SelectItem = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Item, { ref: ref, className: cn('flex select-none flex-row items-center rounded-md py-1.5 px-2 text-[13px] outline-none focus:bg-fd-accent focus:text-fd-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className), ...props, children: [_jsx(SelectPrimitive.ItemText, { children: children }), _jsx(SelectPrimitive.ItemIndicator, { className: "ms-auto", children: _jsx(Check, { className: "size-3.5 text-fd-primary" }) })] })));
|
|
21
21
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
22
22
|
const SelectSeparator = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.Separator, { ref: ref, className: cn('my-1 h-px bg-fd-muted', className), ...props })));
|
|
23
23
|
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAqDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAqDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAqC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,cAAc;IAUxB;;OAEG;;IAEH;;OAEG;qBArKS,WAAW,KAAK,IAAI;EA0KrC"}
|
|
@@ -54,11 +54,9 @@ export function CodeExample(props) {
|
|
|
54
54
|
const [data, setData] = useState(() => {
|
|
55
55
|
return examples.find((example) => example.key === key).data;
|
|
56
56
|
});
|
|
57
|
-
const sample =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return defaultSamples.find((item) => item.label === props.label);
|
|
61
|
-
}, [props]);
|
|
57
|
+
const sample = props.source
|
|
58
|
+
? props
|
|
59
|
+
: defaultSamples.find((item) => item.label === props.label);
|
|
62
60
|
useEffect(() => {
|
|
63
61
|
const listener = setData;
|
|
64
62
|
addListener(listener);
|
|
@@ -88,9 +86,6 @@ function SelectDisplay({ item, ...props }) {
|
|
|
88
86
|
export function useRequestData() {
|
|
89
87
|
const { examples, key, setData } = useContext(CodeExampleContext);
|
|
90
88
|
const data = useMemo(() => examples.find((example) => example.key === key).data, [examples, key]);
|
|
91
|
-
const saveData = useEffectEvent((data) => {
|
|
92
|
-
setData(data);
|
|
93
|
-
});
|
|
94
89
|
return useMemo(() => ({
|
|
95
90
|
/**
|
|
96
91
|
* initial request data
|
|
@@ -99,6 +94,6 @@ export function useRequestData() {
|
|
|
99
94
|
/**
|
|
100
95
|
* Save changes to request data, it won't trigger re-render on the component itself, which makes it safe to call in an effect with `data` as dep
|
|
101
96
|
*/
|
|
102
|
-
saveData,
|
|
103
|
-
}), [data,
|
|
97
|
+
saveData: setData,
|
|
98
|
+
}), [data, setData]);
|
|
104
99
|
}
|
package/dist/ui/index.d.ts
CHANGED
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAkB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAsBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWlE,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAkB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAsBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/ui/index.js
CHANGED
|
@@ -26,3 +26,4 @@ export function APIExample(props) {
|
|
|
26
26
|
export function ObjectCollapsible(props) {
|
|
27
27
|
return (_jsxs(Collapsible, { ...props, children: [_jsxs(CollapsibleTrigger, { className: cn(buttonVariants({ color: 'outline', size: 'sm' }), 'group rounded-full px-2 py-1.5 text-fd-muted-foreground'), children: [props.name, _jsx(ChevronDown, { className: "size-4 group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { className: "-mx-2", children: _jsx("div", { className: "flex flex-col gap-2 p-2", children: props.children }) })] }));
|
|
28
28
|
}
|
|
29
|
+
export { APIPage } from '../render/api-page.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiPageProps } from '../
|
|
1
|
+
import type { ApiPageProps } from '../render/api-page.js';
|
|
2
2
|
import type { GenerateOptions } from '../generate.js';
|
|
3
3
|
import type { Document, TagObject } from '../types.js';
|
|
4
4
|
import type { NoReference } from '../utils/schema.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-pathname-from-input.d.ts","sourceRoot":"","sources":["../../src/utils/get-pathname-from-input.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,
|
|
1
|
+
{"version":3,"file":"get-pathname-from-input.d.ts","sourceRoot":"","sources":["../../src/utils/get-pathname-from-input.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAsBR"}
|
|
@@ -4,12 +4,16 @@ export function getPathnameFromInput(url, path, query) {
|
|
|
4
4
|
const paramValue = path[key];
|
|
5
5
|
if (typeof paramValue === 'string' && paramValue.length > 0)
|
|
6
6
|
pathname = pathname.replace(`{${key}}`, paramValue);
|
|
7
|
+
else if (typeof paramValue === 'number')
|
|
8
|
+
pathname = pathname.replace(`{${key}}`, paramValue.toString());
|
|
7
9
|
}
|
|
8
10
|
const searchParams = new URLSearchParams();
|
|
9
11
|
for (const key in query) {
|
|
10
12
|
const paramValue = query[key];
|
|
11
13
|
if (typeof paramValue === 'string' && paramValue.length > 0)
|
|
12
14
|
searchParams.append(key, paramValue);
|
|
15
|
+
else if (typeof paramValue === 'number')
|
|
16
|
+
searchParams.append(key, paramValue.toString());
|
|
13
17
|
}
|
|
14
18
|
return searchParams.size > 0 ? `${pathname}?${searchParams}` : pathname;
|
|
15
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Convert input value to hardcoded string (with quotes)
|
|
3
3
|
*/
|
|
4
|
-
export declare function inputToString(value: unknown,
|
|
4
|
+
export declare function inputToString(value: unknown, format?: 'xml' | 'json' | 'url', multiLine?: 'single-quote' | 'backtick' | 'python' | 'none'): string;
|
|
5
5
|
//# sourceMappingURL=input-to-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,
|
|
1
|
+
{"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAc,EACvC,SAAS,GAAE,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAe,GAClE,MAAM,CAiCR"}
|
|
@@ -2,7 +2,7 @@ import { js2xml } from 'xml-js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Convert input value to hardcoded string (with quotes)
|
|
4
4
|
*/
|
|
5
|
-
export function inputToString(value,
|
|
5
|
+
export function inputToString(value, format = 'json', multiLine = 'none') {
|
|
6
6
|
const getStr = (v) => {
|
|
7
7
|
if (multiLine === 'none')
|
|
8
8
|
return JSON.stringify(v);
|
|
@@ -11,11 +11,18 @@ export function inputToString(value, mediaType = 'application/json', multiLine =
|
|
|
11
11
|
};
|
|
12
12
|
if (typeof value === 'string')
|
|
13
13
|
return getStr(value);
|
|
14
|
-
if (
|
|
14
|
+
if (format === 'json') {
|
|
15
15
|
return getStr(JSON.stringify(value, null, 2));
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
|
|
17
|
+
if (format === 'url') {
|
|
18
|
+
const params = new URLSearchParams();
|
|
19
|
+
if (typeof value !== 'object')
|
|
20
|
+
throw new Error(`For url encoded data, \`value\` must be an object, but received: ${typeof value}`);
|
|
21
|
+
for (const key in value) {
|
|
22
|
+
if (value[key])
|
|
23
|
+
params.set(key, String(value[key]));
|
|
24
|
+
}
|
|
25
|
+
return getStr(params.toString());
|
|
19
26
|
}
|
|
20
|
-
|
|
27
|
+
return getStr(js2xml(value, { compact: true, spaces: 2 }));
|
|
21
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@fumari/json-schema-to-typescript": "^1.1.3",
|
|
47
|
-
"@radix-ui/react-dialog": "^1.1.
|
|
48
|
-
"@radix-ui/react-select": "^2.1.
|
|
49
|
-
"@radix-ui/react-slot": "^1.
|
|
47
|
+
"@radix-ui/react-dialog": "^1.1.7",
|
|
48
|
+
"@radix-ui/react-select": "^2.1.7",
|
|
49
|
+
"@radix-ui/react-slot": "^1.2.0",
|
|
50
50
|
"@scalar/openapi-parser": "0.10.14",
|
|
51
51
|
"ajv-draft-04": "^1.0.0",
|
|
52
52
|
"class-variance-authority": "^0.7.1",
|
|
@@ -60,21 +60,21 @@
|
|
|
60
60
|
"react-hook-form": "^7.55.0",
|
|
61
61
|
"remark": "^15.0.1",
|
|
62
62
|
"remark-rehype": "^11.1.2",
|
|
63
|
-
"shiki": "^3.2.
|
|
63
|
+
"shiki": "^3.2.2",
|
|
64
64
|
"xml-js": "^1.6.11",
|
|
65
|
-
"fumadocs-core": "15.2.
|
|
66
|
-
"fumadocs-ui": "15.2.
|
|
65
|
+
"fumadocs-core": "15.2.7",
|
|
66
|
+
"fumadocs-ui": "15.2.7"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@scalar/api-client-react": "^1.2.
|
|
69
|
+
"@scalar/api-client-react": "^1.2.15",
|
|
70
70
|
"@types/js-yaml": "^4.0.9",
|
|
71
71
|
"@types/node": "22.14.0",
|
|
72
72
|
"@types/openapi-sampler": "^1.0.3",
|
|
73
73
|
"@types/react": "^19.1.0",
|
|
74
|
-
"next": "15.
|
|
74
|
+
"next": "15.3.0",
|
|
75
75
|
"openapi-types": "^12.1.3",
|
|
76
76
|
"tailwindcss": "^4.1.3",
|
|
77
|
-
"tsc-alias": "^1.8.
|
|
77
|
+
"tsc-alias": "^1.8.15",
|
|
78
78
|
"eslint-config-custom": "0.0.0",
|
|
79
79
|
"tsconfig": "0.0.0"
|
|
80
80
|
},
|
|
File without changes
|
|
File without changes
|