fumadocs-openapi 4.4.2 → 5.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/index.d.ts CHANGED
@@ -1,60 +1,132 @@
1
1
  import { OpenAPIV3 } from 'openapi-types';
2
- import { A as APIPlaygroundProps } from './playground-vSsfCaVw.js';
3
- export { P as PrimitiveRequestField, a as ReferenceSchema, R as RequestSchema } from './playground-vSsfCaVw.js';
2
+ import Slugger from 'github-slugger';
3
+ import { ComponentType, ReactNode } from 'react';
4
+
5
+ interface BaseRequestField {
6
+ name: string;
7
+ description?: string;
8
+ }
9
+ interface BaseSchema {
10
+ description?: string;
11
+ isRequired: boolean;
12
+ }
13
+ type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
14
+ interface PrimitiveSchema extends BaseSchema {
15
+ type: 'boolean' | 'string' | 'number';
16
+ defaultValue: string;
17
+ }
18
+ interface ReferenceSchema extends BaseSchema {
19
+ type: 'ref';
20
+ schema: string;
21
+ }
22
+ interface ArraySchema extends BaseSchema {
23
+ type: 'array';
24
+ /**
25
+ * Reference to item schema or the schema
26
+ */
27
+ items: string | RequestSchema;
28
+ }
29
+ interface FileSchema extends BaseSchema {
30
+ type: 'file';
31
+ }
32
+ interface ObjectSchema extends BaseSchema {
33
+ type: 'object';
34
+ properties: Record<string, ReferenceSchema>;
35
+ /**
36
+ * Reference to schema, or true if it's `any`
37
+ */
38
+ additionalProperties?: boolean | string;
39
+ }
40
+ interface SwitcherSchema extends BaseSchema {
41
+ type: 'switcher';
42
+ items: Record<string, ReferenceSchema | RequestSchema>;
43
+ }
44
+ interface NullSchema extends BaseSchema {
45
+ type: 'null';
46
+ }
47
+ type RequestSchema = PrimitiveSchema | ArraySchema | ObjectSchema | SwitcherSchema | NullSchema | FileSchema;
48
+ interface APIPlaygroundProps {
49
+ route: string;
50
+ method: string;
51
+ bodyType: 'json' | 'form-data';
52
+ authorization?: PrimitiveRequestField;
53
+ path?: PrimitiveRequestField[];
54
+ query?: PrimitiveRequestField[];
55
+ header?: PrimitiveRequestField[];
56
+ body?: RequestSchema;
57
+ schemas: Record<string, RequestSchema>;
58
+ }
4
59
 
5
60
  interface ResponsesProps {
6
61
  items: string[];
62
+ children: ReactNode;
7
63
  }
8
64
  interface ResponseProps {
9
65
  value: string;
66
+ children: ReactNode;
10
67
  }
11
68
  interface APIInfoProps {
12
69
  method: string;
13
70
  route: string;
71
+ children: ReactNode;
14
72
  }
15
73
  interface PropertyProps {
16
74
  name: string;
17
75
  type: string;
18
76
  required?: boolean;
19
77
  deprecated?: boolean;
78
+ children?: ReactNode;
20
79
  }
21
80
  interface ObjectCollapsibleProps {
22
81
  name: string;
82
+ children: ReactNode;
23
83
  }
24
84
  interface RequestProps {
25
85
  language: string;
26
86
  name: string;
27
87
  code: string;
28
88
  }
89
+ interface ResponseTypeProps {
90
+ lang: string;
91
+ code: string;
92
+ label: string;
93
+ }
29
94
  interface RootProps {
30
95
  baseUrl?: string;
96
+ children: ReactNode;
31
97
  }
32
98
  interface Renderer {
33
- Root: (props: RootProps, child: string[]) => string;
34
- API: (child: string[]) => string;
35
- APIInfo: (props: APIInfoProps, child: string[]) => string;
36
- APIExample: (child: string[]) => string;
37
- Responses: (props: ResponsesProps, child: string[]) => string;
38
- Response: (props: ResponseProps, child: string[]) => string;
39
- Requests: (items: string[], child: string[]) => string;
40
- Request: (props: RequestProps) => string;
41
- ResponseTypes: (child: string[]) => string;
42
- ExampleResponse: (json: string) => string;
43
- TypeScriptResponse: (code: string) => string;
99
+ Root: ComponentType<RootProps>;
100
+ API: ComponentType<{
101
+ children: ReactNode;
102
+ }>;
103
+ APIInfo: ComponentType<APIInfoProps>;
104
+ APIExample: ComponentType<{
105
+ children: ReactNode;
106
+ }>;
107
+ Responses: ComponentType<ResponsesProps>;
108
+ Response: ComponentType<ResponseProps>;
109
+ Requests: ComponentType<{
110
+ items: string[];
111
+ children: ReactNode;
112
+ }>;
113
+ Request: ComponentType<RequestProps>;
114
+ ResponseTypes: ComponentType<{
115
+ children: ReactNode;
116
+ }>;
117
+ ResponseType: ComponentType<ResponseTypeProps>;
44
118
  /**
45
119
  * Collapsible to show object schemas
46
120
  */
47
- ObjectCollapsible: (props: ObjectCollapsibleProps, child: string[]) => string;
48
- Property: (props: PropertyProps, child: string[]) => string;
49
- APIPlayground: (props: APIPlaygroundProps) => string;
121
+ ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
122
+ Property: ComponentType<PropertyProps>;
123
+ APIPlayground: ComponentType<APIPlaygroundProps>;
50
124
  }
