@moccona/apicodegen 0.0.3 → 0.0.8

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/npm/index.d.cts CHANGED
@@ -1,328 +1,313 @@
1
- import * as typescript from 'typescript';
2
- import { Statement, Node, ParameterDeclaration, TypeNode, Block } from 'typescript';
3
- import { OpenAPIV3 } from 'openapi-types';
4
- import { ServerOptions, PluginOption } from 'vite';
1
+ import { Block, Node, ParameterDeclaration, Statement, TypeNode } from "typescript";
2
+ import { OpenAPIV3 } from "openapi-types";
3
+ import { PluginOption } from "vite";
5
4
 
5
+ //#region src/core/interface.d.ts
6
6
  /**
7
7
  * Simple represenration for JSON object
8
8
  */
9
9
  type JSONValue = {
10
- [K: string]: string | number | boolean | JSONValue | (string | number | boolean | JSONValue)[];
10
+ [K: string]: string | number | boolean | JSONValue | (string | number | boolean | JSONValue)[];
11
11
  };
12
12
  declare enum SchemaType {
13
- schemas = "schemas",
14
- parameters = "parameters",
15
- responses = "responses",
16
- requestBodies = "requestBodies"
13
+ schemas = "schemas",
14
+ parameters = "parameters",
15
+ responses = "responses",
16
+ requestBodies = "requestBodies"
17
17
  }
18
18
  declare enum NonArraySchemaType {
19
- "object" = "object",
20
- "string" = "string",
21
- "number" = "number",
22
- "boolean" = "boolean",
23
- "integer" = "integer",
24
- "enum" = "enum",
25
- "file" = "file"
19
+ object = "object",
20
+ string = "string",
21
+ number = "number",
22
+ boolean = "boolean",
23
+ integer = "integer",
24
+ enum = "enum",
25
+ file = "file"
26
26
  }
27
27
  declare enum ArraySchemaType {
28
- "array" = "array"
28
+ array = "array"
29
29
  }
30
30
  declare enum SchemaFormatType {
31
- "string" = "string",
32
- "number" = "number",
33
- "boolean" = "boolean",
34
- "file" = "file",
35
- "binary" = "binary",
36
- "blob" = "blob"
31
+ string = "string",
32
+ number = "number",
33
+ boolean = "boolean",
34
+ file = "file",
35
+ binary = "binary",
36
+ blob = "blob"
37
37
  }
38
38
  declare enum ParameterIn {
39
- "header" = "header",
40
- "body" = "body",
41
- "query" = "query",
42
- "cookie" = "cookie",
43
- "path" = "path",
44
- "formData" = "formData"
39
+ header = "header",
40
+ body = "body",
41
+ query = "query",
42
+ cookie = "cookie",
43
+ path = "path",
44
+ formData = "formData"
45
45
  }
46
46
  interface ReferenceObject {
47
- $ref: string;
47
+ $ref: string;
48
48
  }
49
49
  interface EnumSchemaObject {
50
- name: string;
51
- enum: (string | number)[];
50
+ name: string;
51
+ enum: (string | number)[];
52
52
  }
53
53
  interface SingleTypeSchemaObject {
54
- type: keyof typeof NonArraySchemaType | string;
55
- description?: string;
56
- allOf?: SchemaObject[];
57
- anyOf?: SchemaObject[];
58
- deprecated?: boolean;
59
- enum?: (string | number)[];
60
- format?: keyof typeof SchemaFormatType;
61
- oneOf?: SchemaObject[];
62
- properties?: Record<string, SchemaObject>;
63
- readonly?: boolean;
64
- required?: string[] | boolean;
65
- ref?: string;
54
+ type: keyof typeof NonArraySchemaType | string;
55
+ description?: string;
56
+ allOf?: SchemaObject[];
57
+ anyOf?: SchemaObject[];
58
+ deprecated?: boolean;
59
+ enum?: (string | number)[];
60
+ format?: keyof typeof SchemaFormatType;
61
+ oneOf?: SchemaObject[];
62
+ properties?: Record<string, SchemaObject>;
63
+ readonly?: boolean;
64
+ required?: string[] | boolean;
65
+ ref?: string;
66
66
  }
67
67
  interface ArrayTypeSchemaObject {
68
- type: keyof typeof ArraySchemaType;
69
- items?: SchemaObject;
70
- required?: boolean;
71
- description?: string;
72
- ref?: string;
68
+ type: keyof typeof ArraySchemaType;
69
+ items?: SchemaObject;
70
+ required?: boolean;
71
+ description?: string;
72
+ ref?: string;
73
73
  }
74
74
  type SchemaObject = SingleTypeSchemaObject | ArrayTypeSchemaObject;
75
75
  type ParameterObject = {
76
- name: string;
77
- in: keyof typeof ParameterIn;
78
- schema?: SchemaObject;
79
- required?: boolean;
80
- description?: string;
81
- deprecated?: boolean;
82
- ref?: string;
76
+ name: string;
77
+ in: keyof typeof ParameterIn;
78
+ schema?: SchemaObject;
79
+ required?: boolean;
80
+ description?: string;
81
+ deprecated?: boolean;
82
+ ref?: string;
83
83
  };
84
84
  declare enum MediaTypes {
85
- JSON = "application/json",
86
- TEXT = "text",
87
- IMAGE = "image",
88
- AUDIO = "audio",
89
- VIDEO = "video"
85
+ JSON = "application/json",
86
+ TEXT = "text",
87
+ IMAGE = "image",
88
+ AUDIO = "audio",
89
+ VIDEO = "video"
90
90
  }
91
91
  type MediaTypeObject = {
92
- type: MediaTypes | keyof typeof MediaTypes;
93
- schema?: SchemaObject;
92
+ type: MediaTypes | keyof typeof MediaTypes;
93
+ schema?: SchemaObject;
94
94
  };
95
95
  type ResponsesObject = Record<string, MediaTypeObject[]>;
96
96
  type RequestBodyObject = ResponsesObject;
