fumadocs-openapi 6.0.1 → 6.0.3

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 (155) hide show
  1. package/dist/build-routes.d.ts +15 -0
  2. package/dist/build-routes.d.ts.map +1 -0
  3. package/dist/build-routes.js +38 -0
  4. package/dist/generate-file.d.ts +38 -0
  5. package/dist/generate-file.d.ts.map +1 -0
  6. package/dist/generate-file.js +118 -0
  7. package/dist/generate.d.ts +48 -0
  8. package/dist/generate.d.ts.map +1 -0
  9. package/dist/generate.js +129 -0
  10. package/dist/index.d.ts +4 -274
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +3 -389
  13. package/dist/render/codeblock.d.ts +9 -0
  14. package/dist/render/codeblock.d.ts.map +1 -0
  15. package/dist/render/codeblock.js +13 -0
  16. package/dist/render/heading.d.ts +4 -0
  17. package/dist/render/heading.d.ts.map +1 -0
  18. package/dist/render/heading.js +6 -0
  19. package/dist/render/markdown.d.ts +5 -0
  20. package/dist/render/markdown.d.ts.map +1 -0
  21. package/dist/render/markdown.js +25 -0
  22. package/dist/render/operation.d.ts +17 -0
  23. package/dist/render/operation.d.ts.map +1 -0
  24. package/dist/render/operation.js +230 -0
  25. package/dist/render/playground.d.ts +66 -0
  26. package/dist/render/playground.d.ts.map +1 -0
  27. package/dist/render/playground.js +181 -0
  28. package/dist/render/renderer.d.ts +76 -0
  29. package/dist/render/renderer.d.ts.map +1 -0
  30. package/dist/render/renderer.js +23 -0
  31. package/dist/render/schema.d.ts +29 -0
  32. package/dist/render/schema.d.ts.map +1 -0
  33. package/dist/render/schema.js +151 -0
  34. package/dist/requests/curl.d.ts +3 -0
  35. package/dist/requests/curl.d.ts.map +1 -0
  36. package/dist/requests/curl.js +33 -0
  37. package/dist/requests/go.d.ts +3 -0
  38. package/dist/requests/go.d.ts.map +1 -0
  39. package/dist/requests/go.js +54 -0
  40. package/dist/requests/javascript.d.ts +3 -0
  41. package/dist/requests/javascript.d.ts.map +1 -0
  42. package/dist/requests/javascript.js +49 -0
  43. package/dist/requests/python.d.ts +3 -0
  44. package/dist/requests/python.d.ts.map +1 -0
  45. package/dist/requests/python.js +45 -0
  46. package/dist/scalar/client.d.ts +6 -0
  47. package/dist/scalar/client.d.ts.map +1 -0
  48. package/dist/scalar/client.js +25 -0
  49. package/dist/scalar/index.d.ts +4 -173
  50. package/dist/scalar/index.d.ts.map +1 -0
  51. package/dist/scalar/index.js +4 -11
  52. package/dist/server/api-page.d.ts +33 -0
  53. package/dist/server/api-page.d.ts.map +1 -0
  54. package/dist/server/api-page.js +59 -0
  55. package/dist/server/create-method.d.ts +7 -0
  56. package/dist/server/create-method.d.ts.map +1 -0
  57. package/dist/server/create-method.js +12 -0
  58. package/dist/server/create.d.ts +16 -0
  59. package/dist/server/create.d.ts.map +1 -0
  60. package/dist/server/create.js +11 -0
  61. package/dist/server/index.d.ts +3 -221
  62. package/dist/server/index.d.ts.map +1 -0
  63. package/dist/server/index.js +2 -1493
  64. package/dist/server/proxy.d.ts +8 -0
  65. package/dist/server/proxy.d.ts.map +1 -0
  66. package/dist/server/proxy.js +53 -0
  67. package/dist/server/source-api.d.ts +8 -0
  68. package/dist/server/source-api.d.ts.map +1 -0
  69. package/dist/server/source-api.js +34 -0
  70. package/dist/types.d.ts +60 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +1 -0
  73. package/dist/ui/client.d.ts +22 -0
  74. package/dist/ui/client.d.ts.map +1 -0
  75. package/dist/ui/client.js +10 -0
  76. package/dist/ui/components/input.d.ts +6 -0
  77. package/dist/ui/components/input.d.ts.map +1 -0
  78. package/dist/ui/components/input.js +10 -0
  79. package/dist/ui/components/method-label.d.ts +5 -0
  80. package/dist/ui/components/method-label.d.ts.map +1 -0
  81. package/dist/ui/components/method-label.js +33 -0
  82. package/dist/ui/components/select.d.ts +14 -0
  83. package/dist/ui/components/select.d.ts.map +1 -0
  84. package/dist/ui/components/select.js +24 -0
  85. package/dist/ui/components/variants.d.ts +6 -0
  86. package/dist/ui/components/variants.d.ts.map +1 -0
  87. package/dist/ui/components/variants.js +26 -0
  88. package/dist/ui/contexts/api.d.ts +28 -0
  89. package/dist/ui/contexts/api.d.ts.map +1 -0
  90. package/dist/ui/contexts/api.js +74 -0
  91. package/dist/ui/contexts/schema.d.ts +17 -0
  92. package/dist/ui/contexts/schema.d.ts.map +1 -0
  93. package/dist/ui/contexts/schema.js +8 -0
  94. package/dist/ui/index.d.ts +12 -302
  95. package/dist/ui/index.d.ts.map +1 -0
  96. package/dist/ui/index.js +18 -98
  97. package/dist/ui/playground/fetcher.d.ts +34 -0
  98. package/dist/ui/playground/fetcher.d.ts.map +1 -0
  99. package/dist/ui/{fetcher-CsHhplmD.js → playground/fetcher.js} +45 -44
  100. package/dist/ui/playground/get-default-values.d.ts +4 -0
  101. package/dist/ui/playground/get-default-values.d.ts.map +1 -0
  102. package/dist/ui/playground/get-default-values.js +24 -0
  103. package/dist/ui/playground/index.d.ts +44 -0
  104. package/dist/ui/playground/index.d.ts.map +1 -0
  105. package/dist/ui/playground/index.js +187 -0
  106. package/dist/ui/playground/inputs.d.ts +23 -0
  107. package/dist/ui/playground/inputs.d.ts.map +1 -0
  108. package/dist/ui/playground/inputs.js +172 -0
  109. package/dist/ui/playground/resolve.d.ts +6 -0
  110. package/dist/ui/playground/resolve.d.ts.map +1 -0
  111. package/dist/ui/playground/resolve.js +14 -0
  112. package/dist/ui/playground/status-info.d.ts +8 -0
  113. package/dist/ui/playground/status-info.d.ts.map +1 -0
  114. package/dist/ui/playground/status-info.js +40 -0
  115. package/dist/ui/server-select.d.ts +3 -0
  116. package/dist/ui/server-select.d.ts.map +1 -0
  117. package/dist/ui/server-select.js +27 -0
  118. package/dist/utils/combine-schema.d.ts +6 -0
  119. package/dist/utils/combine-schema.d.ts.map +1 -0
  120. package/dist/utils/combine-schema.js +46 -0
  121. package/dist/utils/generate-document.d.ts +20 -0
  122. package/dist/utils/generate-document.d.ts.map +1 -0
  123. package/dist/utils/generate-document.js +82 -0
  124. package/dist/utils/generate-sample.d.ts +33 -0
  125. package/dist/utils/generate-sample.d.ts.map +1 -0
  126. package/dist/utils/generate-sample.js +97 -0
  127. package/dist/utils/get-security.d.ts +8 -0
  128. package/dist/utils/get-security.d.ts.map +1 -0
  129. package/dist/utils/get-security.js +23 -0
  130. package/dist/utils/get-typescript-schema.d.ts +4 -0
  131. package/dist/utils/get-typescript-schema.d.ts.map +1 -0
  132. package/dist/utils/get-typescript-schema.js +18 -0
  133. package/dist/utils/id-to-title.d.ts +2 -0
  134. package/dist/utils/id-to-title.d.ts.map +1 -0
  135. package/dist/utils/id-to-title.js +17 -0
  136. package/dist/utils/input-to-string.d.ts +5 -0
  137. package/dist/utils/input-to-string.d.ts.map +1 -0
  138. package/dist/utils/input-to-string.js +21 -0
  139. package/dist/utils/process-document.d.ts +14 -0
  140. package/dist/utils/process-document.d.ts.map +1 -0
  141. package/dist/utils/process-document.js +32 -0
  142. package/dist/utils/schema.d.ts +9 -0
  143. package/dist/utils/schema.d.ts.map +1 -0
  144. package/dist/utils/schema.js +16 -0
  145. package/dist/utils/server-url.d.ts +2 -0
  146. package/dist/utils/server-url.d.ts.map +1 -0
  147. package/dist/utils/server-url.js +7 -0
  148. package/dist/utils/use-query.d.ts +6 -0
  149. package/dist/utils/use-query.d.ts.map +1 -0
  150. package/dist/utils/use-query.js +22 -0
  151. package/package.json +8 -8
  152. package/dist/scalar/client-client-BXAjVueF.js +0 -93
  153. package/dist/ui/client-client-CYO00OiB.js +0 -107
  154. package/dist/ui/index-client-BUeWwFWK.js +0 -1116
  155. package/dist/ui/server-select-client-Ct_HJ46K.js +0 -86
