@moccona/apicodegen 0.0.3 → 0.0.7

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