97
97
  declare enum HttpMethods {
98
- GET = "get",
99
- PUT = "put",
100
- POST = "post",
101
- DELETE = "delete",
102
- OPTIONS = "options",
103
- HEAD = "head",
104
- PATCH = "patch",
105
- TRACE = "trace"
98
+ GET = "get",
99
+ PUT = "put",
100
+ POST = "post",
101
+ DELETE = "delete",
102
+ OPTIONS = "options",
103
+ HEAD = "head",
104
+ PATCH = "patch",
105
+ TRACE = "trace"
106
106
  }
107
107
  type OperationObject = {
108
- method: string;
109
- summary?: string;
108
+ method: string;
109
+ summary?: string;
110
+ description?: string;
111
+ operationId?: string;
112
+ externalDocs?: {
113
+ url: string;
110
114
  description?: string;
111
- operationId?: string;
112
- externalDocs?: {
113
- url: string;
114
- description?: string;
115
- }[];
116
- parameters?: ParameterObject[];
117
- requestBody?: MediaTypeObject[];
118
- responses: MediaTypeObject[];
119
- deprecated?: boolean;
115
+ }[];
116
+ parameters?: ParameterObject[];
117
+ requestBody?: MediaTypeObject[];
118
+ responses: MediaTypeObject[];
119
+ deprecated?: boolean;
120
120
  };
121
121
  type PathObject = {
122
- ref?: string;
123
- summary?: string;
124
- description?: string;
125
- parameters?: ParameterObject[];
122
+ ref?: string;
123
+ summary?: string;
124
+ description?: string;
125
+ parameters?: ParameterObject[];
126
126
  } & Partial<Record<HttpMethods, OperationObject>>;
127
127
  type PathsObject = Record<string, OperationObject[]>;
128
128
  type FetchDocRequestInit = {
129
- method?: string;
130
- body?: string | FormData;
131
- headers?: Record<string, string>;
129
+ method?: string;
130
+ body?: string | FormData;
131
+ headers?: Record<string, string>;
132
132
  };
133
133
  declare enum Adaptors {
134
- fetch = "fetch",
135
- axios = "axios"
134
+ fetch = "fetch",
135
+ axios = "axios"
136
136
  }
137
137
  type ProviderInitOptions = {
138
- docURL: string;
139
- output: string;
140
- baseURL?: string;
141
- importClientSource?: string;
142
- requestOptions?: FetchDocRequestInit;
143
- verbose?: boolean;
144
- adaptor?: keyof typeof Adaptors;
138
+ docURL: string;
139
+ output: string;
140
+ baseURL?: string;
141
+ importClientSource?: string;
142
+ requestOptions?: FetchDocRequestInit;
143
+ verbose?: boolean;
144
+ adaptor?: keyof typeof Adaptors;
145
145
  };
146
146
  interface ProviderInitResult {
147
- readonly enums: EnumSchemaObject[];
148
- readonly schemas: Record<string, SchemaObject>;
149
- readonly parameters: Record<string, ParameterObject>;
150
- readonly responses: Record<string, ResponsesObject>;
151
- readonly requestBodies: Record<string, RequestBodyObject>;
152
- readonly apis: PathsObject;
147
+ readonly enums: EnumSchemaObject[];
148
+ readonly schemas: Record<string, SchemaObject>;
149
+ readonly parameters: Record<string, ParameterObject>;
150
+ readonly responses: Record<string, ResponsesObject>;
151
+ readonly requestBodies: Record<string, RequestBodyObject>;
152
+ readonly apis: PathsObject;
153
153
  }
154
-
155
- /**
156
- * @file Adapter abstract class definition
157
- * @author wp.l
158
- * @description Base adapter implementation for various code generation tools
159
- */
160
-
154
+ //#endregion
155
+ //#region src/core/base/Adaptor.d.ts
161
156
  /**
162
157
  * Base adapter for tool
163
158
  * This abstract class serves as the foundation for implementing adapters for different code generation tools
164
159
  */
165
160
  declare abstract class Adapter {
166
- /**
167
- * @abstract The unique name/identifier for this adapter implementation
168
- */
169
- abstract readonly name: string;
170
- /**
171
- * @abstract The name of the field used to specify the HTTP method in API calls
172
- */
173
- abstract readonly methodFieldName: string;
174
- /**
175
- * @abstract The name of the field used to specify the request body in API calls
176
- */
177
- abstract readonly bodyFieldName: string;
178
- /**
179
- * @abstract The name of the field used to specify request headers in API calls
180
- */
181
- abstract readonly headersFieldName: string;
182
- /**
183
- * @abstract The name of the field used to specify query parameters in API calls
184
- */
185
- abstract readonly queryFieldName: string;
186
- /**
187
- * @abstract
188
- * @param {string} uri - The API endpoint URI
189
- * @param {string} method - The HTTP method (e.g., GET, POST, etc.)
190
- * @param {ParameterObject[]} parameters - An array of parameters for the API call
191
- * @param {MediaTypeObject | undefined} requestBody - The request body payload (if applicable)
192
- * @param {MediaTypeObject | undefined} response - The expected response format (if applicable)
193
- * @param {Adapter} adapter - An instance of the adapter being used
194
- * @param {boolean} useFormData - Flag indicating whether to use FormData for the request body
195
- * @param {boolean} useJSONResponse - Flag indicating whether the response should be parsed as JSON
196
- * @returns {Statement[]} An array of TypeScript AST statements representing the generated code
197
- */
198
- abstract client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, useFormData: boolean, useJSONResponse: boolean): Statement[];
161
+ /**
162
+ * @abstract The unique name/identifier for this adapter implementation
163
+ */
164
+ abstract readonly name: string;
165
+ /**
166
+ * @abstract The name of the field used to specify the HTTP method in API calls
167
+ */
168
+ abstract readonly methodFieldName: string;
169
+ /**
170
+ * @abstract The name of the field used to specify the request body in API calls
171
+ */
172
+ abstract readonly bodyFieldName: string;
173
+ /**
174
+ * @abstract The name of the field used to specify request headers in API calls
175
+ */
176
+ abstract readonly headersFieldName: string;
177
+ /**
178
+ * @abstract The name of the field used to specify query parameters in API calls
179
+ */
180
+ abstract readonly queryFieldName: string;
181
+ /**
182
+ * @abstract
183
+ * @param {string} uri - The API endpoint URI
184
+ * @param {string} method - The HTTP method (e.g., GET, POST, etc.)
185
+ * @param {ParameterObject[]} parameters - An array of parameters for the API call
186
+ * @param {MediaTypeObject | undefined} requestBody - The request body payload (if applicable)
187
+ * @param {MediaTypeObject | undefined} response - The expected response format (if applicable)
188
+ * @param {Adapter} adapter - An instance of the adapter being used
189
+ * @param {boolean} useFormData - Flag indicating whether to use FormData for the request body
190
+ * @param {boolean} useJSONResponse - Flag indicating whether the response should be parsed as JSON
191
+ * @returns {Statement[]} An array of TypeScript AST statements representing the generated code
192
+ */
193
+ abstract client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, useFormData: boolean, useJSONResponse: boolean): Statement[];
199
194
  }
