@moccona/apicodegen 0.1.2 → 1.0.0
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/README.md +312 -29
- package/bin/cli.cjs +9 -6
- package/npm/index.cjs +1279 -311
- package/npm/index.cjs.map +1 -1
- package/npm/index.d.cts +293 -51
- package/npm/index.d.cts.map +1 -1
- package/npm/index.d.mts +293 -51
- package/npm/index.d.mts.map +1 -1
- package/npm/index.mjs +1271 -310
- package/npm/index.mjs.map +1 -1
- package/npm/vite/index.d.mts +27 -10
- package/npm/vite/index.d.mts.map +1 -1
- package/npm/vite/index.mjs +1259 -306
- package/npm/vite/index.mjs.map +1 -1
- package/package.json +36 -20
package/npm/index.d.cts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Block, Node, ParameterDeclaration, Statement, TypeNode } from "typescript";
|
|
1
|
+
import { Block, Expression, Node, ObjectLiteralElementLike, ParameterDeclaration, Statement, TypeNode } from "typescript";
|
|
2
2
|
import { OpenAPIV3 } from "openapi-types";
|
|
3
3
|
import { PluginOption } from "vite";
|
|
4
|
-
|
|
5
|
-
//#region src/core/interface.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* Simple represenration for JSON object
|
|
8
6
|
*/
|
|
@@ -46,21 +44,39 @@ declare enum ParameterIn {
|
|
|
46
44
|
interface ReferenceObject {
|
|
47
45
|
$ref: string;
|
|
48
46
|
}
|
|
47
|
+
/** OpenAPI 3 discriminator: property name plus value → schema ref map. */
|
|
48
|
+
interface DiscriminatorObject {
|
|
49
|
+
propertyName: string;
|
|
50
|
+
mapping?: Record<string, string>;
|
|
51
|
+
}
|
|
49
52
|
interface EnumSchemaObject {
|
|
50
53
|
name: string;
|
|
51
54
|
enum: (string | number)[];
|
|
52
55
|
}
|
|
53
56
|
interface SingleTypeSchemaObject {
|
|
54
57
|
type: keyof typeof NonArraySchemaType | string;
|
|
58
|
+
/** Explicit union from a JSON Schema `type` array (OpenAPI 3.1). */
|
|
59
|
+
types?: string[];
|
|
60
|
+
/** JSON Schema `nullable` (OpenAPI 3.0) or `null` in a type array. */
|
|
61
|
+
nullable?: boolean;
|
|
62
|
+
/** JSON Schema `const`: the only allowed value. */
|
|
63
|
+
const?: string | number | boolean;
|
|
64
|
+
/** Index signature for objects without fixed properties. */
|
|
65
|
+
additionalProperties?: boolean | SchemaObject;
|
|
55
66
|
description?: string;
|
|
56
67
|
allOf?: SchemaObject[];
|
|
57
68
|
anyOf?: SchemaObject[];
|
|
58
69
|
deprecated?: boolean;
|
|
70
|
+
discriminator?: DiscriminatorObject;
|
|
59
71
|
enum?: (string | number)[];
|
|
60
72
|
format?: keyof typeof SchemaFormatType;
|
|
61
73
|
oneOf?: SchemaObject[];
|
|
62
74
|
properties?: Record<string, SchemaObject>;
|
|
63
75
|
readonly?: boolean;
|
|
76
|
+
/** Present in requests only; omitted from generated response types (OpenAPI `writeOnly`). */
|
|
77
|
+
writeOnly?: boolean;
|
|
78
|
+
/** Present in responses only; omitted from generated request types (OpenAPI `readOnly`). */
|
|
79
|
+
readOnly?: boolean;
|
|
64
80
|
required?: string[] | boolean;
|
|
65
81
|
ref?: string;
|
|
66
82
|
isRef?: boolean;
|
|
@@ -69,17 +85,23 @@ interface ArrayTypeSchemaObject {
|
|
|
69
85
|
type: keyof typeof ArraySchemaType;
|
|
70
86
|
items?: SchemaObject;
|
|
71
87
|
required?: boolean;
|
|
88
|
+
nullable?: boolean;
|
|
72
89
|
description?: string;
|
|
73
90
|
ref?: string;
|
|
74
91
|
}
|
|
75
92
|
type SchemaObject = SingleTypeSchemaObject | ArrayTypeSchemaObject;
|
|
76
93
|
type ParameterObject = {
|
|
77
|
-
name: string;
|
|
94
|
+
name: string;
|
|
95
|
+
/** Where the parameter is sent. A missing `in` is treated as a body parameter. */
|
|
78
96
|
in?: keyof typeof ParameterIn;
|
|
79
97
|
schema?: SchemaObject;
|
|
80
98
|
required?: boolean;
|
|
81
99
|
description?: string;
|
|
82
100
|
deprecated?: boolean;
|
|
101
|
+
/** OpenAPI serialization style (e.g. `form`, `spaceDelimited`, `pipeDelimited`). */
|
|
102
|
+
style?: string;
|
|
103
|
+
/** Whether array/object values use repeated keys instead of one joined value. */
|
|
104
|
+
explode?: boolean;
|
|
83
105
|
ref?: string;
|
|
84
106
|
};
|
|
85
107
|
declare enum MediaTypes {
|
|
@@ -110,6 +132,18 @@ declare enum HttpMethods {
|
|
|
110
132
|
PATCH = "patch",
|
|
111
133
|
TRACE = "trace"
|
|
112
134
|
}
|
|
135
|
+
type SecuritySchemeObject = {
|
|
136
|
+
/** `apiKey`, `http`, `oauth2`, `openIdConnect`, or Swagger 2.0 `basic`. */
|
|
137
|
+
type: string;
|
|
138
|
+
/** HTTP auth scheme (`bearer` / `basic`). */
|
|
139
|
+
scheme?: string;
|
|
140
|
+
/** apiKey location. */
|
|
141
|
+
in?: 'header' | 'query' | 'cookie';
|
|
142
|
+
/** apiKey header/query/cookie name. */
|
|
143
|
+
name?: string;
|
|
144
|
+
};
|
|
145
|
+
/** A security requirement: scheme name → required scopes. */
|
|
146
|
+
type SecurityRequirementObject = Record<string, string[]>;
|
|
113
147
|
type OperationObject = {
|
|
114
148
|
method: string;
|
|
115
149
|
summary?: string;
|
|
@@ -121,7 +155,14 @@ type OperationObject = {
|
|
|
121
155
|
}[];
|
|
122
156
|
parameters?: ParameterObject[];
|
|
123
157
|
requestBody?: MediaTypeObject[];
|
|
158
|
+
/** Media type chosen for the function return value (first 2xx). */
|
|
124
159
|
responses: MediaTypeObject[];
|
|
160
|
+
/** Every declared status code, including error responses. */
|
|
161
|
+
responseTypes?: ResponsesObject;
|
|
162
|
+
/** OpenAPI tags (first tag selects the output file in split mode). */
|
|
163
|
+
tags?: string[];
|
|
164
|
+
/** Effective security requirements (operation-level, else document-level). */
|
|
165
|
+
security?: SecurityRequirementObject[];
|
|
125
166
|
deprecated?: boolean;
|
|
126
167
|
};
|
|
127
168
|
type PathObject = {
|
|
@@ -135,11 +176,32 @@ type FetchDocRequestInit = {
|
|
|
135
176
|
method?: string;
|
|
136
177
|
body?: string | FormData;
|
|
137
178
|
headers?: Record<string, string>;
|
|
179
|
+
/**
|
|
180
|
+
* Skip TLS certificate verification when fetching the spec.
|
|
181
|
+
* Only use this for trusted local/self-signed endpoints.
|
|
182
|
+
*/
|
|
183
|
+
insecure?: boolean;
|
|
184
|
+
/** Milliseconds to wait for response headers (undici). */
|
|
185
|
+
headersTimeout?: number;
|
|
186
|
+
/** Milliseconds to wait for the response body (undici). */
|
|
187
|
+
bodyTimeout?: number;
|
|
138
188
|
};
|
|
139
189
|
declare enum Adaptors {
|
|
140
190
|
fetch = "fetch",
|
|
141
191
|
axios = "axios"
|
|
142
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* How generated clients handle non-2xx responses.
|
|
195
|
+
*
|
|
196
|
+
* - `throw` — reject with an error carrying `status` and `body`.
|
|
197
|
+
* - `result` — resolve a `{ ok, status, data | error }` discriminated union.
|
|
198
|
+
*
|
|
199
|
+
* Omitted keeps the adaptor's current behaviour (fetch returns the response
|
|
200
|
+
* as-is; axios rejects on non-2xx).
|
|
201
|
+
*/
|
|
202
|
+
type ErrorMode = 'throw' | 'result';
|
|
203
|
+
/** Output layout: one file for everything, or one file per OpenAPI tag. */
|
|
204
|
+
type SplitBy = 'tag';
|
|
143
205
|
type ProviderInitOptions = {
|
|
144
206
|
docURL: string;
|
|
145
207
|
output: string;
|
|
@@ -148,6 +210,18 @@ type ProviderInitOptions = {
|
|
|
148
210
|
requestOptions?: FetchDocRequestInit;
|
|
149
211
|
verbose?: boolean;
|
|
150
212
|
adaptor?: keyof typeof Adaptors;
|
|
213
|
+
/** How generated clients handle non-2xx responses (default: leave as-is). */
|
|
214
|
+
errorMode?: ErrorMode;
|
|
215
|
+
/** Split output into one file per tag (default: single file). */
|
|
216
|
+
splitBy?: SplitBy;
|
|
217
|
+
/** Keep only operations carrying at least one of these tags. */
|
|
218
|
+
includeTags?: string[];
|
|
219
|
+
/** Drop operations carrying any of these tags. */
|
|
220
|
+
excludeTags?: string[];
|
|
221
|
+
/** Keep only paths starting with one of these prefixes. */
|
|
222
|
+
includePaths?: string[];
|
|
223
|
+
/** Drop paths starting with one of these prefixes. */
|
|
224
|
+
excludePaths?: string[];
|
|
151
225
|
};
|
|
152
226
|
interface ProviderInitResult {
|
|
153
227
|
readonly enums: EnumSchemaObject[];
|
|
@@ -155,10 +229,53 @@ interface ProviderInitResult {
|
|
|
155
229
|
readonly parameters: Record<string, ParameterObject>;
|
|
156
230
|
readonly responses: Record<string, ResponsesObject>;
|
|
157
231
|
readonly requestBodies: Record<string, RequestBodyObject>;
|
|
232
|
+
readonly securitySchemes: Record<string, SecuritySchemeObject>;
|
|
158
233
|
readonly apis: PathsObject;
|
|
159
234
|
}
|
|
160
|
-
|
|
161
|
-
|
|
235
|
+
/**
|
|
236
|
+
* How a security scheme is injected into a generated request.
|
|
237
|
+
*/
|
|
238
|
+
type AuthInjection = {
|
|
239
|
+
/** Key into the generated `AuthOptions` object. */
|
|
240
|
+
scheme: string;
|
|
241
|
+
location: 'header' | 'query' | 'cookie';
|
|
242
|
+
/** Header / query / cookie name. */
|
|
243
|
+
name: string;
|
|
244
|
+
/** `raw` = direct value, `bearer` = `Bearer <token>`, `basic` = base64 pair. */
|
|
245
|
+
kind: 'raw' | 'bearer' | 'basic';
|
|
246
|
+
};
|
|
247
|
+
/** The generated auth argument: parameter name plus its injections. */
|
|
248
|
+
type AuthArgument = {
|
|
249
|
+
name: string;
|
|
250
|
+
injections: AuthInjection[];
|
|
251
|
+
};
|
|
252
|
+
/** The generated request-options argument (`signal`, `headers`, `timeout`). */
|
|
253
|
+
type RequestControl = {
|
|
254
|
+
/** Parameter name in the generated function, e.g. `options`. */
|
|
255
|
+
name: string;
|
|
256
|
+
};
|
|
257
|
+
/** `options?.name` */
|
|
258
|
+
declare function optionalAccess(control: RequestControl, name: string): Expression;
|
|
259
|
+
/**
|
|
260
|
+
* `options?.signal && options?.timeout ? AbortSignal.any([...]) : ...`,
|
|
261
|
+
* combining a caller signal with a timeout when both are present.
|
|
262
|
+
*/
|
|
263
|
+
declare function fetchSignalExpression(control: RequestControl): Expression;
|
|
264
|
+
/**
|
|
265
|
+
* Header entries plus a spread of caller-supplied headers.
|
|
266
|
+
*/
|
|
267
|
+
declare function withRequestHeaders(entries: ObjectLiteralElementLike[], control: RequestControl | undefined): ObjectLiteralElementLike[];
|
|
268
|
+
/** `auth?.["scheme"]` */
|
|
269
|
+
declare function authAccess(auth: AuthArgument, scheme: string): Expression;
|
|
270
|
+
/**
|
|
271
|
+
* Header entries (conditional spreads) for auth schemes sent as headers.
|
|
272
|
+
*/
|
|
273
|
+
declare function authHeaderEntries(auth: AuthArgument): ObjectLiteralElementLike[];
|
|
274
|
+
/**
|
|
275
|
+
* Builds a `Cookie` header value from OpenAPI cookie parameters.
|
|
276
|
+
* Undefined/null values are filtered out at runtime.
|
|
277
|
+
*/
|
|
278
|
+
declare function cookieHeaderExpression(parameters: ParameterObject[], auth?: AuthArgument): Expression;
|
|
162
279
|
/**
|
|
163
280
|
* Body shape used to encode the request payload.
|
|
164
281
|
*
|
|
@@ -205,12 +322,13 @@ declare abstract class Adapter {
|
|
|
205
322
|
* @param {BodyKind} bodyKind - How the request body should be encoded
|
|
206
323
|
* @param {string | undefined} bodyContentType - The Content-Type header to set (undefined means "let the runtime decide", e.g. for multipart with boundary)
|
|
207
324
|
* @param {boolean} useJSONResponse - Flag indicating whether the response should be parsed as JSON
|
|
325
|
+
* @param {ErrorMode | undefined} errorMode - Non-2xx handling (undefined keeps current behaviour)
|
|
326
|
+
* @param {AuthArgument} auth - Security credentials to inject (if any)
|
|
327
|
+
* @param {RequestControl} requestControl - Request options argument (if any)
|
|
208
328
|
* @returns {Statement[]} An array of TypeScript AST statements representing the generated code
|
|
209
329
|
*/
|
|
210
|
-
abstract client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, useJSONResponse: boolean): Statement[];
|
|
330
|
+
abstract client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, useJSONResponse: boolean, errorMode?: ErrorMode, auth?: AuthArgument, requestControl?: RequestControl): Statement[];
|
|
211
331
|
}
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/core/base/Base.d.ts
|
|
214
332
|
/**
|
|
215
333
|
* Represents success HTTP status codes.
|
|
216
334
|
* Each key is a string representation of a success HTTP status code.
|
|
@@ -247,6 +365,14 @@ declare abstract class Base {
|
|
|
247
365
|
* @returns - The generated function name.
|
|
248
366
|
*/
|
|
249
367
|
static pathToFnName(path: string, method?: string, operationId?: string): string;
|
|
368
|
+
/**
|
|
369
|
+
* Converts arbitrary text into a legal TypeScript variable identifier.
|
|
370
|
+
* Keywords keep the `_` suffix that `normalize` adds, since `camelCase`
|
|
371
|
+
* would otherwise strip it and emit a reserved word.
|
|
372
|
+
* @param text - Input text.
|
|
373
|
+
* @returns - A legal identifier.
|
|
374
|
+
*/
|
|
375
|
+
static toIdentifier(text: string): string;
|
|
250
376
|
/**
|
|
251
377
|
* Normalizes a string by replacing special characters and avoiding TypeScript keywords.
|
|
252
378
|
* @param text - Input text to normalize.
|
|
@@ -308,12 +434,24 @@ declare abstract class Base {
|
|
|
308
434
|
* @returns - A promise resolving to the parsed document.
|
|
309
435
|
*/
|
|
310
436
|
private static readLocalDoc;
|
|
437
|
+
/**
|
|
438
|
+
* Parses an OpenAPI document from JSON or YAML text.
|
|
439
|
+
*
|
|
440
|
+
* JSON is attempted first for a clearer syntax error on JSON files; YAML
|
|
441
|
+
* then handles `.yaml` / `.yml` specs. Any failure is reported as
|
|
442
|
+
* `E_SPEC_PARSE_FAILED` with the source path attached.
|
|
443
|
+
*
|
|
444
|
+
* @param raw - Raw spec content.
|
|
445
|
+
* @param source - Path or URL used in error messages.
|
|
446
|
+
* @returns - The parsed document.
|
|
447
|
+
*/
|
|
448
|
+
static parseDoc<T = unknown>(raw: string, source: string): T;
|
|
311
449
|
/**
|
|
312
450
|
* Fetches documentation from a given URL.
|
|
313
451
|
*
|
|
314
452
|
* Supports three transport modes:
|
|
315
|
-
* - `file://...` URLs → read from filesystem (
|
|
316
|
-
* - absolute filesystem paths → read from filesystem (
|
|
453
|
+
* - `file://...` URLs → read from filesystem (JSON or YAML)
|
|
454
|
+
* - absolute filesystem paths → read from filesystem (JSON or YAML)
|
|
317
455
|
* - `http(s)://...` URLs (and unrecognised inputs like relative paths)
|
|
318
456
|
* → fetched via undici (existing behavior)
|
|
319
457
|
*
|
|
@@ -323,9 +461,31 @@ declare abstract class Base {
|
|
|
323
461
|
*
|
|
324
462
|
* @param url - The URL or filesystem path to fetch the documentation from.
|
|
325
463
|
* @param requestInit - Additional request parameters (only used for http(s)).
|
|
464
|
+
* TLS certificates are verified by default; set `insecure: true` to opt out.
|
|
326
465
|
* @returns - A promise resolving to the fetched documentation data.
|
|
327
466
|
*/
|
|
328
467
|
static fetchDoc<T = unknown>(url: string, requestInit?: FetchDocRequestInit): Promise<T>;
|
|
468
|
+
/**
|
|
469
|
+
* Copies external `$ref` targets (other files or remote URLs) into the root
|
|
470
|
+
* document and rewrites the refs to local ones. Objects are registered
|
|
471
|
+
* before their children are walked, so cycles keep working.
|
|
472
|
+
*
|
|
473
|
+
* External refs are placed in the component section implied by their
|
|
474
|
+
* fragment (`schemas` by default); a generated local `$ref` points at the
|
|
475
|
+
* copy.
|
|
476
|
+
*
|
|
477
|
+
* @param doc - Parsed root document (mutated in place).
|
|
478
|
+
* @param source - Absolute path or URL of the root document.
|
|
479
|
+
* @param requestInit - Request options for remote refs.
|
|
480
|
+
* @returns - The same document with external refs resolved.
|
|
481
|
+
*/
|
|
482
|
+
static bundleExternalRefs<T>(doc: T, source: string, requestInit?: FetchDocRequestInit): Promise<T>;
|
|
483
|
+
/** Component section an external ref belongs to. */
|
|
484
|
+
private static externalRefSection;
|
|
485
|
+
/** Local component name derived from the ref fragment or file name. */
|
|
486
|
+
private static externalRefName;
|
|
487
|
+
/** Resolves a `#/a/b` JSON pointer inside a parsed document. */
|
|
488
|
+
private static resolveJSONPointer;
|
|
329
489
|
/**
|
|
330
490
|
* Determines the media type from a given media type string.
|
|
331
491
|
* @param mediaType - The media type string to evaluate.
|
|
@@ -371,8 +531,6 @@ declare abstract class Base {
|
|
|
371
531
|
*/
|
|
372
532
|
static isRef(schema: unknown): schema is ReferenceObject;
|
|
373
533
|
}
|
|
374
|
-
//#endregion
|
|
375
|
-
//#region src/core/base/Provider.d.ts
|
|
376
534
|
/**
|
|
377
535
|
* Abstract Provider Class.
|
|
378
536
|
*
|
|
@@ -416,6 +574,8 @@ declare abstract class Provider implements ProviderInitResult, ProviderInitOptio
|
|
|
416
574
|
readonly responses: Record<string, ResponsesObject>;
|
|
417
575
|
/** collection of request bodies indexed by name */
|
|
418
576
|
readonly requestBodies: Record<string, RequestBodyObject>;
|
|
577
|
+
/** security schemes declared by the document */
|
|
578
|
+
readonly securitySchemes: Record<string, SecuritySchemeObject>;
|
|
419
579
|
/** collection of API endpoints (operations) indexed by path */
|
|
420
580
|
readonly apis: Record<string, OperationObject[]>;
|
|
421
581
|
/** URL for fetching API documentation */
|
|
@@ -444,8 +604,6 @@ declare abstract class Provider implements ProviderInitResult, ProviderInitOptio
|
|
|
444
604
|
*/
|
|
445
605
|
abstract parse(doc: unknown): ProviderInitResult;
|
|
446
606
|
}
|
|
447
|
-
//#endregion
|
|
448
|
-
//#region src/core/client/axios.d.ts
|
|
449
607
|
/**
|
|
450
608
|
* Adapter class implementing support for generating code that makes use of the Axios HTTP client library.
|
|
451
609
|
* This adapter defines custom behavior and field mappings specific to the Axios client.
|
|
@@ -476,10 +634,8 @@ declare class AxiosAdapter extends Adapter {
|
|
|
476
634
|
*
|
|
477
635
|
* @returns {Statement[]} An array of TypeScript statements that define the client configuration.
|
|
478
636
|
*/
|
|
479
|
-
client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, _shouldUseJSONResponse: boolean): Statement[];
|
|
637
|
+
client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, _shouldUseJSONResponse: boolean, errorMode?: ErrorMode, auth?: AuthArgument, requestControl?: RequestControl): Statement[];
|
|
480
638
|
}
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/core/client/fetch.d.ts
|
|
483
639
|
/**
|
|
484
640
|
* FetchAdapter is an adapter class that generates client-side fetch requests.
|
|
485
641
|
* It handles parameters, headers, and request bodies to construct proper fetch calls.
|
|
@@ -503,10 +659,8 @@ declare class FetchAdapter extends Adapter {
|
|
|
503
659
|
* @param shouldUseJSONResponse - Flag to use JSON parsing for the response
|
|
504
660
|
* @return - An array of generated TypeScript statements
|
|
505
661
|
*/
|
|
506
|
-
client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, shouldUseJSONResponse: boolean): Statement[];
|
|
662
|
+
client(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, bodyKind: BodyKind, bodyContentType: string | undefined, shouldUseJSONResponse: boolean, errorMode?: ErrorMode, auth?: AuthArgument, requestControl?: RequestControl): Statement[];
|
|
507
663
|
}
|
|
508
|
-
//#endregion
|
|
509
|
-
//#region src/core/config.d.ts
|
|
510
664
|
/**
|
|
511
665
|
* Adaptor type for HTTP client
|
|
512
666
|
*/
|
|
@@ -515,6 +669,8 @@ type ConfigAdaptor = keyof typeof Adaptors;
|
|
|
515
669
|
* Shared config interface for CLI and Vite plugin
|
|
516
670
|
*/
|
|
517
671
|
interface ApicodegenConfig {
|
|
672
|
+
/** Display name used in logs and multi-spec configs */
|
|
673
|
+
name?: string;
|
|
518
674
|
/** OpenAPI spec file path or URL (required) */
|
|
519
675
|
spec: string;
|
|
520
676
|
/** Output file path */
|
|
@@ -531,8 +687,22 @@ interface ApicodegenConfig {
|
|
|
531
687
|
typeCheck?: boolean;
|
|
532
688
|
/** Watch for file changes */
|
|
533
689
|
watch?: boolean;
|
|
690
|
+
/** Fail when generated output differs from what is on disk */
|
|
691
|
+
check?: boolean;
|
|
534
692
|
/** Request options for fetching spec */
|
|
535
693
|
requestOptions?: FetchDocRequestInit;
|
|
694
|
+
/** Non-2xx handling for generated clients (throw|result; default: as-is) */
|
|
695
|
+
errorMode?: ErrorMode;
|
|
696
|
+
/** Split output into one file per tag (default: single file) */
|
|
697
|
+
splitBy?: SplitBy;
|
|
698
|
+
/** Keep only operations carrying at least one of these tags */
|
|
699
|
+
includeTags?: string[];
|
|
700
|
+
/** Drop operations carrying any of these tags */
|
|
701
|
+
excludeTags?: string[];
|
|
702
|
+
/** Keep only paths starting with one of these prefixes */
|
|
703
|
+
includePaths?: string[];
|
|
704
|
+
/** Drop paths starting with one of these prefixes */
|
|
705
|
+
excludePaths?: string[];
|
|
536
706
|
}
|
|
537
707
|
/**
|
|
538
708
|
* Options for loading config
|
|
@@ -561,12 +731,21 @@ interface ResolvedConfig extends ApicodegenConfig {
|
|
|
561
731
|
* Priority: defaults < env vars < config file < CLI args
|
|
562
732
|
*/
|
|
563
733
|
declare function mergeConfigs(base: ApicodegenConfig, ...sources: (Partial<ApicodegenConfig> | undefined)[]): ApicodegenConfig;
|
|
734
|
+
/**
|
|
735
|
+
* Validate field types before the values reach the generator.
|
|
736
|
+
*/
|
|
737
|
+
declare function validateConfigShape(config: Partial<ApicodegenConfig>): void;
|
|
564
738
|
/**
|
|
565
739
|
* Validate config has required fields
|
|
566
740
|
*/
|
|
567
741
|
declare function validateConfig(config: Partial<ApicodegenConfig>): config is ApicodegenConfig;
|
|
568
742
|
/**
|
|
569
|
-
* Load and resolve config
|
|
743
|
+
* Load and resolve every config entry. A config file may define a single
|
|
744
|
+
* object or a `specs` array for multi-spec projects.
|
|
745
|
+
*/
|
|
746
|
+
declare function loadConfigs(options?: LoadConfigOptions): Promise<ResolvedConfig[]>;
|
|
747
|
+
/**
|
|
748
|
+
* Load a single config. Throws when the file defines no entries.
|
|
570
749
|
*/
|
|
571
750
|
declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
|
|
572
751
|
/**
|
|
@@ -584,9 +763,13 @@ declare function toProviderOptions(config: ResolvedConfig): {
|
|
|
584
763
|
importClientSource: string | undefined;
|
|
585
764
|
verbose: boolean | undefined;
|
|
586
765
|
requestOptions: FetchDocRequestInit | undefined;
|
|
766
|
+
errorMode: ErrorMode | undefined;
|
|
767
|
+
splitBy: "tag" | undefined;
|
|
768
|
+
includeTags: string[] | undefined;
|
|
769
|
+
excludeTags: string[] | undefined;
|
|
770
|
+
includePaths: string[] | undefined;
|
|
771
|
+
excludePaths: string[] | undefined;
|
|
587
772
|
};
|
|
588
|
-
//#endregion
|
|
589
|
-
//#region src/core/errors.d.ts
|
|
590
773
|
/**
|
|
591
774
|
* Error handling utilities for api-codegen
|
|
592
775
|
*/
|
|
@@ -647,16 +830,16 @@ declare class ApicodegenError extends Error {
|
|
|
647
830
|
* ANSI color codes for terminal output
|
|
648
831
|
*/
|
|
649
832
|
declare const Colors: {
|
|
650
|
-
readonly reset: "
|
|
651
|
-
readonly bold: "
|
|
652
|
-
readonly red: "
|
|
653
|
-
readonly green: "
|
|
654
|
-
readonly yellow: "
|
|
655
|
-
readonly blue: "
|
|
656
|
-
readonly cyan: "
|
|
657
|
-
readonly gray: "
|
|
658
|
-
readonly brightRed: "
|
|
659
|
-
readonly brightGreen: "
|
|
833
|
+
readonly reset: "[0m";
|
|
834
|
+
readonly bold: "[1m";
|
|
835
|
+
readonly red: "[31m";
|
|
836
|
+
readonly green: "[32m";
|
|
837
|
+
readonly yellow: "[33m";
|
|
838
|
+
readonly blue: "[34m";
|
|
839
|
+
readonly cyan: "[36m";
|
|
840
|
+
readonly gray: "[90m";
|
|
841
|
+
readonly brightRed: "[91m";
|
|
842
|
+
readonly brightGreen: "[92m";
|
|
660
843
|
};
|
|
661
844
|
/**
|
|
662
845
|
* Format error for CLI output
|
|
@@ -677,6 +860,7 @@ declare const createErrors: {
|
|
|
677
860
|
configInvalid(path: string, cause?: Error): ApicodegenError;
|
|
678
861
|
validationFailed(path: string, details: string, cause?: Error): ApicodegenError;
|
|
679
862
|
generationFailed(cause?: Error): ApicodegenError;
|
|
863
|
+
writeFailed(path: string, cause?: Error): ApicodegenError;
|
|
680
864
|
typeCheckFailed(path: string, _errors: string[], cause?: Error): ApicodegenError;
|
|
681
865
|
missingRequiredField(field: string, context?: string): ApicodegenError;
|
|
682
866
|
};
|
|
@@ -688,8 +872,6 @@ declare function wrapError(error: unknown, context?: Partial<ApicodegenErrorCont
|
|
|
688
872
|
* Check if error is an ApicodegenError
|
|
689
873
|
*/
|
|
690
874
|
declare function isApicodegenError(error: unknown): error is ApicodegenError;
|
|
691
|
-
//#endregion
|
|
692
|
-
//#region src/core/generator/index.d.ts
|
|
693
875
|
/**
|
|
694
876
|
* Represents a comment object with optional tag and message.
|
|
695
877
|
*/
|
|
@@ -722,7 +904,16 @@ declare class Generator {
|
|
|
722
904
|
* @param basePath - Optional base path to prepend (default: "").
|
|
723
905
|
* @returns A TypeScript template expressi
|
|
724
906
|
*/
|
|
725
|
-
static toUrlTemplate(path: string, parameters: ParameterObject[], basePath?: string):
|
|
907
|
+
static toUrlTemplate(path: string, parameters: ParameterObject[], basePath?: string, auth?: AuthArgument): Expression;
|
|
908
|
+
/**
|
|
909
|
+
* Builds the path part of a URL, encoding every `{param}` interpolation.
|
|
910
|
+
*/
|
|
911
|
+
private static toPathTemplate;
|
|
912
|
+
/**
|
|
913
|
+
* Emits an IIFE that builds a query string, omitting undefined/null
|
|
914
|
+
* values and honouring array `explode` / delimiter styles.
|
|
915
|
+
*/
|
|
916
|
+
private static toQueryStringExpression;
|
|
726
917
|
/**
|
|
727
918
|
* Adds synthetic comments to a TypeScript AST node.
|
|
728
919
|
*
|
|
@@ -737,13 +928,26 @@ declare class Generator {
|
|
|
737
928
|
* @returns true if the schema is a binary type, false otherwise.
|
|
738
929
|
*/
|
|
739
930
|
static isBinarySchema(schema: SchemaObject): boolean;
|
|
931
|
+
/** Whether a schema is a primitive text part (not binary, ref, or object). */
|
|
932
|
+
static isTextSchema(schema: SchemaObject): boolean;
|
|
740
933
|
static schemaToTypeString(schema: SchemaObject): string;
|
|
741
934
|
static generateParamTags(parameters: ParameterObject[], requestBody?: MediaTypeObject): CommentObject[];
|
|
742
935
|
static toRequestBodyTypeNode(schema: SchemaObject): ParameterDeclaration;
|
|
936
|
+
/**
|
|
937
|
+
* Narrows a `oneOf` member with its discriminator mapping value:
|
|
938
|
+
* `Cat & { petType: 'cat' }`.
|
|
939
|
+
*/
|
|
940
|
+
private static discriminatedMember;
|
|
743
941
|
static toTypeNode(schema: SchemaObject): TypeNode;
|
|
942
|
+
private static toLiteralTypeNode;
|
|
943
|
+
private static primitiveTypeNode;
|
|
944
|
+
private static toTypeNodeInner;
|
|
945
|
+
static toResponsesTypeNode(responses: ResponsesObject): TypeNode;
|
|
744
946
|
static deduplicateTypes(types: TypeNode[]): TypeNode[];
|
|
745
947
|
static getTypeNodeKey(type: TypeNode): string;
|
|
746
948
|
static toDeclarationNodes(parameters: ParameterObject[]): ParameterDeclaration[];
|
|
949
|
+
/** Property keys listed in a parent schema's `required` array. */
|
|
950
|
+
private static requiredPropertyKeys;
|
|
747
951
|
static toFormDataStatement(parameters: ParameterObject[], requestBody?: SchemaObject): Statement[];
|
|
748
952
|
/**
|
|
749
953
|
* Build statements that construct a `URLSearchParams` from request body
|
|
@@ -762,13 +966,32 @@ declare class Generator {
|
|
|
762
966
|
* everything else is coerced via `String(...)`.
|
|
763
967
|
*/
|
|
764
968
|
private static toFormDataCompatibleString;
|
|
765
|
-
static bodyBlock(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter): Block;
|
|
969
|
+
static bodyBlock(uri: string, method: string, parameters: ParameterObject[], requestBody: MediaTypeObject | undefined, response: MediaTypeObject | undefined, adapter: Adapter, errorMode?: ErrorMode, auth?: AuthArgument, requestControl?: RequestControl): Block;
|
|
970
|
+
/**
|
|
971
|
+
* Resolves effective security requirements into concrete injections.
|
|
972
|
+
* Requirements are OR-ed by the spec; we inject every credential the
|
|
973
|
+
* caller provides, so either branch of an OR works.
|
|
974
|
+
*/
|
|
975
|
+
static toAuthInjections(security: SecurityRequirementObject[] | undefined, schemes: Record<string, SecuritySchemeObject>): AuthInjection[];
|
|
976
|
+
/** `{ [scheme: string]: string | { username: string; password: string } }` */
|
|
977
|
+
private static authOptionsTypeNode;
|
|
978
|
+
/** `{ signal?: AbortSignal; headers?: Record<string, string>; timeout?: number }` */
|
|
979
|
+
private static requestOptionsTypeNode;
|
|
766
980
|
static schemaToStatemets(parsedDoc: ProviderInitResult, adaptor: Adapter, options: Omit<ProviderInitOptions, 'docURL' | 'output' | 'requestOptions'>): Statement[];
|
|
767
981
|
static prettier(code: string): Promise<string>;
|
|
982
|
+
/**
|
|
983
|
+
* Splits generated code into `types.ts`, one file per tag, and `index.ts`.
|
|
984
|
+
* Shared type declarations live in `types.ts`; tag files import them and
|
|
985
|
+
* export only their functions.
|
|
986
|
+
*/
|
|
987
|
+
static genCodeMulti(schema: ProviderInitResult, initOptions: ProviderInitOptions, adaptor: Adapter): Promise<{
|
|
988
|
+
code: string;
|
|
989
|
+
files: Record<string, string>;
|
|
990
|
+
}>;
|
|
991
|
+
/** Lower-case file stem that cannot collide with reserved or earlier names. */
|
|
992
|
+
private static uniqueFileName;
|
|
768
993
|
static genCode(schema: ProviderInitResult, initOptions: ProviderInitOptions, adaptor: Adapter): Promise<string>;
|
|
769
994
|
}
|
|
770
|
-
//#endregion
|
|
771
|
-
//#region src/openapi/index.d.ts
|
|
772
995
|
declare enum OpenAPIVersion {
|
|
773
996
|
v2 = "v2",
|
|
774
997
|
v3 = "v3",
|
|
@@ -780,6 +1003,8 @@ declare class OpenAPIProvider extends Provider {
|
|
|
780
1003
|
}
|
|
781
1004
|
interface CodeGenResult {
|
|
782
1005
|
code: string;
|
|
1006
|
+
/** Additional files when `splitBy` is enabled (name → content). */
|
|
1007
|
+
files?: Record<string, string>;
|
|
783
1008
|
stats: {
|
|
784
1009
|
endpoints: number;
|
|
785
1010
|
schemas: number;
|
|
@@ -787,16 +1012,34 @@ interface CodeGenResult {
|
|
|
787
1012
|
};
|
|
788
1013
|
}
|
|
789
1014
|
declare function codeGen(initOptions: ProviderInitOptions): Promise<CodeGenResult>;
|
|
790
|
-
//#endregion
|
|
791
|
-
//#region src/vite-plugin/index.d.ts
|
|
792
1015
|
type ApiCodeGenPluginOptions = {
|
|
793
|
-
/** Human-readable name for this API config (required) */
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1016
|
+
/** Human-readable name for this API config (required) */
|
|
1017
|
+
name: string;
|
|
1018
|
+
/** OpenAPI spec file path or URL */
|
|
1019
|
+
spec?: string;
|
|
1020
|
+
/** Output file path */
|
|
1021
|
+
output?: string;
|
|
1022
|
+
/** HTTP client adaptor */
|
|
1023
|
+
adaptor?: 'fetch' | 'axios';
|
|
1024
|
+
/** Non-2xx handling in generated clients (throw|result; default: as-is) */
|
|
1025
|
+
errorMode?: 'throw' | 'result';
|
|
1026
|
+
/** Split output into one file per tag (default: single file) */
|
|
1027
|
+
splitBy?: 'tag';
|
|
1028
|
+
/** Keep only operations carrying at least one of these tags */
|
|
1029
|
+
includeTags?: string[];
|
|
1030
|
+
/** Drop operations carrying any of these tags */
|
|
1031
|
+
excludeTags?: string[];
|
|
1032
|
+
/** Keep only paths starting with one of these prefixes */
|
|
1033
|
+
includePaths?: string[];
|
|
1034
|
+
/** Drop paths starting with one of these prefixes */
|
|
1035
|
+
excludePaths?: string[];
|
|
1036
|
+
/** Base URL for API endpoints */
|
|
1037
|
+
baseURL?: string;
|
|
1038
|
+
/** Custom client import source path */
|
|
1039
|
+
importClientSource?: string;
|
|
1040
|
+
/** Enable verbose logging */
|
|
1041
|
+
verbose?: boolean;
|
|
1042
|
+
/** Run type check after generation (default: true) */
|
|
800
1043
|
typeCheck?: boolean;
|
|
801
1044
|
/**
|
|
802
1045
|
* Enable on-disk caching of generated code (default: true).
|
|
@@ -833,6 +1076,5 @@ type ApiCodeGenPluginOptions = {
|
|
|
833
1076
|
* ```
|
|
834
1077
|
*/
|
|
835
1078
|
declare function apiCodeGenPlugin(options: ApiCodeGenPluginOptions[]): PluginOption;
|
|
836
|
-
|
|
837
|
-
export { Adapter, Adaptors, ApiCodeGenPluginOptions, ApicodegenConfig, ApicodegenError, ApicodegenErrorContext, ArraySchemaType, ArrayTypeSchemaObject, AxiosAdapter, Base, BodyKind, 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, mergeConfigs, printError, toProviderOptions, validateConfig, wrapError };
|
|
1079
|
+
export { Adapter, Adaptors, ApiCodeGenPluginOptions, ApicodegenConfig, ApicodegenError, ApicodegenErrorContext, ArraySchemaType, ArrayTypeSchemaObject, AuthArgument, AuthInjection, AxiosAdapter, Base, BodyKind, CodeGenResult, Colors, CommentObject, Comments, ConfigAdaptor, DiscriminatorObject, EnumSchemaObject, ErrorCode, ErrorCodes, ErrorMode, FetchAdapter, FetchDocRequestInit, Generator, HttpMethods, JSONValue, LoadConfigOptions, MediaTypeObject, MediaTypes, NonArraySchemaType, OpenAPIProvider, OpenAPIVersion, OperationObject, ParameterIn, ParameterObject, PathObject, PathsObject, Provider, ProviderInitOptions, ProviderInitResult, ReferenceObject, RequestBodyObject, RequestControl, ResolvedConfig, ResponsesObject, SchemaFormatType, SchemaObject, SchemaType, SecurityRequirementObject, SecuritySchemeObject, SingleTypeSchemaObject, SplitBy, SuccessHttpStatusCode, apiCodeGenPlugin, authAccess, authHeaderEntries, codeGen, configToCLIOptions, cookieHeaderExpression, createErrors, fetchSignalExpression, formatError, isApicodegenError, loadConfig, loadConfigs, mergeConfigs, optionalAccess, printError, toProviderOptions, validateConfig, validateConfigShape, withRequestHeaders, wrapError };
|
|
838
1080
|
//# sourceMappingURL=index.d.cts.map
|