@@ -1,302 +1,12 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
- import { ReactNode, ComponentType, RefObject, ReactElement, HTMLAttributes } from 'react';
4
- import { OpenAPIV3_1 } from 'openapi-types';
5
- import Slugger from 'github-slugger';
6
- import { CodeToHastOptionsCommon, CodeOptionsThemes, BuiltinTheme } from 'shiki';
7
- import { FieldPath, ControllerRenderProps, ControllerFieldState, UseFormStateReturn } from 'react-hook-form';
8
-
9
- type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
10
- [K in keyof T]: NoReference<T[K]>;
11
- } : T;
12
- type ParsedSchema = OpenAPIV3_1.SchemaObject;
13
-
14
- /**
15
- * Sample info of endpoint
16
- */
17
- interface EndpointSample {
18
- /**
19
- * Request URL, including path and query parameters
20
- */
21
- url: string;
22
- method: string;
23
- body?: {
24
- schema: ParsedSchema;
25
- mediaType: string;
26
- sample: unknown;
27
- };
28
- responses: Record<string, ResponseSample>;
29
- parameters: ParameterSample[];
30
- }
31
- interface ResponseSample {
32
- mediaType: string;
33
- sample: unknown;
34
- schema: ParsedSchema;
35
- }
36
- interface ParameterSample {
37
- name: string;
38
- in: string;
39
- schema: ParsedSchema;
40
- sample: unknown;
41
- }
42
-
43
- interface CodeSample {
44
- lang: string;
45
- label: string;
46
- source: string | ((endpoint: EndpointSample) => string | undefined) | false;
47
- }
48
-
49
- type ProcessedDocument = {
50
- document: NoReference<Document>;
51
- dereferenceMap: DereferenceMap;
52
- downloaded: Document;
53
- };
54
-
55
- type Document = OpenAPIV3_1.Document;
56
- type OperationObject = OpenAPIV3_1.OperationObject;
57
- type SecuritySchemeObject = OpenAPIV3_1.SecuritySchemeObject;
58
- type ReferenceObject = OpenAPIV3_1.ReferenceObject;
59
- type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
60
- type MethodInformation = NoReference<OperationObject> & {
61
- method: string;
62
- };
63
- type Awaitable<T> = T | Promise<T>;
64
- /**
65
- * Dereferenced value and its original `$ref` value
66
- */
67
- type DereferenceMap = Map<unknown, string>;
68
- interface RenderContext {
69
- /**
70
- * The url of proxy to avoid CORS issues
71
- */
72
- proxyUrl?: string;
73
- renderer: Renderer;
74
- baseUrl: string;
75
- servers: ServerObject[];
76
- slugger: Slugger;
77
- /**
78
- * dereferenced schema
79
- */
80
- schema: ProcessedDocument;
81
- /**
82
- * Generate TypeScript definitions from response schema.
83
- *
84
- * Pass `false` to disable it.
85
- *
86
- * @param endpoint - the API endpoint
87
- * @param code - status code
88
- */
89
- generateTypeScriptSchema?: ((endpoint: EndpointSample, code: string) => Awaitable<string>) | false;
90
- /**
91
- * Generate code samples for endpoint.
92
- */
93
- generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
94
- shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
95
- /**
96
- * Show full response schema instead of only example response & Typescript definitions
97
- */
98
- showResponseSchema?: boolean;
99
- }
100
-
101
- type Security = SecuritySchemeObject & {
102
- scopes: string[];
103
- };
104
-
105
- interface BaseRequestField {
106
- name: string;
107
- description?: string;
108
- }
109
- interface BaseSchema {
110
- description?: string;
111
- isRequired: boolean;
112
- }
113
- type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
114
- interface PrimitiveSchema extends BaseSchema {
115
- type: 'boolean' | 'string' | 'number';
116
- defaultValue: string;
117
- }
118
- interface ReferenceSchema extends BaseSchema {
119
- type: 'ref';
120
- schema: string;
121
- }
122
- interface ArraySchema extends BaseSchema {
123
- type: 'array';
124
- /**
125
- * Reference to item schema or the schema
126
- */
127
- items: string | RequestSchema;
128
- }
129
- interface FileSchema extends BaseSchema {
130
- type: 'file';
131
- }
132
- interface ObjectSchema extends BaseSchema {
133
- type: 'object';
134
- properties: Record<string, RequestSchema | ReferenceSchema>;
135
- /**
136
- * Reference to schema, or true if it's `any`
137
- */
138
- additionalProperties?: boolean | string;
139
- }
140
- interface SwitcherSchema extends BaseSchema {
141
- type: 'switcher';
142
- items: Record<string, ReferenceSchema | RequestSchema>;
143
- }
144
- interface NullSchema extends BaseSchema {
145
- type: 'null';
146
- }
147
- type RequestSchema = PrimitiveSchema | ArraySchema | ObjectSchema | SwitcherSchema | NullSchema | FileSchema;
148
- interface APIPlaygroundProps {
149
- route: string;
150
- method: string;
151
- authorization?: Security;
152
- path?: PrimitiveRequestField[];
153
- query?: PrimitiveRequestField[];
154
- header?: PrimitiveRequestField[];
155
- body?: RequestSchema & {
156
- mediaType: string;
157
- };
158
- schemas: Record<string, RequestSchema>;
159
- proxyUrl?: string;
160
- }
161
-
162
- interface ResponsesProps {
163
- items: string[];
164
- children: ReactNode;
165
- }
166
- interface ResponseProps {
167
- value: string;
168
- children: ReactNode;
169
- }
170
- interface APIInfoProps {
171
- method: string;
172
- route: string;
173
- head: ReactNode;
174
- children: ReactNode;
175
- }
176
- interface PropertyProps {
177
- name: string;
178
- type: string;
179
- required?: boolean;
180
- deprecated?: boolean;
181
- children?: ReactNode;
182
- }
183
- interface ObjectCollapsibleProps {
184
- name: string;
185
- children: ReactNode;
186
- }
187
- interface RequestProps {
188
- language: string;
189
- name: string;
190
- code: string;
191
- }
192
- interface ResponseTypeProps {
193
- lang: string;
194
- code: string;
195
- label: string;
196
- }
197
- interface RootProps {
198
- baseUrl?: string;
199
- servers: ServerObject[];
200
- children: ReactNode;
201
- }
202
- interface Renderer {
203
- Root: ComponentType<RootProps>;
204
- API: ComponentType<{
205
- children: ReactNode;
206
- }>;
207
- APIInfo: ComponentType<APIInfoProps>;
208
- APIExample: ComponentType<{
209
- children: ReactNode;
210
- }>;
211
- Responses: ComponentType<ResponsesProps>;
212
- Response: ComponentType<ResponseProps>;
213
- Requests: ComponentType<{
214
- items: string[];
215
- children: ReactNode;
216
- }>;
217
- Request: ComponentType<RequestProps>;
218
- ResponseTypes: ComponentType<{
219
- children: ReactNode;
220
- }>;
221
- ResponseType: ComponentType<ResponseTypeProps>;
222
- /**
223
- * Collapsible to show object schemas
224
- */
225
- ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
226
- Property: ComponentType<PropertyProps>;
227
- APIPlayground: ComponentType<{
228
- path: string;
229
- method: MethodInformation;
230
- ctx: RenderContext;
231
- }>;
232
- }
233
-
234
- interface SchemaContextType {
235
- references: Record<string, RequestSchema>;
236
- dynamic: RefObject<Map<string, DynamicField>>;
237
- }
238
- type DynamicField = {
239
- type: 'object';
240
- properties: string[];
241
- } | {
242
- type: 'field';
243
- schema: RequestSchema | ReferenceSchema;
244
- };
245
- declare function useSchemaContext(): SchemaContextType;
246
-
247
- interface FetchResult {
248
- status: number;
249
- type: 'json' | 'html' | 'text';
250
- data: unknown;
251
- }
252
-
253
- interface FormValues {
254
- authorization: string | {
255
- username: string;
256
- password: string;
257
- };
258
- path: Record<string, unknown>;
259
- query: Record<string, unknown>;
260
- header: Record<string, unknown>;
261
- body: unknown;
262
- }
263
- interface CustomField<TName extends FieldPath<FormValues>, Info> {
264
- render: (props: {
265
- /**
266
- * Field Info
267
- */
268
- info: Info;
269
- field: ControllerRenderProps<FormValues, TName>;
270
- fieldState: ControllerFieldState;
271
- formState: UseFormStateReturn<FormValues>;
272
- }) => ReactElement;
273
- }
274
-
275
- declare const APIPlayground: react.ComponentType<APIPlaygroundProps & {
276
- fields?: {
277
- auth?: CustomField<"authorization", RequestSchema>;
278
- path?: CustomField<`path.${string}`, PrimitiveRequestField>;
279
- query?: CustomField<`query.${string}`, PrimitiveRequestField>;
280
- header?: CustomField<`header.${string}`, PrimitiveRequestField>;
281
- body?: CustomField<"body", RequestSchema>;
282
- };
283
- components?: Partial<{
284
- ResultDisplay: react.FC<{
285
- data: FetchResult;
286
- }>;
287
- }>;
288
- } & HTMLAttributes<HTMLFormElement>>;
289
- declare function Root({ children, baseUrl, className, shikiOptions, servers, ...props }: RootProps & {
290
- shikiOptions: RenderContext['shikiOptions'];
291
- } & HTMLAttributes<HTMLDivElement>): ReactNode;
292
-
293
- declare function APIInfo({ className, ...props }: HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element;
294
- declare function API({ children, ...props }: HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element;
295
- declare function Property({ name, type, required, deprecated, children, }: PropertyProps): react_jsx_runtime.JSX.Element;
296
- declare function APIExample(props: HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element;
297
- declare function ObjectCollapsible(props: {
298
- name: string;
299
- children: ReactNode;
300
- }): react_jsx_runtime.JSX.Element;
301
-
302
- export { API, APIExample, APIInfo, APIPlayground, ObjectCollapsible, Property, Root, useSchemaContext };
1
+ import { type HTMLAttributes, type ReactNode } from 'react';
2
+ import type { PropertyProps } from '../render/renderer.js';
3
+ export { Root, useSchemaContext, APIPlayground } from './client.js';
4
+ export declare function APIInfo({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
5
+ export declare function API({ children, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
6
+ export declare function Property({ name, type, required, deprecated, children, }: PropertyProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function APIExample(props: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
8
+ export declare function ObjectCollapsible(props: {
9
+ name: string;
10
+ children: ReactNode;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQvD,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjE,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,2CAoBf;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"}
package/dist/ui/index.js CHANGED
@@ -1,104 +1,24 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { cn, buttonVariants } from 'fumadocs-ui/components/api';
3
- import { cva } from 'class-variance-authority';
4
- import { Collapsible, CollapsibleTrigger, CollapsibleContent } from 'fumadocs-ui/components/ui/collapsible';
5
- export { A as APIPlayground, R as Root, u as useSchemaContext } from './client-client-CYO00OiB.js';
6
- import { C as ChevronDown } from './index-client-BUeWwFWK.js';
7
-
8
- const badgeVariants = cva('rounded-xl border px-1.5 py-1 text-xs font-medium leading-[12px]', {
9
- variants: {
10
- color: {
11
- green: 'bg-green-400/20 text-green-600 dark:text-green-400',
12
- yellow: 'bg-yellow-400/20 text-yellow-600 dark:text-yellow-400',
13
- red: 'bg-red-400/20 text-red-600 dark:text-red-400',
14
- blue: 'bg-blue-400/20 text-blue-600 dark:text-blue-400',
15
- orange: 'bg-orange-400/20 text-orange-600 dark:text-orange-400'
16
- }
17
- }
18
- });
19
-
20
- function APIInfo({ className, ...props }) {
21
- return /*#__PURE__*/ jsx("div", {
22
- className: cn('min-w-0 flex-1', className),
23
- ...props,
24
- children: props.children
25
- });
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { buttonVariants, cn } from 'fumadocs-ui/components/api';
3
+ import { badgeVariants } from '../ui/components/variants.js';
4
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
5
+ import { ChevronDown } from 'lucide-react';
6
+ export { Root, useSchemaContext, APIPlayground } from './client.js';
7
+ export function APIInfo({ className, ...props }) {
8
+ return (_jsx("div", { className: cn('min-w-0 flex-1', className), ...props, children: props.children }));
26
9
  }
27
- function API({ children, ...props }) {
28
- return /*#__PURE__*/ jsx("div", {
29
- ...props,
30
- className: cn('flex flex-col gap-x-6 gap-y-4 xl:flex-row xl:items-start', props.className),
31
- style: {
10
+ export function API({ children, ...props }) {
11
+ return (_jsx("div", { ...props, className: cn('flex flex-col gap-x-6 gap-y-4 xl:flex-row xl:items-start', props.className), style: {
32
12
  '--fd-api-info-top': 'calc(var(--fd-nav-height) + var(--fd-banner-height) + var(--fd-tocnav-height, 0px))',
33
- ...props.style
34
- },
35
- children: children
36
- });
13
+ ...props.style,
14
+ }, children: children }));
37
15
  }
38
- function Property({ name, type, required, deprecated, children }) {
39
- return /*#__PURE__*/ jsxs("div", {
40
- className: "rounded-xl border bg-fd-card p-3 prose-no-margin",
41
- children: [
42
- /*#__PURE__*/ jsxs("div", {
43
- className: "flex flex-row flex-wrap items-center gap-4",
44
- children: [
45
- /*#__PURE__*/ jsx("code", {
46
- children: name
47
- }),
48
- required ? /*#__PURE__*/ jsx("div", {
49
- className: cn(badgeVariants({
50
- color: 'red'
51
- })),
52
- children: "Required"
53
- }) : null,
54
- deprecated ? /*#__PURE__*/ jsx("div", {
55
- className: cn(badgeVariants({
56
- color: 'yellow'
57
- })),
58
- children: "Deprecated"
59
- }) : null,
60
- /*#__PURE__*/ jsx("span", {
61
- className: "ms-auto text-xs font-mono text-fd-muted-foreground",
62
- children: type
63
- })
64
- ]
65
- }),
66
- children
67
- ]
68
- });
16
+ export function Property({ name, type, required, deprecated, children, }) {
17
+ return (_jsxs("div", { className: "rounded-xl border bg-fd-card p-3 prose-no-margin", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-center gap-4", children: [_jsx("code", { children: name }), required ? (_jsx("div", { className: cn(badgeVariants({ color: 'red' })), children: "Required" })) : null, deprecated ? (_jsx("div", { className: cn(badgeVariants({ color: 'yellow' })), children: "Deprecated" })) : null, _jsx("span", { className: "ms-auto text-xs font-mono text-fd-muted-foreground", children: type })] }), children] }));
69
18
  }
70
- function APIExample(props) {
71
- return /*#__PURE__*/ jsx("div", {
72
- ...props,
73
- className: cn('prose-no-margin md:sticky md:top-[var(--fd-api-info-top)] xl:w-[400px]', props.className),
74
- children: props.children
75
- });
19
+ export function APIExample(props) {
20
+ return (_jsx("div", { ...props, className: cn('prose-no-margin md:sticky md:top-[var(--fd-api-info-top)] xl:w-[400px]', props.className), children: props.children }));
76
21
  }
77
- function ObjectCollapsible(props) {
78
- return /*#__PURE__*/ jsxs(Collapsible, {
79
- ...props,
80
- children: [
81
- /*#__PURE__*/ jsxs(CollapsibleTrigger, {
82
- className: cn(buttonVariants({
83
- color: 'outline',
84
- size: 'sm'
85
- }), 'group rounded-full px-2 py-1.5 text-fd-muted-foreground'),
86
- children: [
87
- props.name,
88
- /*#__PURE__*/ jsx(ChevronDown, {
89
- className: "size-4 group-data-[state=open]:rotate-180"
90
- })
91
- ]
92
- }),
93
- /*#__PURE__*/ jsx(CollapsibleContent, {
94
- className: "-mx-2",
95
- children: /*#__PURE__*/ jsx("div", {
96
- className: "flex flex-col gap-2 p-2",
97
- children: props.children
98
- })
99
- })
100
- ]
101
- });
22
+ export function ObjectCollapsible(props) {
23
+ 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 }) })] }));
102
24
  }
103
-
104
- export { API, APIExample, APIInfo, ObjectCollapsible, Property };
@@ -0,0 +1,34 @@
1
+ import { type RequestSchema } from '../../render/playground.js';
2
+ import { type DynamicField } from '../../ui/contexts/schema.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>;
12
+ }
13
+ export interface FetchResult {
14
+ status: number;
15
+ type: 'json' | 'html' | 'text';
16
+ data: unknown;
17
+ }
18
+ 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>;
24
+ }
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;
30
+ /**
31
+ * Create request body from value
32
+ */
33
+ export declare function createBodyFromValue(mediaType: string, value: unknown, schema: RequestSchema, references: Record<string, RequestSchema>, dynamicFields: Map<string, DynamicField>): Promise<string | FormData>;
34
+ //# sourceMappingURL=fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../src/ui/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,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,53 +1,57 @@
1
- import { r as resolve } from './index-client-BUeWwFWK.js';
2
-
1
+ import { resolve } from '../../ui/playground/resolve.js';
3
2
  /**
4
3
  * @param bodySchema - schema of body
5
4
  * @param references - defined references of schemas, needed for resolve cyclic references
6
- */ function createBrowserFetcher(bodySchema, references) {
5
+ */
6
+ export function createBrowserFetcher(bodySchema, references) {
7
7
  return {
8
- async fetch (options) {
8
+ async fetch(options) {
9
9
  const headers = new Headers();
10
- if (options.body && options.body.mediaType !== 'multipart/form-data') headers.append('Content-Type', options.body.mediaType);
11
- for (const key of Object.keys(options.header)){
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)) {
12
13
  const paramValue = options.header[key];
13
- if (typeof paramValue === 'string' && paramValue.length > 0) headers.append(key, paramValue.toString());
14
+ if (typeof paramValue === 'string' && paramValue.length > 0)
15
+ headers.append(key, paramValue.toString());
14
16
  }
15
17
  return fetch(options.url, {
16
18
  method: options.method,
17
19
  cache: 'no-cache',
18
20
  headers,
19
- body: bodySchema && options.body ? await createBodyFromValue(options.body.mediaType, options.body.value, bodySchema, references, options.dynamicFields ?? new Map()) : undefined,
20
- signal: AbortSignal.timeout(10 * 1000)
21
- }).then(async (res)=>{
21
+ body: bodySchema && options.body
22
+ ? await createBodyFromValue(options.body.mediaType, options.body.value, bodySchema, references, options.dynamicFields ?? new Map())
23
+ : undefined,
24
+ signal: AbortSignal.timeout(10 * 1000),
25
+ })
26
+ .then(async (res) => {
22
27
  const contentType = res.headers.get('Content-Type') ?? '';
23
28
  let type;
24
29
  let data;
25
30
  if (contentType.startsWith('application/json')) {
26
31
  type = 'json';
27
32
  data = await res.json();
28
- } else {
33
+ }
34
+ else {
29
35
  type = contentType.startsWith('text/html') ? 'html' : 'text';
30
36
  data = await res.text();
31
37
  }
32
- return {
33
- status: res.status,
34
- type,
35
- data
36
- };
37
- }).catch((e)=>{
38
+ return { status: res.status, type, data };
39
+ })
40
+ .catch((e) => {
38
41
  const message = e instanceof Error ? `[${e.name}] ${e.message}` : e.toString();
39
42
  return {
40
43
  status: 400,
41
44
  type: 'text',
42
- data: `Client side error: ${message}`
45
+ data: `Client side error: ${message}`,
43
46
  };
44
47
  });
45
- }
48
+ },
46
49
  };
47
50
  }
48
51
  /**
49
52
  * Create request body from value
50
- */ async function createBodyFromValue(mediaType, value, schema, references, dynamicFields) {
53
+ */
54
+ export async function createBodyFromValue(mediaType, value, schema, references, dynamicFields) {
51
55
  const result = convertValue('body', value, schema, references, dynamicFields);
52
56
  if (mediaType === 'application/json') {
53
57
  return JSON.stringify(result);
@@ -56,20 +60,20 @@ import { r as resolve } from './index-client-BUeWwFWK.js';
56
60
  const { js2xml } = await import('xml-js');
57
61
  return js2xml(result, {
58
62
  compact: true,
59
- spaces: 2
63
+ spaces: 2,
60
64
  });
61
65
  }
62
66
  const formData = new FormData();
63
67
  if (typeof result !== 'object' || !result) {
64
68
  throw new Error(`Unsupported body type: ${typeof result}, expected: object`);
65
69
  }
66
- for (const key of Object.keys(result)){
70
+ for (const key of Object.keys(result)) {
67
71
  const prop = result[key];
68
72
  if (typeof prop === 'object' && prop instanceof File) {
69
73
  formData.set(key, prop);
70
74
  }
71
- if (Array.isArray(prop) && prop.every((item)=>item instanceof File)) {
72
- for (const item of prop){
75
+ if (Array.isArray(prop) && prop.every((item) => item instanceof File)) {
76
+ for (const item of prop) {
73
77
  formData.append(key, item);
74
78
  }
75
79
  }
@@ -87,42 +91,42 @@ import { r as resolve } from './index-client-BUeWwFWK.js';
87
91
  * @param schema - the schema of field
88
92
  * @param references - schema references
89
93
  * @param dynamicFields - Dynamic references
90
- */ function convertValue(fieldName, value, schema, references, dynamicFields) {
94
+ */
95
+ function convertValue(fieldName, value, schema, references, dynamicFields) {
91
96
  const isEmpty = value === '' || value === undefined || value === null;
92
- if (isEmpty && schema.isRequired) return schema.type === 'boolean' ? false : '';
93
- else if (isEmpty) return undefined;
97
+ if (isEmpty && schema.isRequired)
98
+ return schema.type === 'boolean' ? false : '';
99
+ else if (isEmpty)
100
+ return undefined;
94
101
  if (Array.isArray(value) && schema.type === 'array') {
95
- return value.map((item, index)=>convertValue(`${fieldName}.${String(index)}`, item, resolve(schema.items, references), references, dynamicFields));
102
+ return value.map((item, index) => convertValue(`${fieldName}.${String(index)}`, item, resolve(schema.items, references), references, dynamicFields));
96
103
  }
97
104
  if (schema.type === 'switcher') {
98
105
  return convertValue(fieldName, value, resolve(getDynamicFieldSchema(fieldName, dynamicFields, Object.values(schema.items).at(0)), references), references, dynamicFields);
99
106
  }
100
107
  if (typeof value === 'object' && schema.type === 'object') {
101
- const entries = Object.keys(value).map((key)=>{
108
+ const entries = Object.keys(value).map((key) => {
102
109
  const prop = value[key];
103
110
  const propFieldName = `${fieldName}.${key}`;
104
111
  if (key in schema.properties) {
105
112
  return [
106
113
  key,
107
- convertValue(propFieldName, prop, resolve(schema.properties[key], references), references, dynamicFields)
114
+ convertValue(propFieldName, prop, resolve(schema.properties[key], references), references, dynamicFields),
108
115
  ];
109
116
  }
110
117
  if (schema.additionalProperties) {
111
118
  const schema = resolve(getDynamicFieldSchema(propFieldName, dynamicFields), references);
112
119
  return [
113
120
  key,
114
- convertValue(propFieldName, prop, schema, references, dynamicFields)
121
+ convertValue(propFieldName, prop, schema, references, dynamicFields),
115
122
  ];
116
123
  }
117
124
  console.warn('Could not resolve field', propFieldName, dynamicFields);
118
- return [
119
- key,
120
- prop
121
- ];
125
+ return [key, prop];
122
126
  });
123
127
  return Object.fromEntries(entries);
124
128
  }
125
- switch(schema.type){
129
+ switch (schema.type) {
126
130
  case 'number':
127
131
  return Number(value);
128
132
  case 'boolean':
@@ -135,12 +139,9 @@ import { r as resolve } from './index-client-BUeWwFWK.js';
135
139
  }
136
140
  function getDynamicFieldSchema(name, dynamicFields, defaultValue) {
137
141
  const field = dynamicFields.get(name);
138
- if (field?.type === 'field') return field.schema;
139
- if (defaultValue) return defaultValue;
140
- return {
141
- type: 'null',
142
- isRequired: false
143
- };
142
+ if (field?.type === 'field')
143
+ return field.schema;
144
+ if (defaultValue)
145
+ return defaultValue;
146
+ return { type: 'null', isRequired: false };
144
147
  }
145
-
146
- export { createBodyFromValue, createBrowserFetcher };
@@ -0,0 +1,4 @@
1
+ import type { PrimitiveRequestField, RequestSchema } from '../../render/playground.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>;
4
+ //# sourceMappingURL=get-default-values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-values.d.ts","sourceRoot":"","sources":["../../../src/ui/playground/get-default-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGhF,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"}