200
-
201
- /**
202
- * @file Base class implementation
203
- * @author wp.l
204
- * @description Base utility class providing common methods for code generation and API handling
205
- */
206
-
195
+ //#endregion
196
+ //#region src/core/base/Base.d.ts
207
197
  /**
208
198
  * Represents success HTTP status codes.
209
199
  * Each key is a string representation of a success HTTP status code.
210
200
  */
211
201
  declare const SuccessHttpStatusCode: {
212
- "200": string;
213
- "201": string;
214
- "202": string;
215
- "203": string;
216
- "204": string;
217
- "205": string;
218
- "206": string;
219
- "207": string;
220
- "208": string;
221
- "226": string;
202
+ '200': string;
203
+ '201': string;
204
+ '202': string;
205
+ '203': string;
206
+ '204': string;
207
+ '205': string;
208
+ '206': string;
209
+ '207': string;
210
+ '208': string;
211
+ '226': string;
222
212
  };
223
213
  /**
224
214
  * Base abstract class providing common utility methods.
225
215
  */
226
216
  declare abstract class Base {
227
- protected constructor();
228
- /**
229
- * Converts a reference string to a meaningful name.
230
- * @param ref - The reference string to process.
231
- * @param [doc] - Optional document reference for context.
232
- * @returns - The processed name.
233
- */
234
- static ref2name(ref: string, doc?: any): string;
235
- /**
236
- * Converts an API path to a function name.
237
- * @param path - The API endpoint path.
238
- * @param [method] - The HTTP method (e.g., GET, POST).
239
- * @param [operationId] - Unique identifier for the operation.
240
- * @returns - The generated function name.
241
- */
242
- static pathToFnName(path: string, method?: string, _operationId?: string): string;
243
- /**
244
- * Normalizes a string by replacing special characters and avoiding TypeScript keywords.
245
- * @param text - Input text to normalize.
246
- * @returns - The normalized string.
247
- */
248
- static normalize(text: string): string;
249
- /**
250
- * Capitalizes the first character of a string.
251
- * @param text - Input string.
252
- * @returns - Capitalized string.
253
- */
254
- static capitalize(text: string): string;
255
- /**
256
- * Converts a string to camelCase.
257
- * @param text - Input string.
258
- * @returns - CamelCase string.
259
- */
260
- static camelCase(text: string): string;
261
- /**
262
- * Converts a string to UpperCamelCase.
263
- * @param text - Input string.
264
- * @returns - UpperCamelCase string.
265
- */
266
- static upperCamelCase(text: string): string;
267
- /**
268
- * Fetches documentation from a given URL.
269
- * @param url - The URL to fetch the documentation from.
270
- * @param requestInit - Additional request parameters.
271
- * @returns - A promise resolving to the fetched documentation data.
272
- */
273
- static fetchDoc<T = unknown>(url: string, requestInit?: FetchDocRequestInit): Promise<T>;
274
- /**
275
- * Determines the media type from a given media type string.
276
- * @param mediaType - The media type string to evaluate.
277
- * @returns - The matched MediaTypes or null.
278
- */
279
- static getMediaType(mediaType: string): MediaTypes | undefined;
280
- /**
281
- * Checks if a schema is a valid enum type that isn't boolean.
282
- * @param a - The schema object to evaluate.
283
- * @returns - True if the schema is a valid non-boolean enum.
284
- */
285
- static isValidEnumType(a: SchemaObject): boolean;
286
- /**
287
- * Checks if a schema represents a boolean enum.
288
- * @param a - The schema object to evaluate.
289
- * @returns - True if the schema is a boolean enum.
290
- */
291
- static isBooleanEnum(a: SchemaObject): boolean;
292
- /**
293
- * Checks if two enum schemas are identical.
294
- * @param a - First enum schema to compare.
295
- * @param b - Second enum schema to compare.
296
- * @returns - True if the enums are identical.
297
- */
298
- private static isSameEnum;
299
- /**
300
- * Filters out duplicate enum schemas from an array.
301
- * @param enums - Array of enum schemas to process.
302
- * @returns - Array of unique enum schemas.
303
- */
304
- static uniqueEnums(enums: EnumSchemaObject[]): EnumSchemaObject[];
305
- /**
306
- * Finds the first occurrence of a matching enum schema in an array.
307
- * @param a - The enum schema to find.
308
- * @param enums - Array of enum schemas to search.
309
- * @returns - The found schema or undefined.
310
- */
311
- static findSameSchema(a: EnumSchemaObject, enums: EnumSchemaObject[]): EnumSchemaObject | undefined;
312
- /**
313
- * Checks if an object is a reference object.
314
- * @param schema - The object to check.
315
- * @returns - True if the object is a reference.
316
- */
317
- static isRef(schema: unknown): schema is ReferenceObject;
217
+ protected constructor();
218
+ /**
219
+ * Converts a reference string to a meaningful name.
220
+ * @param ref - The reference string to process.
221
+ * @param [doc] - Optional document reference for context.
222
+ * @returns - The processed name.
223
+ */
224
+ static ref2name(ref: string, doc?: any): string;
225
+ /**
226
+ * Converts an API path to a function name.
227
+ * @param path - The API endpoint path.
228
+ * @param [method] - The HTTP method (e.g., GET, POST).
229
+ * @param [operationId] - Unique identifier for the operation.
230
+ * @returns - The generated function name.
231
+ */
232
+ static pathToFnName(path: string, method?: string, _operationId?: string): string;
233
+ /**
234
+ * Normalizes a string by replacing special characters and avoiding TypeScript keywords.
235
+ * @param text - Input text to normalize.
236
+ * @returns - The normalized string.
237
+ */
238
+ static normalize(text: string): string;
239
+ /**
240
+ * Capitalizes the first character of a string.
241
+ * @param text - Input string.
242
+ * @returns - Capitalized string.
243
+ */
244
+ static capitalize(text: string): string;
245
+ /**
246
+ * Converts a string to camelCase.
247
+ * @param text - Input string.
248
+ * @returns - CamelCase string.
249
+ */
250
+ static camelCase(text: string): string;
251
+ /**
252
+ * Converts a string to UpperCamelCase.
253
+ * @param text - Input string.
254
+ * @returns - UpperCamelCase string.
255
+ */
256
+ static upperCamelCase(text: string): string;
257
+ /**
258
+ * Fetches documentation from a given URL.
259
+ * @param url - The URL to fetch the documentation from.
260
+ * @param requestInit - Additional request parameters.
261
+ * @returns - A promise resolving to the fetched documentation data.
262
+ */
263
+ static fetchDoc<T = unknown>(url: string, requestInit?: FetchDocRequestInit): Promise<T>;
264
+ /**
265
+ * Determines the media type from a given media type string.
266
+ * @param mediaType - The media type string to evaluate.
267
+ * @returns - The matched MediaTypes or null.
268
+ */
269
+ static getMediaType(mediaType: string): MediaTypes | undefined;
270
+ /**
271
+ * Checks if a schema is a valid enum type that isn't boolean.
272
+ * @param a - The schema object to evaluate.
273
+ * @returns - True if the schema is a valid non-boolean enum.
274
+ */
275
+ static isValidEnumType(a: SchemaObject): boolean;
276
+ /**
277
+ * Checks if a schema represents a boolean enum.
278
+ * @param a - The schema object to evaluate.
279
+ * @returns - True if the schema is a boolean enum.
280
+ */
281
+ static isBooleanEnum(a: SchemaObject): boolean;
282
+ /**
283
+ * Checks if two enum schemas are identical.
284
+ * @param a - First enum schema to compare.
285
+ * @param b - Second enum schema to compare.
286
+ * @returns - True if the enums are identical.
287
+ */
288
+ private static isSameEnum;
289
+ /**
290
+ * Filters out duplicate enum schemas from an array.
291
+ * @param enums - Array of enum schemas to process.
292
+ * @returns - Array of unique enum schemas.
293
+ */
294
+ static uniqueEnums(enums: EnumSchemaObject[]): EnumSchemaObject[];
295
+ /**
296
+ * Finds the first occurrence of a matching enum schema in an array.
297
+ * @param a - The enum schema to find.
298
+ * @param enums - Array of enum schemas to search.
299
+ * @returns - The found schema or undefined.
300
+ */
301
+ static findSameSchema(a: EnumSchemaObject, enums: EnumSchemaObject[]): EnumSchemaObject | undefined;
302
+ /**
303
+ * Checks if an object is a reference object.
304
+ * @param schema - The object to check.
305
+ * @returns - True if the object is a reference.
306
+ */
307
+ static isRef(schema: unknown): schema is ReferenceObject;
318
308
  }
