@powerduck/openapi-codegen 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +195 -72
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +271 -0
- package/dist/index.d.ts +271 -0
- package/dist/index.js +1 -6785
- package/dist/index.js.map +1 -0
- package/package.json +35 -25
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for OpenAPI3.2 code-generation library
|
|
3
|
+
* Browser-compatible, compliant with OAS 3.2 specification
|
|
4
|
+
*/
|
|
5
|
+
type ParameterLocation = "path" | "query" | "querystring" | "header" | "cookie";
|
|
6
|
+
interface FileValue {
|
|
7
|
+
__file: true;
|
|
8
|
+
path?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
data?: string | ArrayBuffer | Uint8Array | Blob;
|
|
12
|
+
}
|
|
13
|
+
interface Parameter {
|
|
14
|
+
name: string;
|
|
15
|
+
in: ParameterLocation;
|
|
16
|
+
value: unknown;
|
|
17
|
+
style?: string;
|
|
18
|
+
explode?: boolean;
|
|
19
|
+
allowReserved?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface Body {
|
|
22
|
+
mediaType: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
encoding?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
interface Security {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
scheme?: string;
|
|
30
|
+
in?: string;
|
|
31
|
+
paramName?: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
interface RequestIR {
|
|
35
|
+
method: string;
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
path: string;
|
|
38
|
+
parameters: Parameter[];
|
|
39
|
+
headers: Parameter[];
|
|
40
|
+
body?: Body;
|
|
41
|
+
security: Security[];
|
|
42
|
+
}
|
|
43
|
+
interface GenerateResult {
|
|
44
|
+
code: string;
|
|
45
|
+
files?: Record<string, string>;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
interface Generator {
|
|
49
|
+
language: string;
|
|
50
|
+
client: string;
|
|
51
|
+
generate(request: RequestIR): string;
|
|
52
|
+
}
|
|
53
|
+
interface Plugin {
|
|
54
|
+
name: string;
|
|
55
|
+
register(api: {
|
|
56
|
+
register(generator: Generator): void;
|
|
57
|
+
}): void;
|
|
58
|
+
}
|
|
59
|
+
interface GenerateOptions {
|
|
60
|
+
language: string;
|
|
61
|
+
client: string;
|
|
62
|
+
request?: RequestIR;
|
|
63
|
+
document?: unknown;
|
|
64
|
+
path?: string;
|
|
65
|
+
method?: string;
|
|
66
|
+
serverUrl?: string;
|
|
67
|
+
securityValues?: Record<string, string>;
|
|
68
|
+
softRefMode?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* RefResolver for OpenAPI 3.2, browser-compatible, only supports in-document JSON-Pointer references starting with #/
|
|
73
|
+
* Compliant: https://spec.openapis.org/oas/3.2/schema/2025-11-23.html
|
|
74
|
+
*/
|
|
75
|
+
declare class RefResolver {
|
|
76
|
+
private readonly root;
|
|
77
|
+
private readonly cache;
|
|
78
|
+
private readonly stack;
|
|
79
|
+
/** When softMode=true: do NOT throw on broken/circular refs; return partial/original value instead */
|
|
80
|
+
softMode: boolean;
|
|
81
|
+
constructor(root: unknown, softMode?: boolean);
|
|
82
|
+
/**
|
|
83
|
+
* Dereference value, if it contains $ref, resolve it; otherwise return original value.
|
|
84
|
+
* Does NOT validate type of resolved result, only resolves pointer.
|
|
85
|
+
*/
|
|
86
|
+
deref<T = unknown>(value: T): T;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve JSON Pointer $ref starting with #/.
|
|
89
|
+
* Throws for external refs, circular refs, broken pointers unless softMode is enabled.
|
|
90
|
+
*/
|
|
91
|
+
resolveRef<T = unknown>(ref: string): T;
|
|
92
|
+
/** Clear internal cache, for reuse with different documents. */
|
|
93
|
+
clearCache(): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Context for example generation, controls readOnly/writeOnly filtering.
|
|
98
|
+
* - isRequestBody: true → skip readOnly properties
|
|
99
|
+
* - isResponse: true → skip writeOnly properties
|
|
100
|
+
*/
|
|
101
|
+
type ExampleGenContext = {
|
|
102
|
+
isRequestBody: boolean;
|
|
103
|
+
isResponse: boolean;
|
|
104
|
+
};
|
|
105
|
+
declare const defaultExampleContext: ExampleGenContext;
|
|
106
|
+
/**
|
|
107
|
+
* Generate example value from JSON-Schema / OpenAPI 3.2 Schema Object.
|
|
108
|
+
* Compliant with OAS3.2 schema 2025-11-23, browser-only.
|
|
109
|
+
* Handles boolean schemas (true / false), const, enum, composition keywords, type inference, formats.
|
|
110
|
+
* Respects minLength/maxLength, minItems/maxItems, minimum/maximum, multipleOf.
|
|
111
|
+
* Skips readOnly fields for request-body context; skips writeOnly fields for response context.
|
|
112
|
+
* Basic pattern regex-aware string example generation.
|
|
113
|
+
* @param schema raw schema value (may contain $ref)
|
|
114
|
+
* @param resolver reference resolver instance
|
|
115
|
+
* @param seen set for circular-reference detection
|
|
116
|
+
* @param depth current recursion depth
|
|
117
|
+
* @param ctx generation context for readOnly/writeOnly rules
|
|
118
|
+
* @returns example instance value, null for stop-circular, undefined for no-inference
|
|
119
|
+
*/
|
|
120
|
+
declare function example(schema: unknown, resolver: RefResolver, seen?: Set<unknown>, depth?: number, ctx?: ExampleGenContext): unknown;
|
|
121
|
+
|
|
122
|
+
type Pair = [string, string];
|
|
123
|
+
declare function parameter(parameter: {
|
|
124
|
+
name: string;
|
|
125
|
+
in: string;
|
|
126
|
+
value: unknown;
|
|
127
|
+
style?: string;
|
|
128
|
+
explode?: boolean;
|
|
129
|
+
allowReserved?: boolean;
|
|
130
|
+
}): Pair[];
|
|
131
|
+
declare function query(pairs: Pair[]): string;
|
|
132
|
+
declare function cookie(pairs: Pair[]): string;
|
|
133
|
+
declare function headerValue(value: string): string;
|
|
134
|
+
|
|
135
|
+
type GeneratorEmitter = (request: RequestIR) => string;
|
|
136
|
+
declare function createGenerator(language: string, client: string, emit: GeneratorEmitter): Generator;
|
|
137
|
+
|
|
138
|
+
declare function registerGenerator(generator: Generator): void;
|
|
139
|
+
declare function getGenerator(language: string, client: string): Generator | undefined;
|
|
140
|
+
declare function listGenerators(): Array<{
|
|
141
|
+
language: string;
|
|
142
|
+
client: string;
|
|
143
|
+
}>;
|
|
144
|
+
|
|
145
|
+
interface PluginApi {
|
|
146
|
+
register(generator: Generator): void;
|
|
147
|
+
}
|
|
148
|
+
declare function applyPlugin(plugin: Plugin, api: PluginApi): void;
|
|
149
|
+
|
|
150
|
+
interface CompiledRequest {
|
|
151
|
+
url: string;
|
|
152
|
+
headers: Array<[string, string]>;
|
|
153
|
+
body?: Body;
|
|
154
|
+
queryPairs: Array<[string, string]>;
|
|
155
|
+
cookiePairs: Array<[string, string]>;
|
|
156
|
+
}
|
|
157
|
+
declare function compile(request: RequestIR): CompiledRequest;
|
|
158
|
+
declare function form(value: unknown): string;
|
|
159
|
+
|
|
160
|
+
interface NormalizeOptions {
|
|
161
|
+
document: unknown;
|
|
162
|
+
path: string;
|
|
163
|
+
method: string;
|
|
164
|
+
serverUrl?: string;
|
|
165
|
+
securityValues?: Record<string, string>;
|
|
166
|
+
softRefMode?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface NormalizedParameter {
|
|
169
|
+
name: string;
|
|
170
|
+
in: string;
|
|
171
|
+
value: unknown;
|
|
172
|
+
style?: string;
|
|
173
|
+
explode?: boolean;
|
|
174
|
+
allowReserved?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface NormalizedSecurity {
|
|
177
|
+
name: string;
|
|
178
|
+
type: string;
|
|
179
|
+
scheme?: string;
|
|
180
|
+
in?: string;
|
|
181
|
+
paramName?: string;
|
|
182
|
+
value: string;
|
|
183
|
+
}
|
|
184
|
+
declare function normalize(options: NormalizeOptions): {
|
|
185
|
+
preWarnings: string[];
|
|
186
|
+
method: string;
|
|
187
|
+
baseUrl: string;
|
|
188
|
+
path: string;
|
|
189
|
+
parameters: NormalizedParameter[];
|
|
190
|
+
headers: NormalizedParameter[];
|
|
191
|
+
body: {
|
|
192
|
+
mediaType: string;
|
|
193
|
+
value: unknown;
|
|
194
|
+
encoding?: unknown;
|
|
195
|
+
} | undefined;
|
|
196
|
+
security: NormalizedSecurity[];
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Unified emitter registry.
|
|
201
|
+
*
|
|
202
|
+
* This module replaces the redundant src/generators/ directory.
|
|
203
|
+
* Each emitter exports an `emit` function; we wrap it with createGenerator
|
|
204
|
+
* and register all built-in generators here.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* All built-in generators, defined as [language, client, emitter] tuples.
|
|
209
|
+
* This is the single source of truth for built-in generator registration.
|
|
210
|
+
*/
|
|
211
|
+
declare const builtinGenerators: Generator[];
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @powerduck/openapi-codegen
|
|
215
|
+
*
|
|
216
|
+
* Generate runnable HTTP request examples from OpenAPI documents.
|
|
217
|
+
* Supports 21 languages and 41 language/client combinations.
|
|
218
|
+
*
|
|
219
|
+
* Browser-compatible, zero runtime dependencies.
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Register all built-in generators.
|
|
224
|
+
* Called automatically on first use, but can be called explicitly.
|
|
225
|
+
*/
|
|
226
|
+
declare function registerBuiltins(): void;
|
|
227
|
+
/**
|
|
228
|
+
* Register a custom generator.
|
|
229
|
+
*/
|
|
230
|
+
declare function register(generator: Generator): void;
|
|
231
|
+
/**
|
|
232
|
+
* Get a generator by language and client.
|
|
233
|
+
*/
|
|
234
|
+
declare function get(language: string, client: string): Generator | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* List all available generators.
|
|
237
|
+
*/
|
|
238
|
+
declare function list(): Array<{
|
|
239
|
+
language: string;
|
|
240
|
+
client: string;
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Apply a plugin that can register custom generators.
|
|
244
|
+
*/
|
|
245
|
+
declare function use(plugin: Plugin): void;
|
|
246
|
+
/**
|
|
247
|
+
* Generate an HTTP request example for an OpenAPI operation.
|
|
248
|
+
*
|
|
249
|
+
* @param options - Generation options
|
|
250
|
+
* @returns Generated source code as a string
|
|
251
|
+
* @throws Error when the path/method is not found, the generator is unknown,
|
|
252
|
+
* or the document is invalid.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import { generate } from "@powerduck/openapi-codegen";
|
|
257
|
+
*
|
|
258
|
+
* const code = generate({
|
|
259
|
+
* document: openApiDocument,
|
|
260
|
+
* path: "/users/{id}",
|
|
261
|
+
* method: "get",
|
|
262
|
+
* language: "javascript",
|
|
263
|
+
* client: "fetch",
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* console.log(code);
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function generate(options: GenerateOptions): string;
|
|
270
|
+
|
|
271
|
+
export { type Body, type CompiledRequest, type ExampleGenContext, type FileValue, type GenerateOptions, type GenerateResult, type Generator, type GeneratorEmitter, type Pair, type Parameter, type ParameterLocation, type Plugin, type PluginApi, RefResolver, type RequestIR, type Security, applyPlugin, builtinGenerators, compile, cookie, createGenerator, defaultExampleContext, example, form, generate, get, getGenerator, headerValue, list, listGenerators, normalize, parameter, query, register, registerBuiltins, registerGenerator, use };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for OpenAPI3.2 code-generation library
|
|
3
|
+
* Browser-compatible, compliant with OAS 3.2 specification
|
|
4
|
+
*/
|
|
5
|
+
type ParameterLocation = "path" | "query" | "querystring" | "header" | "cookie";
|
|
6
|
+
interface FileValue {
|
|
7
|
+
__file: true;
|
|
8
|
+
path?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
data?: string | ArrayBuffer | Uint8Array | Blob;
|
|
12
|
+
}
|
|
13
|
+
interface Parameter {
|
|
14
|
+
name: string;
|
|
15
|
+
in: ParameterLocation;
|
|
16
|
+
value: unknown;
|
|
17
|
+
style?: string;
|
|
18
|
+
explode?: boolean;
|
|
19
|
+
allowReserved?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface Body {
|
|
22
|
+
mediaType: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
encoding?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
interface Security {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
scheme?: string;
|
|
30
|
+
in?: string;
|
|
31
|
+
paramName?: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
interface RequestIR {
|
|
35
|
+
method: string;
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
path: string;
|
|
38
|
+
parameters: Parameter[];
|
|
39
|
+
headers: Parameter[];
|
|
40
|
+
body?: Body;
|
|
41
|
+
security: Security[];
|
|
42
|
+
}
|
|
43
|
+
interface GenerateResult {
|
|
44
|
+
code: string;
|
|
45
|
+
files?: Record<string, string>;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
interface Generator {
|
|
49
|
+
language: string;
|
|
50
|
+
client: string;
|
|
51
|
+
generate(request: RequestIR): string;
|
|
52
|
+
}
|
|
53
|
+
interface Plugin {
|
|
54
|
+
name: string;
|
|
55
|
+
register(api: {
|
|
56
|
+
register(generator: Generator): void;
|
|
57
|
+
}): void;
|
|
58
|
+
}
|
|
59
|
+
interface GenerateOptions {
|
|
60
|
+
language: string;
|
|
61
|
+
client: string;
|
|
62
|
+
request?: RequestIR;
|
|
63
|
+
document?: unknown;
|
|
64
|
+
path?: string;
|
|
65
|
+
method?: string;
|
|
66
|
+
serverUrl?: string;
|
|
67
|
+
securityValues?: Record<string, string>;
|
|
68
|
+
softRefMode?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* RefResolver for OpenAPI 3.2, browser-compatible, only supports in-document JSON-Pointer references starting with #/
|
|
73
|
+
* Compliant: https://spec.openapis.org/oas/3.2/schema/2025-11-23.html
|
|
74
|
+
*/
|
|
75
|
+
declare class RefResolver {
|
|
76
|
+
private readonly root;
|
|
77
|
+
private readonly cache;
|
|
78
|
+
private readonly stack;
|
|
79
|
+
/** When softMode=true: do NOT throw on broken/circular refs; return partial/original value instead */
|
|
80
|
+
softMode: boolean;
|
|
81
|
+
constructor(root: unknown, softMode?: boolean);
|
|
82
|
+
/**
|
|
83
|
+
* Dereference value, if it contains $ref, resolve it; otherwise return original value.
|
|
84
|
+
* Does NOT validate type of resolved result, only resolves pointer.
|
|
85
|
+
*/
|
|
86
|
+
deref<T = unknown>(value: T): T;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve JSON Pointer $ref starting with #/.
|
|
89
|
+
* Throws for external refs, circular refs, broken pointers unless softMode is enabled.
|
|
90
|
+
*/
|
|
91
|
+
resolveRef<T = unknown>(ref: string): T;
|
|
92
|
+
/** Clear internal cache, for reuse with different documents. */
|
|
93
|
+
clearCache(): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Context for example generation, controls readOnly/writeOnly filtering.
|
|
98
|
+
* - isRequestBody: true → skip readOnly properties
|
|
99
|
+
* - isResponse: true → skip writeOnly properties
|
|
100
|
+
*/
|
|
101
|
+
type ExampleGenContext = {
|
|
102
|
+
isRequestBody: boolean;
|
|
103
|
+
isResponse: boolean;
|
|
104
|
+
};
|
|
105
|
+
declare const defaultExampleContext: ExampleGenContext;
|
|
106
|
+
/**
|
|
107
|
+
* Generate example value from JSON-Schema / OpenAPI 3.2 Schema Object.
|
|
108
|
+
* Compliant with OAS3.2 schema 2025-11-23, browser-only.
|
|
109
|
+
* Handles boolean schemas (true / false), const, enum, composition keywords, type inference, formats.
|
|
110
|
+
* Respects minLength/maxLength, minItems/maxItems, minimum/maximum, multipleOf.
|
|
111
|
+
* Skips readOnly fields for request-body context; skips writeOnly fields for response context.
|
|
112
|
+
* Basic pattern regex-aware string example generation.
|
|
113
|
+
* @param schema raw schema value (may contain $ref)
|
|
114
|
+
* @param resolver reference resolver instance
|
|
115
|
+
* @param seen set for circular-reference detection
|
|
116
|
+
* @param depth current recursion depth
|
|
117
|
+
* @param ctx generation context for readOnly/writeOnly rules
|
|
118
|
+
* @returns example instance value, null for stop-circular, undefined for no-inference
|
|
119
|
+
*/
|
|
120
|
+
declare function example(schema: unknown, resolver: RefResolver, seen?: Set<unknown>, depth?: number, ctx?: ExampleGenContext): unknown;
|
|
121
|
+
|
|
122
|
+
type Pair = [string, string];
|
|
123
|
+
declare function parameter(parameter: {
|
|
124
|
+
name: string;
|
|
125
|
+
in: string;
|
|
126
|
+
value: unknown;
|
|
127
|
+
style?: string;
|
|
128
|
+
explode?: boolean;
|
|
129
|
+
allowReserved?: boolean;
|
|
130
|
+
}): Pair[];
|
|
131
|
+
declare function query(pairs: Pair[]): string;
|
|
132
|
+
declare function cookie(pairs: Pair[]): string;
|
|
133
|
+
declare function headerValue(value: string): string;
|
|
134
|
+
|
|
135
|
+
type GeneratorEmitter = (request: RequestIR) => string;
|
|
136
|
+
declare function createGenerator(language: string, client: string, emit: GeneratorEmitter): Generator;
|
|
137
|
+
|
|
138
|
+
declare function registerGenerator(generator: Generator): void;
|
|
139
|
+
declare function getGenerator(language: string, client: string): Generator | undefined;
|
|
140
|
+
declare function listGenerators(): Array<{
|
|
141
|
+
language: string;
|
|
142
|
+
client: string;
|
|
143
|
+
}>;
|
|
144
|
+
|
|
145
|
+
interface PluginApi {
|
|
146
|
+
register(generator: Generator): void;
|
|
147
|
+
}
|
|
148
|
+
declare function applyPlugin(plugin: Plugin, api: PluginApi): void;
|
|
149
|
+
|
|
150
|
+
interface CompiledRequest {
|
|
151
|
+
url: string;
|
|
152
|
+
headers: Array<[string, string]>;
|
|
153
|
+
body?: Body;
|
|
154
|
+
queryPairs: Array<[string, string]>;
|
|
155
|
+
cookiePairs: Array<[string, string]>;
|
|
156
|
+
}
|
|
157
|
+
declare function compile(request: RequestIR): CompiledRequest;
|
|
158
|
+
declare function form(value: unknown): string;
|
|
159
|
+
|
|
160
|
+
interface NormalizeOptions {
|
|
161
|
+
document: unknown;
|
|
162
|
+
path: string;
|
|
163
|
+
method: string;
|
|
164
|
+
serverUrl?: string;
|
|
165
|
+
securityValues?: Record<string, string>;
|
|
166
|
+
softRefMode?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface NormalizedParameter {
|
|
169
|
+
name: string;
|
|
170
|
+
in: string;
|
|
171
|
+
value: unknown;
|
|
172
|
+
style?: string;
|
|
173
|
+
explode?: boolean;
|
|
174
|
+
allowReserved?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface NormalizedSecurity {
|
|
177
|
+
name: string;
|
|
178
|
+
type: string;
|
|
179
|
+
scheme?: string;
|
|
180
|
+
in?: string;
|
|
181
|
+
paramName?: string;
|
|
182
|
+
value: string;
|
|
183
|
+
}
|
|
184
|
+
declare function normalize(options: NormalizeOptions): {
|
|
185
|
+
preWarnings: string[];
|
|
186
|
+
method: string;
|
|
187
|
+
baseUrl: string;
|
|
188
|
+
path: string;
|
|
189
|
+
parameters: NormalizedParameter[];
|
|
190
|
+
headers: NormalizedParameter[];
|
|
191
|
+
body: {
|
|
192
|
+
mediaType: string;
|
|
193
|
+
value: unknown;
|
|
194
|
+
encoding?: unknown;
|
|
195
|
+
} | undefined;
|
|
196
|
+
security: NormalizedSecurity[];
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Unified emitter registry.
|
|
201
|
+
*
|
|
202
|
+
* This module replaces the redundant src/generators/ directory.
|
|
203
|
+
* Each emitter exports an `emit` function; we wrap it with createGenerator
|
|
204
|
+
* and register all built-in generators here.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* All built-in generators, defined as [language, client, emitter] tuples.
|
|
209
|
+
* This is the single source of truth for built-in generator registration.
|
|
210
|
+
*/
|
|
211
|
+
declare const builtinGenerators: Generator[];
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @powerduck/openapi-codegen
|
|
215
|
+
*
|
|
216
|
+
* Generate runnable HTTP request examples from OpenAPI documents.
|
|
217
|
+
* Supports 21 languages and 41 language/client combinations.
|
|
218
|
+
*
|
|
219
|
+
* Browser-compatible, zero runtime dependencies.
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Register all built-in generators.
|
|
224
|
+
* Called automatically on first use, but can be called explicitly.
|
|
225
|
+
*/
|
|
226
|
+
declare function registerBuiltins(): void;
|
|
227
|
+
/**
|
|
228
|
+
* Register a custom generator.
|
|
229
|
+
*/
|
|
230
|
+
declare function register(generator: Generator): void;
|
|
231
|
+
/**
|
|
232
|
+
* Get a generator by language and client.
|
|
233
|
+
*/
|
|
234
|
+
declare function get(language: string, client: string): Generator | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* List all available generators.
|
|
237
|
+
*/
|
|
238
|
+
declare function list(): Array<{
|
|
239
|
+
language: string;
|
|
240
|
+
client: string;
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Apply a plugin that can register custom generators.
|
|
244
|
+
*/
|
|
245
|
+
declare function use(plugin: Plugin): void;
|
|
246
|
+
/**
|
|
247
|
+
* Generate an HTTP request example for an OpenAPI operation.
|
|
248
|
+
*
|
|
249
|
+
* @param options - Generation options
|
|
250
|
+
* @returns Generated source code as a string
|
|
251
|
+
* @throws Error when the path/method is not found, the generator is unknown,
|
|
252
|
+
* or the document is invalid.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import { generate } from "@powerduck/openapi-codegen";
|
|
257
|
+
*
|
|
258
|
+
* const code = generate({
|
|
259
|
+
* document: openApiDocument,
|
|
260
|
+
* path: "/users/{id}",
|
|
261
|
+
* method: "get",
|
|
262
|
+
* language: "javascript",
|
|
263
|
+
* client: "fetch",
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* console.log(code);
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function generate(options: GenerateOptions): string;
|
|
270
|
+
|
|
271
|
+
export { type Body, type CompiledRequest, type ExampleGenContext, type FileValue, type GenerateOptions, type GenerateResult, type Generator, type GeneratorEmitter, type Pair, type Parameter, type ParameterLocation, type Plugin, type PluginApi, RefResolver, type RequestIR, type Security, applyPlugin, builtinGenerators, compile, cookie, createGenerator, defaultExampleContext, example, form, generate, get, getGenerator, headerValue, list, listGenerators, normalize, parameter, query, register, registerBuiltins, registerGenerator, use };
|