51
125
 
52
- declare const defaultRenderer: Renderer;
53
-
54
126
  /**
55
127
  * Sample info of endpoint
56
128
  */
57
- interface Endpoint {
129
+ interface EndpointSample {
58
130
  /**
59
131
  * Request URL, including path and query parameters
60
132
  */
@@ -65,13 +137,15 @@ interface Endpoint {
65
137
  mediaType: string;
66
138
  sample: unknown;
67
139
  };
68
- responses: Record<string, Response>;
69
- parameters: Parameter[];
140
+ responses: Record<string, ResponseSample>;
141
+ parameters: ParameterSample[];
70
142
  }
71
- interface Response {
143
+ interface ResponseSample {
144
+ mediaType: string;
145
+ sample: unknown;
72
146
  schema: OpenAPIV3.SchemaObject;
73
147
  }
74
- interface Parameter {
148
+ interface ParameterSample {
75
149
  name: string;
76
150
  in: string;
77
151
  schema: OpenAPIV3.SchemaObject;
@@ -99,6 +173,7 @@ interface RenderContext {
99
173
  renderer: Renderer;
100
174
  document: OpenAPIV3.Document;
101
175
  baseUrl: string;
176
+ slugger: Slugger;
102
177
  /**
103
178
  * Generate TypeScript definitions from response schema.
104
179
  *
@@ -107,11 +182,11 @@ interface RenderContext {
107
182
  * @param endpoint - the API endpoint
108
183
  * @param code - status code
109
184
  */
110
- generateTypeScriptSchema?: ((endpoint: Endpoint, code: string) => Awaitable<string>) | false;
185
+ generateTypeScriptSchema?: ((endpoint: EndpointSample, code: string) => Awaitable<string>) | false;
111
186
  /**
112
187
  * Generate code samples for endpoint.
113
188
  */
114
- generateCodeSamples?: (endpoint: Endpoint) => Awaitable<CodeSample[]>;
189
+ generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
115
190
  }
116
191
 
117
192
  type DocumentContext = {
@@ -132,11 +207,9 @@ type DocumentContext = {
132
207
  type: 'file';
133
208
  routes: RouteInformation[];
134
209
  };
135
- interface GenerateOptions extends Pick<RenderContext, 'generateCodeSamples' | 'generateTypeScriptSchema'> {
210
+ interface GenerateOptions {
136
211
  /**
137
- * The imports of your MDX components.
138
- *
139
- * If not specified, import required components from `fumadocs-ui/components/api`.
212
+ * Additional imports of your MDX components.
140
213
  */
141
214
  imports?: {
142
215
  names: string[];
@@ -148,18 +221,17 @@ interface GenerateOptions extends Pick<RenderContext, 'generateCodeSamples' | 'g
148
221
  * A `full: true` property will be added by default.
149
222
  */
150
223
  frontmatter?: (title: string, description: string | undefined, context: DocumentContext) => Record<string, unknown>;
151
- renderer?: Partial<Renderer>;
152
224
  }
153
225
  interface GenerateTagOutput {
154
226
  tag: string;
155
227
  content: string;
156
228
  }
157
229
  interface GenerateOperationOutput {
158
- id: string;
159
230
  content: string;
231
+ method: MethodInformation;
160
232
  route: RouteInformation;
161
233
  }
162
- declare function generate(pathOrDocument: string | OpenAPIV3.Document, options?: GenerateOptions): Promise<string>;
234
+ declare function generateAll(pathOrDocument: string | OpenAPIV3.Document, options?: GenerateOptions): Promise<string>;
163
235
  declare function generateOperations(pathOrDocument: string | OpenAPIV3.Document, options?: GenerateOptions): Promise<GenerateOperationOutput[]>;
164
236
  declare function generateTags(pathOrDocument: string | OpenAPIV3.Document, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
165
237
 
@@ -187,13 +259,18 @@ interface Config extends GenerateOptions {
187
259
  /**
188
260
  * Group output using folders (Only works on `operation` mode)
189
261
  *
262
+ * @deprecated Use `groupBy` instead
190
263
  * @defaultValue false
191
264
  */
192
265
  groupByFolder?: boolean;
266
+ /**
267
+ * Group output using folders (Only works on `operation` mode)
268
+ *
269
+ * @defaultValue 'none'
270
+ */
271
+ groupBy?: 'tag' | 'route' | 'none';
193
272
  cwd?: string;
194
273
  }
195
- declare function generateFiles({ input, output, name: nameFn, per, cwd, groupByFolder, ...options }: Config): Promise<void>;
196
-
197
- declare function createElement(name: string, props: object, ...child: string[]): string;
274
+ declare function generateFiles({ input, output, name: nameFn, per, cwd, groupBy, ...options }: Config): Promise<void>;
198
275
 
199
- export { type APIInfoProps, APIPlaygroundProps, type Config, type DocumentContext, type GenerateOperationOutput, type GenerateOptions, type GenerateTagOutput, type MethodInformation, type ObjectCollapsibleProps, type PropertyProps, type RenderContext, type Renderer, type RequestProps, type ResponseProps, type ResponsesProps, type RootProps, type RouteInformation, createElement, defaultRenderer, generate, generateFiles, generateOperations, generateTags };
276
+ export { type Config, type DocumentContext, type GenerateOperationOutput, type GenerateOptions, type GenerateTagOutput, type MethodInformation, type RenderContext, type RouteInformation, generateAll, generateFiles, generateOperations, generateTags };