319
-
320
- /**
321
- * @file Base class implementation
322
- * @author wp.l
323
- * @description This file defines the `Provider` abstract class, which serves as a base for providers responsible for parsing and processing API documentation.
324
- */
325
-
309
+ //#endregion
310
+ //#region src/core/base/Provider.d.ts
326
311
  /**
327
312
  * Abstract Provider Class.
328
313
  *
@@ -356,181 +341,391 @@ declare abstract class Base {
356
341
  * ```
357
342
  */
358
343
  declare abstract class Provider implements ProviderInitResult, ProviderInitOptions {
359
- /** collection of enum schemas */
360
- readonly enums: EnumSchemaObject[];
361
- /** collection of schemas indexed by name */
362
- readonly schemas: Record<string, SchemaObject>;
363
- /** collection of parameters indexed by name */
364
- readonly parameters: Record<string, ParameterObject>;
365
- /** collection of API responses indexed by name */
366
- readonly responses: Record<string, ResponsesObject>;
367
- /** collection of request bodies indexed by name */
368
- readonly requestBodies: Record<string, RequestBodyObject>;
369
- /** collection of API endpoints (operations) indexed by path */
370
- readonly apis: Record<string, OperationObject[]>;
371
- /** URL for fetching API documentation */
372
- readonly docURL: string;
373
- /** base URL for API endpoints */
374
- readonly baseURL: string;
375
- /** output directory for generated code */
376
- readonly output: string;
377
- /** request options for API documentation fetch */
378
- readonly requestOptions: FetchDocRequestInit;
379
- /** source path for imported client */
380
- readonly importClientSource: string;
381
- /**
382
- * Provider Constructor.
383
- * @param {ProviderInitOptions} initOptions - Initial configuration for the provider.
384
- * @param {unknown} doc - Raw API documentation data to be parsed.
385
- */
386
- constructor(initOptions: ProviderInitOptions, doc: unknown);
387
- /**
388
- * Abstract Parse Method.
389
- * @abstract
390
- * @param {unknown} doc - Raw API documentation data.
391
- * @returns {ProviderInitResult} - Parsed documentation data.
392
- *
393
- * This method must be implemented by subclasses to parse the raw documentation into structured data.
394
- */
395
- abstract parse(doc: unknown): ProviderInitResult;
344
+ /** collection of enum schemas */
345
+ readonly enums: EnumSchemaObject[];
346
+ /** collection of schemas indexed by name */
347
+ readonly schemas: Record<string, SchemaObject>;
348
+ /** collection of parameters indexed by name */
349
+ readonly parameters: Record<string, ParameterObject>;
350
+ /** collection of API responses indexed by name */
351
+ readonly responses: Record<string, ResponsesObject>;
352
+ /** collection of request bodies indexed by name */
353
+ readonly requestBodies: Record<string, RequestBodyObject>;
354
+ /** collection of API endpoints (operations) indexed by path */
355
+ readonly apis: Record<string, OperationObject[]>;
356
+ /** URL for fetching API documentation */
357
+ readonly docURL: string;
358
+ /** base URL for API endpoints */
359
+ readonly baseURL: string;
360
+ /** output directory for generated code */
361
+ readonly output: string;
362
+ /** request options for API documentation fetch */
363
+ readonly requestOptions: FetchDocRequestInit;
364
+ /** source path for imported client */
365
+ readonly importClientSource: string;
366
+ /**
367
+ * Provider Constructor.
368
+ * @param {ProviderInitOptions} initOptions - Initial configuration for the provider.
369
+ * @param {unknown} doc - Raw API documentation data to be parsed.
370
+ */
371
+ constructor(initOptions: ProviderInitOptions, doc: unknown);
372
+ /**
373
+ * Abstract Parse Method.
374
+ * @abstract
375
+ * @param {unknown} doc - Raw API documentation data.
376
+ * @returns {ProviderInitResult} - Parsed documentation data.
377
+ *
378
+ * This method must be implemented by subclasses to parse the raw documentation into structured data.
379
+ */
380
+ abstract parse(doc: unknown): ProviderInitResult;
396
381
  }
397
-
398
- /**
399
- * File containing the implementation of the AxiosAdapter class.
400
- * This adapter is responsible for generating code that uses the Axios HTTP client library.
401
- */
402
-
382
+ //#endregion
383
+ //#region src/core/client/axios.d.ts
403
384
  /**
404
385
  * Adapter class implementing support for generating code that makes use of the Axios HTTP client library.
405
386
  * This class defines custom behavior and field mappings specific to the Axios client.
406
387
  */
407
388
  declare class AxiosAdapter extends Adapter {
408
- /**
409
- * Name of the field used to specify the HTTP method in the request configuration.
410
- */
411
- readonly methodFieldName = "method";
412
- /**
413
- * Name of the field used to specify the request body (data) in the request configuration.
414
- */
415
- readonly bodyFieldName = "data";
416
- /**
417
- * Name of the field used to specify the request headers in the request configuration.
418
- */
419
- readonly headersFieldName = "headers";
420
- /**
421
- * Name of the field used to specify the query parameters in the request configuration.
422
- */
423
- readonly queryFieldName = "params";
424
- /**
425
- * The name of the client this adapter is configured for, which is 'axios' in this case.
426
- */
427
- readonly name = "axios";
428
- /**
429
- * Method that should generate and return the client-specific configuration statements.
430
- *
431
- * @returns {Statement[]} An array of TypeScript statements that define the client configuration.
432
- *
433
- * @throws {Error} Indicates that the method is not yet implemented and needs to be filled in.
434
- */
435
- client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, shouldUseFormData: boolean): Statement[];
389
+ /**
390
+ * Name of the field used to specify the HTTP method in the request configuration.
391
+ */
392
+ readonly methodFieldName = "method";
393
+ /**
394
+ * Name of the field used to specify the request body (data) in the request configuration.
395
+ */
396
+ readonly bodyFieldName = "data";
397
+ /**
398
+ * Name of the field used to specify the request headers in the request configuration.
399
+ */
400
+ readonly headersFieldName = "headers";
401
+ /**
402
+ * Name of the field used to specify the query parameters in the request configuration.
403
+ */
404
+ readonly queryFieldName = "params";
405
+ /**
406
+ * The name of the client this adapter is configured for, which is 'axios' in this case.
407
+ */
408
+ readonly name = "axios";
409
+ /**
410
+ * Method that should generate and return the client-specific configuration statements.
411
+ *
412
+ * @returns {Statement[]} An array of TypeScript statements that define the client configuration.
413
+ *
414
+ * @throws {Error} Indicates that the method is not yet implemented and needs to be filled in.
415
+ */
416
+ client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, shouldUseFormData: boolean): Statement[];
436
417
  }
437
-
418
+ //#endregion
419
+ //#region src/core/client/fetch.d.ts
438
420
  /**
439
421
  * FetchAdapter is an adapter class that generates client-side fetch requests.
440
422
  * It handles parameters, headers, and request bodies to construct proper fetch calls.
441
423
  */
442
424
  declare class FetchAdapter extends Adapter {
443
- readonly methodFieldName = "method";
444
- readonly bodyFieldName = "body";
445
- readonly headersFieldName = "headers";
446
- readonly queryFieldName = "";
447
- readonly name = "fetch";
448
- /**
449
- * Generates client code for making API requests using the Fetch API.
450
- * @param uri - The API endpoint URI
451
- * @param method - The HTTP method (GET, POST, etc.)
452
- * @param parameters - Array of parameters to include in the request
453
- * @param requestBody - The request body media type definition
454
- * @param response - The response media type definition
455
- * @param adapter - The adapter instance
456
- * @param shouldUseFormData - Flag to use FormData for the request body
457
- * @param shouldUseJSONResponse - Flag to use JSON parsing for the response
458
- * @return - An array of generated TypeScript statements
459
- */
460
- client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, shouldUseFormData: boolean, shouldUseJSONResponse: boolean): Statement[];
425
+ readonly methodFieldName = "method";
426
+ readonly bodyFieldName = "body";
427
+ readonly headersFieldName = "headers";
428
+ readonly queryFieldName = "";
429
+ readonly name = "fetch";
430
+ /**
431
+ * Generates client code for making API requests using the Fetch API.
432
+ * @param uri - The API endpoint URI
433
+ * @param method - The HTTP method (GET, POST, etc.)
434
+ * @param parameters - Array of parameters to include in the request
435
+ * @param requestBody - The request body media type definition
436
+ * @param response - The response media type definition
437
+ * @param adapter - The adapter instance
438
+ * @param shouldUseFormData - Flag to use FormData for the request body
439
+ * @param shouldUseJSONResponse - Flag to use JSON parsing for the response
440
+ * @return - An array of generated TypeScript statements
441
+ */
442
+ client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, shouldUseFormData: boolean, shouldUseJSONResponse: boolean): Statement[];
461
443
  }
462
-
444
+ //#endregion
445
+ //#region src/core/config.d.ts
446
+ /**
447
+ * Adaptor type for HTTP client
448
+ */
449
+ type ConfigAdaptor = keyof typeof Adaptors;
450
+ /**
451
+ * Shared config interface for CLI and Vite plugin
452
+ */
453
+ interface ApicodegenConfig {
454
+ /** OpenAPI spec file path or URL (required) */
455
+ spec: string;
456
+ /** Output file path */
457
+ output: string;
458
+ /** HTTP client adaptor (fetch|axios) */
459
+ adaptor?: ConfigAdaptor;
460
+ /** Base URL for API endpoints */
461
+ baseURL?: string;
462
+ /** Custom client import source path */
463
+ importClientSource?: string;
464
+ /** Enable verbose logging */
465
+ verbose?: boolean;
466
+ /** Run type check after generation (default: true) */
467
+ typeCheck?: boolean;
468
+ /** Watch for file changes */
469
+ watch?: boolean;
470
+ /** Request options for fetching spec */
471
+ requestOptions?: FetchDocRequestInit;
472
+ }
473
+ /**
474
+ * Options for loading config
475
+ */
476
+ interface LoadConfigOptions {
477
+ /** Explicit config file path */
478
+ configFile?: string;
479
+ /** Config file directory (defaults to cwd) */
480
+ cwd?: string;
481
+ /** CLI overrides */
482
+ cliOptions?: Partial<ApicodegenConfig>;
483
+ /** Vite plugin options (for name metadata) */
484
+ name?: string;
485
+ }
486
+ /**
487
+ * Result of config loading
488
+ */
489
+ interface ResolvedConfig extends ApicodegenConfig {
490
+ /** Config file path if loaded from file */
491
+ configFilePath?: string;
492
+ /** Config name for logging */
493
+ name: string;
494
+ }
495
+ /**
496
+ * Load and resolve config from multiple sources
497
+ */
498
+ declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
499
+ /**
500
+ * Create CLI options from config for commander
501
+ */
502
+ declare function configToCLIOptions(config: ApicodegenConfig): Record<string, unknown>;
503
+ /**
504
+ * Convert resolved config to provider options format
505
+ */
506
+ declare function toProviderOptions(config: ResolvedConfig): {
507
+ docURL: string;
508
+ output: string;
509
+ adaptor: "fetch" | "axios" | undefined;
510
+ baseURL: string | undefined;
511
+ importClientSource: string | undefined;
512
+ verbose: boolean | undefined;
513
+ requestOptions: FetchDocRequestInit | undefined;
514
+ };
515
+ //#endregion
516
+ //#region src/core/errors.d.ts
517
+ /**
518
+ * Error handling utilities for api-codegen
519
+ */
520
+ declare const ErrorCodes: {
521
+ readonly SPEC_NOT_FOUND: "E_SPEC_NOT_FOUND";
522
+ readonly SPEC_FETCH_FAILED: "E_SPEC_FETCH_FAILED";
523
+ readonly SPEC_PARSE_FAILED: "E_SPEC_PARSE_FAILED";
524
+ readonly OUTPUT_DIR_MISSING: "E_OUTPUT_DIR_MISSING";
525
+ readonly CONFIG_INVALID: "E_CONFIG_INVALID";
526
+ readonly VALIDATION_FAILED: "E_VALIDATION_FAILED";
527
+ readonly GENERATION_FAILED: "E_GENERATION_FAILED";
528
+ readonly TYPE_CHECK_FAILED: "E_TYPE_CHECK_FAILED";
529
+ };
530
+ type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
531
+ /**
532
+ * Error context for ApicodegenError
533
+ */
534
+ interface ApicodegenErrorContext {
535
+ /** Error code */
536
+ code: ErrorCode;
537
+ /** Human readable message */
538
+ message: string;
539
+ /** File/URL related to error */
540
+ location?: string;
541
+ /** Line number if applicable */
542
+ line?: number;
543
+ /** Column number if applicable */
544
+ column?: number;
545
+ /** Related schema/path if applicable */
546
+ path?: string;
547
+ /** Suggested fixes */
548
+ suggestions?: string[];
549
+ /** Original error */
550
+ cause?: Error;
551
+ }
552
+ /**
553
+ * Custom error class for api-codegen with rich context
554
+ */
555
+ declare class ApicodegenError extends Error {
556
+ readonly code: ErrorCode;
557
+ readonly location?: string;
558
+ readonly line?: number;
559
+ readonly column?: number;
560
+ readonly path?: string;
561
+ readonly suggestions: string[];
562
+ readonly cause?: Error;
563
+ constructor(context: ApicodegenErrorContext);
564
+ /**
565
+ * Convert error to formatted string for CLI output
566
+ */
567
+ toString(verbose?: boolean): string;
568
+ /**
569
+ * Convert to JSON-serializable object
570
+ */
571
+ toJSON(): object;
572
+ }
573
+ /**
574
+ * ANSI color codes for terminal output
575
+ */
576
+ declare const Colors: {
577
+ readonly reset: "\u001B[0m";
578
+ readonly bold: "\u001B[1m";
579
+ readonly red: "\u001B[31m";
580
+ readonly green: "\u001B[32m";
581
+ readonly yellow: "\u001B[33m";
582
+ readonly blue: "\u001B[34m";
583
+ readonly cyan: "\u001B[36m";
584
+ readonly gray: "\u001B[90m";
585
+ readonly brightRed: "\u001B[91m";
586
+ readonly brightGreen: "\u001B[92m";
587
+ };
588
+ /**
589
+ * Format error for CLI output
590
+ */
591
+ declare function formatError(error: unknown, verbose?: boolean): string;
592
+ /**
593
+ * Print error to console with formatting
594
+ */
595
+ declare function printError(error: unknown, verbose?: boolean, stream?: NodeJS.WriteStream): void;
596
+ /**
597
+ * Create error with common patterns
598
+ */
599
+ declare const createErrors: {
600
+ specNotFound(path: string, cause?: Error): ApicodegenError;
601
+ specFetchFailed(url: string, statusCode?: number, cause?: Error): ApicodegenError;
602
+ specParseFailed(path: string, line?: number, column?: number, cause?: Error): ApicodegenError;
603
+ outputDirMissing(path: string, cause?: Error): ApicodegenError;
604
+ configInvalid(path: string, cause?: Error): ApicodegenError;
605
+ validationFailed(path: string, details: string, cause?: Error): ApicodegenError;
606
+ generationFailed(cause?: Error): ApicodegenError;
607
+ typeCheckFailed(path: string, _errors: string[], cause?: Error): ApicodegenError;
608
+ missingRequiredField(field: string, context?: string): ApicodegenError;
609
+ };
610
+ /**
611
+ * Wrap unknown error in ApicodegenError if needed
612
+ */
613
+ declare function wrapError(error: unknown, context?: Partial<ApicodegenErrorContext>): ApicodegenError;
614
+ /**
615
+ * Check if error is an ApicodegenError
616
+ */
617
+ declare function isApicodegenError(error: unknown): error is ApicodegenError;
618
+ //#endregion
619
+ //#region src/core/generator/index.d.ts
463
620
  /**
464
621
  * Represents a comment object with optional tag and message.
465
622
  */
466
623
  type CommentObject = {
467
- tag?: string;
468
- comment: string;
624
+ tag?: string;
625
+ comment: string;
469
626
  };
470
627
  /**
471
628
  * Array of comment objects to be added to the code.
472
629
  */
473
630
  type Comments = CommentObject[];
474
631
  declare class Generator {
475
- /**
476
- * Converts an array of TypeScript statements into a formatted string of code.
477
- *
478
- * @param statements - The array of TypeScript statement nodes.
479
- * @returns Formatted code as a string.
480
- * @throws {Error} If no valid statements are provided.
481
- */
482
- static toCode(statements: Statement[]): string;
483
- static write(code: string, filepath: string): Promise<void>;
484
- /**
485
- * Converts a path string with parameters into a TypeScript template expression.
486
- * Handles query parameters and path placeholders.
487
- *
488
- * @param path - The base path string containing placeholders.
489
- * @param parameters - Array of parameter objects defining the parameters.
490
- * @param basePath - Optional base path to prepend (default: "").
491
- * @returns A TypeScript template expressi
492
- */
493
- static toUrlTemplate(path: string, parameters: ParameterObject[], basePath?: string): typescript.NoSubstitutionTemplateLiteral | typescript.TemplateExpression;
494
- /**
495
- * Adds synthetic comments to a TypeScript AST node.
496
- *
497
- * @param node - The target AST node.
498
- * @param comments - Array of comment objects to add.
499
- */
500
- static addComments(node: Node, comments: Comments): void;
501
- /**
502
- * Checks if a schema represents a binary type.
503
- *
504
- * @param schema - The schema object to check.
505
- * @returns true if the schema is a binary type, false otherwise.
506
- */
507
- static isBinarySchema(schema: SchemaObject): boolean;
508
- static toRequestBodyTypeNode(schema: SchemaObject): ParameterDeclaration;
509
- static toTypeNode(schema: SchemaObject): TypeNode;
510
- static toDeclarationNodes(parameters: ParameterObject[]): ParameterDeclaration[];
511
- static toFormDataStatement(parameters: ParameterObject[], requestBody?: SchemaObject): Statement[];
512
- static bodyBlock(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter): Block;
513
- static schemaToStatemets(parsedDoc: ProviderInitResult, adaptor: Adapter, options: Omit<ProviderInitOptions, "docURL" | "output" | "requestOptions">): Statement[];
514
- static prettier(code: string): Promise<string>;
515
- static genCode(schema: ProviderInitResult, initOptions: ProviderInitOptions, adaptor: Adapter): Promise<string>;
632
+ /**
633
+ * Converts an array of TypeScript statements into a formatted string of code.
634
+ *
635
+ * @param statements - The array of TypeScript statement nodes.
636
+ * @returns Formatted code as a string.
637
+ * @throws {Error} If no valid statements are provided.
638
+ */
639
+ static toCode(statements: Statement[]): string;
640
+ static write(code: string, filepath: string): Promise<void>;
641
+ /**
642
+ * Converts a path string with parameters into a TypeScript template expression.
643
+ * Handles query parameters and path placeholders.
644
+ *
645
+ * @param path - The base path string containing placeholders.
646
+ * @param parameters - Array of parameter objects defining the parameters.
647
+ * @param basePath - Optional base path to prepend (default: "").
648
+ * @returns A TypeScript template expressi
649
+ */
650
+ static toUrlTemplate(path: string, parameters: ParameterObject[], basePath?: string): import("typescript").NoSubstitutionTemplateLiteral | import("typescript").TemplateExpression;
651
+ /**
652
+ * Adds synthetic comments to a TypeScript AST node.
653
+ *
654
+ * @param node - The target AST node.
655
+ * @param comments - Array of comment objects to add.
656
+ */
657
+ static addComments(node: Node, comments: Comments): void;
658
+ /**
659
+ * Checks if a schema represents a binary type.
660
+ *
661
+ * @param schema - The schema object to check.
662
+ * @returns true if the schema is a binary type, false otherwise.
663
+ */
664
+ static isBinarySchema(schema: SchemaObject): boolean;
665
+ static toRequestBodyTypeNode(schema: SchemaObject): ParameterDeclaration;
666
+ static toTypeNode(schema: SchemaObject): TypeNode;
667
+ static toDeclarationNodes(parameters: ParameterObject[]): ParameterDeclaration[];
668
+ static toFormDataStatement(parameters: ParameterObject[], requestBody?: SchemaObject): Statement[];
669
+ static bodyBlock(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter): Block;
670
+ static schemaToStatemets(parsedDoc: ProviderInitResult, adaptor: Adapter, options: Omit<ProviderInitOptions, 'docURL' | 'output' | 'requestOptions'>): Statement[];
671
+ static prettier(code: string): Promise<string>;
672
+ static genCode(schema: ProviderInitResult, initOptions: ProviderInitOptions, adaptor: Adapter): Promise<string>;
516
673
  }
517
-
674
+ //#endregion
675
+ //#region src/openapi/index.d.ts
518
676
  declare enum OpenAPIVersion {
519
- v2 = "v2",
520
- v3 = "v3",
521
- v3_1 = "v3_1",
522
- unknown = "unknown"
677
+ v2 = "v2",
678
+ v3 = "v3",
679
+ v3_1 = "v3_1",
680
+ unknown = "unknown"
523
681
  }
524
682
  declare class OpenAPIProvider extends Provider {
525
- parse(doc: OpenAPIV3.Document): ProviderInitResult;
683
+ parse(doc: OpenAPIV3.Document): ProviderInitResult;
526
684
  }
527
- declare function codeGen(initOptions: ProviderInitOptions): Promise<string>;
528
-
529
- type apiCodeGenPluginOptions = ProviderInitOptions & {
530
- name: string;
531
- proxy?: ServerOptions["proxy"];
685
+ interface CodeGenResult {
686
+ code: string;
687
+ stats: {
688
+ endpoints: number;
689
+ schemas: number;
690
+ duration: number;
691
+ };
692
+ }
693
+ declare function codeGen(initOptions: ProviderInitOptions): Promise<CodeGenResult>;
694
+ //#endregion
695
+ //#region src/vite-plugin/index.d.ts
696
+ type ApiCodeGenPluginOptions = {
697
+ /** Human-readable name for this API config (required) */name: string; /** OpenAPI spec file path or URL */
698
+ spec?: string; /** Output file path */
699
+ output?: string; /** HTTP client adaptor */
700
+ adaptor?: 'fetch' | 'axios'; /** Base URL for API endpoints */
701
+ baseURL?: string; /** Custom client import source path */
702
+ importClientSource?: string; /** Enable verbose logging */
703
+ verbose?: boolean; /** Run type check after generation (default: true) */
704
+ typeCheck?: boolean;
532
705
  };
533
- declare const tsc: (path: string) => Promise<void>;
534
- declare function apiCodeGenPlugin(options: apiCodeGenPluginOptions[]): PluginOption;
535
-
536
- export { Adapter, Adaptors, ArraySchemaType, type ArrayTypeSchemaObject, AxiosAdapter, Base, type CommentObject, type Comments, type EnumSchemaObject, FetchAdapter, type FetchDocRequestInit, Generator, HttpMethods, type JSONValue, type MediaTypeObject, MediaTypes, NonArraySchemaType, OpenAPIProvider, OpenAPIVersion, type OperationObject, ParameterIn, type ParameterObject, type PathObject, type PathsObject, Provider, type ProviderInitOptions, type ProviderInitResult, type ReferenceObject, type RequestBodyObject, type ResponsesObject, SchemaFormatType, type SchemaObject, SchemaType, type SingleTypeSchemaObject, SuccessHttpStatusCode, apiCodeGenPlugin, type apiCodeGenPluginOptions, codeGen, tsc };
706
+ /**
707
+ * Main Vite plugin function
708
+ *
709
+ * @example
710
+ * ```ts
711
+ * // vite.config.ts
712
+ * import { apiCodeGenPlugin } from '@moccona/apicodegen/vite';
713
+ *
714
+ * export default defineConfig({
715
+ * plugins: [
716
+ * apiCodeGenPlugin([
717
+ * {
718
+ * name: 'my-api',
719
+ * spec: './openapi.json',
720
+ * output: './src/api/generated.ts',
721
+ * baseURL: 'https://api.example.com',
722
+ * },
723
+ * ]),
724
+ * ],
725
+ * });
726
+ * ```
727
+ */
728
+ declare function apiCodeGenPlugin(options: ApiCodeGenPluginOptions[]): PluginOption;
729
+ //#endregion
730
+ export { Adapter, Adaptors, ApiCodeGenPluginOptions, ApicodegenConfig, ApicodegenError, ApicodegenErrorContext, ArraySchemaType, ArrayTypeSchemaObject, AxiosAdapter, Base, CodeGenResult, Colors, CommentObject, Comments, ConfigAdaptor, EnumSchemaObject, ErrorCode, ErrorCodes, FetchAdapter, FetchDocRequestInit, Generator, HttpMethods, JSONValue, LoadConfigOptions, MediaTypeObject, MediaTypes, NonArraySchemaType, OpenAPIProvider, OpenAPIVersion, OperationObject, ParameterIn, ParameterObject, PathObject, PathsObject, Provider, ProviderInitOptions, ProviderInitResult, ReferenceObject, RequestBodyObject, ResolvedConfig, ResponsesObject, SchemaFormatType, SchemaObject, SchemaType, SingleTypeSchemaObject, SuccessHttpStatusCode, apiCodeGenPlugin, codeGen, configToCLIOptions, createErrors, formatError, isApicodegenError, loadConfig, printError, toProviderOptions, wrapError };
731
+ //# sourceMappingURL=index.d.cts.map