@sdk-it/cli 0.18.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +494 -1
- package/dist/index.js.map +4 -4
- package/dist/lib/langs/typescript.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -26,6 +26,479 @@ async function loadLocal(location) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// packages/spec/dist/lib/loaders/postman/postman-converter.js
|
|
30
|
+
function descriptionToText(description) {
|
|
31
|
+
if (!description) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
if (typeof description === "string") {
|
|
35
|
+
return description;
|
|
36
|
+
}
|
|
37
|
+
if (description.content) {
|
|
38
|
+
return description.content;
|
|
39
|
+
}
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
function isFolder(item) {
|
|
43
|
+
return "item" in item;
|
|
44
|
+
}
|
|
45
|
+
function isRequest(item) {
|
|
46
|
+
return !!item.request;
|
|
47
|
+
}
|
|
48
|
+
function processItems(items, parentTags, globalTags, paths, securitySchemes) {
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
if (!isFolder(item) && !isRequest(item)) {
|
|
51
|
+
console.warn(
|
|
52
|
+
`Skipping item ${item.name} because it is not a folder or request`
|
|
53
|
+
);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (isFolder(item)) {
|
|
57
|
+
if (item.auth) {
|
|
58
|
+
processAuthScheme(item.auth, securitySchemes);
|
|
59
|
+
}
|
|
60
|
+
if (!globalTags.some((tag) => tag.name === item.name)) {
|
|
61
|
+
globalTags.push({
|
|
62
|
+
name: item.name,
|
|
63
|
+
description: descriptionToText(item.description)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const currentTags = [...parentTags, item.name];
|
|
67
|
+
processItems(item.item, currentTags, globalTags, paths, securitySchemes);
|
|
68
|
+
} else if (isRequest(item)) {
|
|
69
|
+
let operation;
|
|
70
|
+
if (typeof item.request === "string") {
|
|
71
|
+
const url = new URL(item.request);
|
|
72
|
+
operation = requestToOperation(
|
|
73
|
+
{
|
|
74
|
+
name: url.pathname,
|
|
75
|
+
response: [{ code: 200 }],
|
|
76
|
+
request: {
|
|
77
|
+
method: "get",
|
|
78
|
+
url: {
|
|
79
|
+
path: url.pathname.split("/").slice(1)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
securitySchemes
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
const auth = item.request.auth;
|
|
87
|
+
operation = requestToOperation(
|
|
88
|
+
{
|
|
89
|
+
name: item.name,
|
|
90
|
+
request: { ...item.request, auth },
|
|
91
|
+
response: item.response
|
|
92
|
+
},
|
|
93
|
+
securitySchemes
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
paths[operation.path] ??= {};
|
|
97
|
+
Object.assign(paths[operation.path], {
|
|
98
|
+
[operation.method]: {
|
|
99
|
+
tags: parentTags.length ? parentTags : void 0,
|
|
100
|
+
...operation.operation
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function coerceVariable(query) {
|
|
107
|
+
if (!query.key) {
|
|
108
|
+
throw new Error("Invalid query parameter format");
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
key: query.key,
|
|
112
|
+
description: descriptionToText(query.description)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function coerceQuery(query) {
|
|
116
|
+
if (!query.key) {
|
|
117
|
+
throw new Error("Invalid query parameter format");
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
key: query.key,
|
|
121
|
+
description: descriptionToText(query.description)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function coerceUrl(url) {
|
|
125
|
+
if (!url) {
|
|
126
|
+
throw new Error("Invalid URL format");
|
|
127
|
+
}
|
|
128
|
+
if (typeof url === "string") {
|
|
129
|
+
return {
|
|
130
|
+
path: url.split("/").slice(1),
|
|
131
|
+
query: [],
|
|
132
|
+
variable: []
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (typeof url.path === "string") {
|
|
136
|
+
return {
|
|
137
|
+
path: url.path.split("/").slice(1),
|
|
138
|
+
query: (url.query ?? []).map(coerceQuery),
|
|
139
|
+
variable: (url.variable ?? []).map(coerceVariable)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
path: (url.path ?? []).map((p) => {
|
|
144
|
+
if (typeof p === "string") {
|
|
145
|
+
return p;
|
|
146
|
+
}
|
|
147
|
+
throw new Error("Invalid URL path format");
|
|
148
|
+
}),
|
|
149
|
+
query: (url.query ?? []).map(coerceQuery),
|
|
150
|
+
variable: (url.variable ?? []).map(coerceVariable)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function coerceResponseHeader(header) {
|
|
154
|
+
if (!header) {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
if (typeof header === "string") {
|
|
158
|
+
throw new Error(`Invalid header format: ${header}`);
|
|
159
|
+
}
|
|
160
|
+
return header.map((h) => {
|
|
161
|
+
if (typeof h === "string") {
|
|
162
|
+
return {
|
|
163
|
+
key: h,
|
|
164
|
+
value: null
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return h;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function processAuthScheme(auth, securitySchemes) {
|
|
171
|
+
if (!auth || auth.type === "noauth")
|
|
172
|
+
return null;
|
|
173
|
+
const getAuthAttr = (key) => {
|
|
174
|
+
if (!auth || auth.type === "noauth")
|
|
175
|
+
return void 0;
|
|
176
|
+
const authType = auth[auth.type];
|
|
177
|
+
if (!authType)
|
|
178
|
+
return void 0;
|
|
179
|
+
const attr = authType.find((a) => a.key === key);
|
|
180
|
+
return attr ? String(attr.value) : void 0;
|
|
181
|
+
};
|
|
182
|
+
const schemeId = `${auth.type}Auth`;
|
|
183
|
+
switch (auth.type) {
|
|
184
|
+
case "apikey": {
|
|
185
|
+
const key = getAuthAttr("key") || "api_key";
|
|
186
|
+
const in_ = getAuthAttr("in") || "header";
|
|
187
|
+
securitySchemes[schemeId] = {
|
|
188
|
+
type: "apiKey",
|
|
189
|
+
name: key,
|
|
190
|
+
in: in_,
|
|
191
|
+
description: "API key authentication"
|
|
192
|
+
};
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case "basic":
|
|
196
|
+
securitySchemes[schemeId] = {
|
|
197
|
+
type: "http",
|
|
198
|
+
scheme: "basic",
|
|
199
|
+
description: "Basic HTTP authentication"
|
|
200
|
+
};
|
|
201
|
+
break;
|
|
202
|
+
case "bearer": {
|
|
203
|
+
const token = getAuthAttr("token");
|
|
204
|
+
securitySchemes[schemeId] = {
|
|
205
|
+
type: "http",
|
|
206
|
+
scheme: "bearer",
|
|
207
|
+
description: "Bearer token authentication",
|
|
208
|
+
...token ? { bearerFormat: "JWT" } : {}
|
|
209
|
+
};
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "oauth2": {
|
|
213
|
+
const flowType = getAuthAttr("grant_type") || "implicit";
|
|
214
|
+
securitySchemes[schemeId] = {
|
|
215
|
+
type: "oauth2",
|
|
216
|
+
description: "OAuth 2.0 authentication",
|
|
217
|
+
flows: {
|
|
218
|
+
[flowType === "authorization_code" ? "authorizationCode" : flowType]: {
|
|
219
|
+
authorizationUrl: getAuthAttr("authUrl") || "https://example.com/oauth/authorize",
|
|
220
|
+
tokenUrl: getAuthAttr("tokenUrl") || "https://example.com/oauth/token",
|
|
221
|
+
scopes: {}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "digest":
|
|
228
|
+
securitySchemes[schemeId] = {
|
|
229
|
+
type: "http",
|
|
230
|
+
scheme: "digest",
|
|
231
|
+
description: "Digest authentication"
|
|
232
|
+
};
|
|
233
|
+
break;
|
|
234
|
+
case "awsv4":
|
|
235
|
+
securitySchemes[schemeId] = {
|
|
236
|
+
type: "apiKey",
|
|
237
|
+
name: "Authorization",
|
|
238
|
+
in: "header",
|
|
239
|
+
description: "AWS Signature v4 authentication"
|
|
240
|
+
};
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
securitySchemes[schemeId] = {
|
|
244
|
+
type: "apiKey",
|
|
245
|
+
name: "Authorization",
|
|
246
|
+
in: "header",
|
|
247
|
+
description: `${auth.type} authentication`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return schemeId;
|
|
251
|
+
}
|
|
252
|
+
function generateSecurityRequirement(auth, securitySchemes) {
|
|
253
|
+
if (!auth || auth.type === "noauth")
|
|
254
|
+
return [];
|
|
255
|
+
const schemeId = `${auth.type}Auth`;
|
|
256
|
+
if (securitySchemes[schemeId]) {
|
|
257
|
+
return [{ [schemeId]: [] }];
|
|
258
|
+
}
|
|
259
|
+
return [];
|
|
260
|
+
}
|
|
261
|
+
function requestToOperation(item, securitySchemes) {
|
|
262
|
+
const url = coerceUrl(item.request.url);
|
|
263
|
+
const headers = Array.isArray(item.request.header) ? item.request.header : [];
|
|
264
|
+
const parameters = [
|
|
265
|
+
...url.query.filter((param) => !param.disabled).map((param) => {
|
|
266
|
+
return {
|
|
267
|
+
in: "query",
|
|
268
|
+
name: param.key,
|
|
269
|
+
required: false,
|
|
270
|
+
description: param.description,
|
|
271
|
+
schema: {
|
|
272
|
+
...param.value && !isNaN(Number(param.value)) ? { type: "number" } : param.value === "true" || param.value === "false" ? { type: "boolean" } : { type: "string" }
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}),
|
|
276
|
+
...url.variable.map((param) => {
|
|
277
|
+
return {
|
|
278
|
+
in: "path",
|
|
279
|
+
name: param.key,
|
|
280
|
+
required: true,
|
|
281
|
+
description: param.description,
|
|
282
|
+
schema: {
|
|
283
|
+
...param.value && !isNaN(Number(param.value)) ? { type: "number" } : param.value === "true" || param.value === "false" ? { type: "boolean" } : { type: "string" }
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}),
|
|
287
|
+
...headers.filter(
|
|
288
|
+
(h) => !h.disabled && h.key.toLowerCase() !== "accept" && h.key.toLowerCase() !== "content-type"
|
|
289
|
+
).map((header) => {
|
|
290
|
+
return {
|
|
291
|
+
in: "header",
|
|
292
|
+
name: header.key,
|
|
293
|
+
required: false,
|
|
294
|
+
description: descriptionToText(header.description),
|
|
295
|
+
schema: {
|
|
296
|
+
type: "string"
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
})
|
|
300
|
+
];
|
|
301
|
+
const acceptHeaderIdx = headers.findIndex(
|
|
302
|
+
(h) => h.key.toLowerCase() === "accept"
|
|
303
|
+
);
|
|
304
|
+
const contentTypeIdx = headers.findIndex(
|
|
305
|
+
(h) => h.key.toLowerCase() === "content-type"
|
|
306
|
+
);
|
|
307
|
+
const [acceptHeaderValue] = acceptHeaderIdx !== -1 ? headers.splice(acceptHeaderIdx, 1).map((h) => h.value) : [];
|
|
308
|
+
const [contentTypeValue] = contentTypeIdx !== -1 ? headers.splice(contentTypeIdx, 1).map((h) => h.value) : [];
|
|
309
|
+
let security;
|
|
310
|
+
if (item.request.auth) {
|
|
311
|
+
const schemeId = processAuthScheme(item.request.auth, securitySchemes);
|
|
312
|
+
if (schemeId) {
|
|
313
|
+
security = [{ [schemeId]: [] }];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
path: `/${url.path.join("/")}`.replace(/:([^/]+)/g, "{$1}"),
|
|
318
|
+
method: (item.request.method ?? "get").toLowerCase(),
|
|
319
|
+
operation: {
|
|
320
|
+
summary: item.name,
|
|
321
|
+
description: descriptionToText(item.request.description),
|
|
322
|
+
parameters,
|
|
323
|
+
security,
|
|
324
|
+
responses: !item.response || item.response.length === 0 ? {
|
|
325
|
+
200: {
|
|
326
|
+
description: "Successful response"
|
|
327
|
+
}
|
|
328
|
+
} : item.response.reduce((acc, response) => {
|
|
329
|
+
const headers2 = coerceResponseHeader(response.header);
|
|
330
|
+
const contentTypeIdx2 = headers2.findIndex(
|
|
331
|
+
(h) => h.key.toLowerCase() === "content-type"
|
|
332
|
+
);
|
|
333
|
+
const [contentTypeValue2] = contentTypeIdx2 !== -1 ? headers2.splice(contentTypeIdx2).map((h) => h.value) : [];
|
|
334
|
+
const contentType = response.body ? contentTypeValue2 || "application/json" : "application/octet-stream";
|
|
335
|
+
return {
|
|
336
|
+
...acc,
|
|
337
|
+
[response.code ?? 200]: {
|
|
338
|
+
description: response.name ? response.name : `Response for ${response.code}`,
|
|
339
|
+
content: {
|
|
340
|
+
[contentType]: {
|
|
341
|
+
schema: bodyToSchema(response.body)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}, {}),
|
|
347
|
+
requestBody: item.request.body ? requestBodyToOperationBody(
|
|
348
|
+
contentTypeValue || "application/json",
|
|
349
|
+
item.request.body
|
|
350
|
+
) : void 0
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function requestBodyToOperationBody(contentType, body) {
|
|
355
|
+
if (body.mode === "raw") {
|
|
356
|
+
return {
|
|
357
|
+
content: {
|
|
358
|
+
[contentType]: {
|
|
359
|
+
schema: bodyToSchema(body.raw)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
} else if (body.mode === "urlencoded") {
|
|
364
|
+
const properties = {};
|
|
365
|
+
(body.urlencoded || []).filter((param) => !param.disabled).forEach((param) => {
|
|
366
|
+
properties[param.key] = {
|
|
367
|
+
type: "string",
|
|
368
|
+
description: descriptionToText(param.description)
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
return {
|
|
372
|
+
content: {
|
|
373
|
+
"application/x-www-form-urlencoded": {
|
|
374
|
+
schema: {
|
|
375
|
+
type: "object",
|
|
376
|
+
properties
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
} else if (body.mode === "formdata") {
|
|
382
|
+
const properties = {};
|
|
383
|
+
(body.formdata || []).filter((param) => !param.disabled).forEach((param) => {
|
|
384
|
+
if (param.type === "text") {
|
|
385
|
+
properties[param.key] = {
|
|
386
|
+
type: "string",
|
|
387
|
+
description: descriptionToText(param.description)
|
|
388
|
+
};
|
|
389
|
+
} else if (param.type === "file") {
|
|
390
|
+
properties[param.key] = {
|
|
391
|
+
type: "string",
|
|
392
|
+
format: "binary",
|
|
393
|
+
description: descriptionToText(param.description)
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
return {
|
|
398
|
+
content: {
|
|
399
|
+
"multipart/form-data": {
|
|
400
|
+
schema: {
|
|
401
|
+
type: "object",
|
|
402
|
+
properties
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
throw new Error(
|
|
409
|
+
`Unsupported request body mode: ${body.mode}. Supported modes are: raw, urlencoded, formdata`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
function bodyToSchema(bodyString) {
|
|
413
|
+
if (!bodyString) {
|
|
414
|
+
return void 0;
|
|
415
|
+
}
|
|
416
|
+
let body;
|
|
417
|
+
try {
|
|
418
|
+
body = JSON.parse(bodyString);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.warn(
|
|
421
|
+
`Failed to parse JSON body: ${bodyString}. Treating as plain string.`,
|
|
422
|
+
error
|
|
423
|
+
);
|
|
424
|
+
return { type: "string", example: bodyString };
|
|
425
|
+
}
|
|
426
|
+
return toSchema(body);
|
|
427
|
+
}
|
|
428
|
+
function toSchema(body) {
|
|
429
|
+
const typeMap = {
|
|
430
|
+
"<number>": "number",
|
|
431
|
+
"<string>": "string",
|
|
432
|
+
"<boolean>": "boolean",
|
|
433
|
+
false: "boolean",
|
|
434
|
+
true: "boolean"
|
|
435
|
+
};
|
|
436
|
+
if (Array.isArray(body)) {
|
|
437
|
+
return {
|
|
438
|
+
type: "array",
|
|
439
|
+
items: toSchema(body[0])
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (typeof body === "object" && body !== null) {
|
|
443
|
+
const properties = {};
|
|
444
|
+
for (const [key, value] of Object.entries(body)) {
|
|
445
|
+
properties[key] = toSchema(value);
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
type: "object",
|
|
449
|
+
properties
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (typeof body === "string") {
|
|
453
|
+
return {
|
|
454
|
+
type: typeMap[body] ?? "string"
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
if (typeof body === "number") {
|
|
458
|
+
return {
|
|
459
|
+
type: "number"
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (typeof body === "boolean") {
|
|
463
|
+
return {
|
|
464
|
+
type: "boolean"
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (body === null) {
|
|
468
|
+
return {
|
|
469
|
+
type: "null"
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
console.warn(`Unknown type for body: ${body}. Defaulting to string.`, body);
|
|
473
|
+
return {
|
|
474
|
+
type: "string"
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function convertPostmanToOpenAPI(collection) {
|
|
478
|
+
const tags = [];
|
|
479
|
+
const paths = {};
|
|
480
|
+
const securitySchemes = {};
|
|
481
|
+
if (collection.auth) {
|
|
482
|
+
processAuthScheme(collection.auth, securitySchemes);
|
|
483
|
+
}
|
|
484
|
+
processItems(collection.item, [], tags, paths, securitySchemes);
|
|
485
|
+
return {
|
|
486
|
+
openapi: "3.1.0",
|
|
487
|
+
info: {
|
|
488
|
+
title: collection.info.name,
|
|
489
|
+
version: "1.0.0",
|
|
490
|
+
description: descriptionToText(collection.info.description)
|
|
491
|
+
},
|
|
492
|
+
tags,
|
|
493
|
+
paths,
|
|
494
|
+
// Only add security at top level if there's collection auth
|
|
495
|
+
security: collection.auth ? generateSecurityRequirement(collection.auth, securitySchemes) : void 0,
|
|
496
|
+
components: Object.keys(securitySchemes).length > 0 ? {
|
|
497
|
+
securitySchemes
|
|
498
|
+
} : void 0
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
29
502
|
// packages/spec/dist/lib/loaders/remote-loader.js
|
|
30
503
|
import { extname as extname2 } from "node:path";
|
|
31
504
|
import { parse as parse2 } from "yaml";
|
|
@@ -51,7 +524,17 @@ async function loadRemote(location) {
|
|
|
51
524
|
}
|
|
52
525
|
|
|
53
526
|
// packages/spec/dist/lib/loaders/load-spec.js
|
|
54
|
-
function
|
|
527
|
+
function isPostman(content) {
|
|
528
|
+
return typeof content === "object" && content !== null && "info" in content && typeof content.info === "object" && content.info !== null && "item" in content && Array.isArray(content.item) && "schema" in content.info && typeof content.info.schema === "string" && content.info.schema.includes("//schema.getpostman.com/");
|
|
529
|
+
}
|
|
530
|
+
async function loadSpec(location) {
|
|
531
|
+
const content = await loadFile(location);
|
|
532
|
+
if (isPostman(content)) {
|
|
533
|
+
return convertPostmanToOpenAPI(content);
|
|
534
|
+
}
|
|
535
|
+
return content;
|
|
536
|
+
}
|
|
537
|
+
function loadFile(location) {
|
|
55
538
|
const [protocol] = location.split(":");
|
|
56
539
|
if (protocol === "http" || protocol === "https") {
|
|
57
540
|
return loadRemote(location);
|
|
@@ -115,12 +598,22 @@ var typescript_default = new Command2("typescript").alias("ts").description("Gen
|
|
|
115
598
|
"--install",
|
|
116
599
|
"Install dependencies using npm (only in full mode)",
|
|
117
600
|
true
|
|
601
|
+
).option("--output-type <outputType>", "Endpoint output type", "default").option(
|
|
602
|
+
"--error-as-value <errorAsValue>",
|
|
603
|
+
"Treat errors as values instead of throwing them",
|
|
604
|
+
(value) => value === "false" ? false : true,
|
|
605
|
+
true
|
|
118
606
|
).option("--no-default-formatter", "Do not use the default formatter").option("--no-install", "Do not install dependencies").option("-v, --verbose", "Verbose output", false).action(async (options) => {
|
|
119
607
|
const spec = await loadSpec(options.spec);
|
|
120
608
|
await generate2(spec, {
|
|
121
609
|
output: options.output,
|
|
122
610
|
mode: options.mode || "minimal",
|
|
123
611
|
name: options.name,
|
|
612
|
+
style: {
|
|
613
|
+
name: "github",
|
|
614
|
+
outputType: options.outputType,
|
|
615
|
+
errorAsValue: options.errorAsValue
|
|
616
|
+
},
|
|
124
617
|
useTsExtension: options.useTsExtension,
|
|
125
618
|
formatCode: ({ env, output }) => {
|
|
126
619
|
if (options.formatter) {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/cli.ts", "../src/lib/langs/dart.ts", "../../spec/src/lib/loaders/local-loader.ts", "../../spec/src/lib/loaders/remote-loader.ts", "../../spec/src/lib/loaders/load-spec.ts", "../../spec/src/lib/operation.ts", "../src/lib/options.ts", "../src/lib/langs/typescript.ts"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\nimport { Command, program } from 'commander';\n\nimport dart from './langs/dart.ts';\nimport typescript from './langs/typescript.ts';\n\nconst generate = new Command('generate')\n .addCommand(typescript)\n .addCommand(dart);\nconst cli = program\n .description(`CLI tool to interact with SDK-IT.`)\n .addCommand(generate, { isDefault: true })\n .addCommand(\n new Command('_internal').action(() => {\n // do nothing\n }),\n { hidden: true },\n )\n .parse(process.argv);\n\nexport default cli;\n", "import { Command } from 'commander';\nimport { execFile, execSync } from 'node:child_process';\n\nimport { generate } from '@sdk-it/dart';\nimport { loadSpec } from '@sdk-it/spec';\n\nimport { outputOption, specOption } from '../options.ts';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n verbose: boolean;\n}\n\nexport default new Command('dart')\n .description('Generate Dart SDK')\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option('-l, --language <language>', 'Programming language for the SDK')\n // .option(\n // '-m, --mode <mode>',\n // 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n // )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option('-v, --verbose', 'Verbose output', false)\n // .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'full',\n name: options.name,\n formatCode: ({ output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, {\n env: { ...process.env, SDK_IT_OUTPUT: output },\n });\n } else {\n execSync('dart format $SDK_IT_OUTPUT ', {\n env: { ...process.env, SDK_IT_OUTPUT: output },\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n // execSync('dart fix --apply $SDK_IT_OUTPUT ', {\n // env: { ...process.env, SDK_IT_OUTPUT: output },\n // stdio: options.verbose ? 'inherit' : 'pipe',\n // });\n }\n },\n });\n });\n", "import { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { parse } from 'yaml';\n\nexport async function loadLocal(location: string) {\n const extName = extname(location);\n const text = await readFile(location, 'utf-8');\n switch (extName) {\n case '.json':\n return JSON.parse(text);\n case '.yaml':\n case '.yml':\n return parse(text);\n default:\n throw new Error(`Unsupported file extension: ${extName}`);\n }\n}\n", "import { extname } from 'node:path';\nimport type { OpenAPIObject } from 'openapi3-ts/oas31';\nimport { parse } from 'yaml';\n\nexport async function loadRemote(location: string): Promise<OpenAPIObject> {\n const extName = extname(location);\n const response = await fetch(location);\n switch (extName) {\n case '.json':\n return response.json() as Promise<OpenAPIObject>;\n case '.yaml':\n case '.yml': {\n const text = await response.text();\n return parse(text);\n }\n default:\n try {\n // try to parse it as json first\n return response.json() as Promise<OpenAPIObject>;\n } catch {\n // parse as yaml\n const text = await response.text();\n return parse(text) as Promise<OpenAPIObject>;\n }\n }\n}\n", "import type { OpenAPIObject } from 'openapi3-ts/oas31';\n\nimport { loadLocal } from './local-loader.js';\nimport { loadRemote } from './remote-loader.js';\n\nexport function loadSpec(location: string): Promise<OpenAPIObject> {\n const [protocol] = location.split(':');\n if (protocol === 'http' || protocol === 'https') {\n return loadRemote(location);\n }\n return loadLocal(location);\n}\n", "import type {\n OpenAPIObject,\n OperationObject,\n ParameterObject,\n ReferenceObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return camelcase(operation.operationId);\n }\n const metadata = operation['x-oaiMeta'];\n if (metadata && metadata.name) {\n return camelcase(metadata.name);\n }\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0] || determineGenericTag(path, operation);\n },\n};\n\nexport type TunedOperationObject = OperationObject & {\n operationId: string;\n parameters: (ParameterObject | ReferenceObject)[];\n};\n\nexport interface OperationEntry {\n name?: string;\n method: string;\n path: string;\n groupName: string;\n tag: string;\n}\nexport type Operation = {\n entry: OperationEntry;\n operation: TunedOperationObject;\n};\n\nexport function forEachOperation<T>(\n config: GenerateSdkConfig,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(config.spec.paths ?? {})) {\n const { parameters = [], ...methods } = pathItem;\n\n // Convert Express-style routes (:param) to OpenAPI-style routes ({param})\n const fixedPath = path.replace(/:([^/]+)/g, '{$1}');\n\n for (const [method, operation] of Object.entries(methods) as [\n string,\n OperationObject,\n ][]) {\n const formatOperationId = config.operationId ?? defaults.operationId;\n const formatTag = config.tag ?? defaults.tag;\n const operationName = formatOperationId(operation, fixedPath, method);\n const operationTag = formatTag(operation, fixedPath);\n const metadata = operation['x-oaiMeta'] ?? {};\n result.push(\n callback(\n {\n name: metadata.name,\n method,\n path: fixedPath,\n groupName: operationTag,\n tag: operationTag,\n },\n {\n ...operation,\n parameters: [...parameters, ...(operation.parameters ?? [])],\n operationId: operationName,\n },\n ),\n );\n }\n }\n return result;\n}\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\n\n// --- Function Definition (determineGenericTag, sanitizeTag, reservedKeywords, commonVerbs) ---\n/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\nconst reservedKeywords = new Set([\n 'abstract',\n 'arguments',\n 'await',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n // Potentially problematic identifiers / Common Verbs used as tags\n 'object',\n 'string',\n 'number',\n 'any',\n 'unknown',\n 'never',\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make, check\n]);\n\n/**\n * Sanitizes a potential tag name (assumed to be already camelCased)\n * to avoid conflicts with reserved keywords or invalid starting characters (numbers).\n * Appends an underscore if the tag matches a reserved keyword.\n * Prepends an underscore if the tag starts with a number.\n * @param camelCasedTag The potential tag name, already camelCased.\n * @returns The sanitized tag name.\n */\nfunction sanitizeTag(camelCasedTag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(camelCasedTag)) {\n return `_${camelCasedTag}`;\n }\n // Append underscore if it's a reserved keyword\n return reservedKeywords.has(camelCasedTag)\n ? `${camelCasedTag}_`\n : camelCasedTag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n\nexport function parseJsonContentType(contentType: string | null | undefined) {\n if (!contentType) {\n return null;\n }\n\n // 1. Trim whitespace\n let mainType = contentType.trim();\n\n // 2. Remove parameters (anything after the first ';')\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n mainType = mainType.substring(0, semicolonIndex).trim(); // Trim potential space before ';'\n }\n\n // 3. Convert to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n if (mainType.endsWith('/json')) {\n return mainType.split('/')[1];\n } else if (mainType.endsWith('+json')) {\n return mainType.split('+')[1];\n }\n return null;\n}\n\n/**\n * Checks if a given content type string represents Server-Sent Events (SSE).\n * Handles case-insensitivity, parameters (like charset), and leading/trailing whitespace.\n *\n * @param contentType The content type string to check (e.g., from a Content-Type header).\n * @returns True if the content type is 'text/event-stream', false otherwise.\n */\nexport function isSseContentType(\n contentType: string | null | undefined,\n): boolean {\n if (!contentType) {\n return false; // Handle null, undefined, or empty string\n }\n\n // 1. Trim whitespace from the input string\n let mainType = contentType.trim();\n\n // 2. Find the position of the first semicolon (if any) to remove parameters\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n // Extract the part before the semicolon and trim potential space\n mainType = mainType.substring(0, semicolonIndex).trim();\n }\n\n // 3. Convert the main type part to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n // 4. Compare against the standard SSE MIME type\n return mainType === 'text/event-stream';\n}\n\nexport function isStreamingContentType(\n contentType: string | null | undefined,\n): boolean {\n return contentType === 'application/octet-stream';\n}\n\nexport function isSuccessStatusCode(statusCode: number | string): boolean {\n statusCode = Number(statusCode);\n return statusCode >= 200 && statusCode < 300;\n}\n", "import { Option } from 'commander';\n\nexport const specOption = new Option(\n '-s, --spec <spec>',\n 'Path to OpenAPI specification file',\n);\n\nexport const outputOption = new Option(\n '-o, --output <output>',\n 'Output directory for the generated SDK',\n);\n", "import { Command } from 'commander';\nimport { execFile, execSync } from 'node:child_process';\n\nimport { loadSpec } from '@sdk-it/spec';\nimport { generate } from '@sdk-it/typescript';\n\nimport { outputOption, specOption } from '../options.ts';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n framework?: string;\n install: boolean;\n verbose: boolean;\n defaultFormatter: boolean;\n}\n\nexport default new Command('typescript')\n .alias('ts')\n .description('Generate TypeScript SDK')\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option(\n '--useTsExtension [value]',\n 'Use .ts extension for generated files',\n (value) => (value === 'false' ? false : true),\n true,\n )\n .option('-l, --language <language>', 'Programming language for the SDK')\n .option(\n '-m, --mode <mode>',\n 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option(\n '-f, --framework <framework>',\n 'Framework that is integrating with the SDK',\n )\n .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .option(\n '--install',\n 'Install dependencies using npm (only in full mode)',\n true,\n )\n .option('--no-default-formatter', 'Do not use the default formatter')\n .option('--no-install', 'Do not install dependencies')\n .option('-v, --verbose', 'Verbose output', false)\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'minimal',\n name: options.name,\n useTsExtension: options.useTsExtension,\n formatCode: ({ env, output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, {\n env: { ...env, SDK_IT_OUTPUT: output },\n });\n } else if (options.defaultFormatter) {\n execSync('npx -y prettier $SDK_IT_OUTPUT --write', {\n env: {\n ...env,\n SDK_IT_OUTPUT: output,\n NODE_OPTIONS: '--experimental-strip-types',\n },\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n }\n },\n });\n\n // Install dependencies if in full mode and install option is enabled\n\n if (options.install && options.mode === 'full') {\n console.log('Installing dependencies...');\n execSync('npm install', {\n cwd: options.output,\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n }\n });\n"],
|
|
5
|
-
"mappings": ";;;AACA,SAAS,WAAAA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KAAK,CAAC,EACxC;AAAA,EACC,IAAIC,SAAQ,WAAW,EAAE,OAAO,MAAM;AAAA,EAEtC,CAAC;AAAA,EACD,EAAE,QAAQ,KAAK;AACjB,EACC,MAAM,QAAQ,IAAI;",
|
|
6
|
-
"names": ["Command", "extname", "parse", "Command", "execFile", "execSync", "generate", "Command", "generate", "execFile", "execSync", "generate", "Command"]
|
|
3
|
+
"sources": ["../src/lib/cli.ts", "../src/lib/langs/dart.ts", "../../spec/src/lib/loaders/local-loader.ts", "../../spec/src/lib/loaders/postman/postman-converter.ts", "../../spec/src/lib/loaders/remote-loader.ts", "../../spec/src/lib/loaders/load-spec.ts", "../../spec/src/lib/operation.ts", "../src/lib/options.ts", "../src/lib/langs/typescript.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\nimport { Command, program } from 'commander';\n\nimport dart from './langs/dart.ts';\nimport typescript from './langs/typescript.ts';\n\nconst generate = new Command('generate')\n .addCommand(typescript)\n .addCommand(dart);\nconst cli = program\n .description(`CLI tool to interact with SDK-IT.`)\n .addCommand(generate, { isDefault: true })\n .addCommand(\n new Command('_internal').action(() => {\n // do nothing\n }),\n { hidden: true },\n )\n .parse(process.argv);\n\nexport default cli;\n", "import { Command } from 'commander';\nimport { execFile, execSync } from 'node:child_process';\n\nimport { generate } from '@sdk-it/dart';\nimport { loadSpec } from '@sdk-it/spec';\n\nimport { outputOption, specOption } from '../options.ts';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n verbose: boolean;\n}\n\nexport default new Command('dart')\n .description('Generate Dart SDK')\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option('-l, --language <language>', 'Programming language for the SDK')\n // .option(\n // '-m, --mode <mode>',\n // 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n // )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option('-v, --verbose', 'Verbose output', false)\n // .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'full',\n name: options.name,\n formatCode: ({ output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, {\n env: { ...process.env, SDK_IT_OUTPUT: output },\n });\n } else {\n execSync('dart format $SDK_IT_OUTPUT ', {\n env: { ...process.env, SDK_IT_OUTPUT: output },\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n // execSync('dart fix --apply $SDK_IT_OUTPUT ', {\n // env: { ...process.env, SDK_IT_OUTPUT: output },\n // stdio: options.verbose ? 'inherit' : 'pipe',\n // });\n }\n },\n });\n });\n", "import { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { parse } from 'yaml';\n\nexport async function loadLocal(location: string) {\n const extName = extname(location);\n const text = await readFile(location, 'utf-8');\n switch (extName) {\n case '.json':\n return JSON.parse(text);\n case '.yaml':\n case '.yml':\n return parse(text);\n default:\n throw new Error(`Unsupported file extension: ${extName}`);\n }\n}\n", "import type {\n ContentObject,\n OpenAPIObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n RequestBodyObject,\n ResponseObject,\n SchemaObject,\n SecuritySchemeObject,\n TagObject,\n} from 'openapi3-ts/oas31';\n\nimport type {\n Auth,\n Description,\n Folder,\n Header,\n Headers,\n Item,\n Items,\n PostmanCollection,\n PostmanRequest,\n QueryParam,\n Request,\n RequestBody,\n Url,\n Variable,\n} from './spec-types';\n\nfunction descriptionToText(description?: Description) {\n if (!description) {\n return undefined;\n }\n if (typeof description === 'string') {\n return description;\n }\n if (description.content) {\n return description.content;\n }\n return undefined;\n}\n\ntype OurQueryParam = Omit<QueryParam, 'key'> & {\n key: string;\n description?: string;\n};\ntype OurVariable = Omit<QueryParam, 'key'> & {\n key: string;\n description?: string;\n};\ntype OurUrl = {\n path: string[];\n query: OurQueryParam[];\n variable: OurVariable[];\n};\n\nfunction isFolder(item: Items): item is Folder & { name: string } {\n return 'item' in item;\n}\n\nfunction isRequest(\n item: Items,\n): item is Item & { name: string; request: Request } {\n return !!item.request;\n}\n\n/**\n * Recursively processes items and folders in a Postman collection\n * @param items Array of Postman items (requests or folders)\n * @param parentTags Array of parent folder tags for proper nesting\n */\nfunction processItems(\n items: Items[],\n parentTags: string[],\n globalTags: TagObject[],\n paths: PathsObject,\n securitySchemes: Record<string, SecuritySchemeObject>,\n) {\n for (const item of items) {\n if (!isFolder(item) && !isRequest(item)) {\n console.warn(\n `Skipping item ${item.name} because it is not a folder or request`,\n );\n continue;\n }\n\n if (isFolder(item)) {\n // Process folder-level auth if it exists\n if (item.auth) {\n processAuthScheme(item.auth, securitySchemes);\n }\n\n // Add this folder as a tag if not already added\n if (!globalTags.some((tag) => tag.name === item.name)) {\n globalTags.push({\n name: item.name,\n description: descriptionToText(item.description),\n });\n }\n\n const currentTags = [...parentTags, item.name];\n processItems(item.item, currentTags, globalTags, paths, securitySchemes);\n } else if (isRequest(item)) {\n // Process this request\n let operation: ReturnType<typeof requestToOperation>;\n if (typeof item.request === 'string') {\n const url = new URL(item.request);\n operation = requestToOperation(\n {\n name: url.pathname,\n response: [{ code: 200 }],\n request: {\n method: 'get',\n url: {\n path: url.pathname.split('/').slice(1),\n },\n },\n },\n securitySchemes,\n );\n } else {\n const auth = item.request.auth;\n operation = requestToOperation(\n {\n name: item.name,\n request: { ...item.request, auth },\n response: item.response,\n },\n securitySchemes,\n );\n }\n\n paths[operation.path] ??= {};\n Object.assign(paths[operation.path], {\n [operation.method]: {\n tags: parentTags.length ? parentTags : undefined,\n ...operation.operation,\n },\n });\n }\n }\n}\n\nfunction coerceVariable(query: Variable): OurVariable {\n if (!query.key) {\n throw new Error('Invalid query parameter format');\n }\n return {\n key: query.key,\n description: descriptionToText(query.description),\n };\n}\nfunction coerceQuery(query: QueryParam): OurQueryParam {\n if (!query.key) {\n throw new Error('Invalid query parameter format');\n }\n return {\n key: query.key,\n description: descriptionToText(query.description),\n };\n}\nfunction coerceUrl(url?: Url): OurUrl {\n if (!url) {\n throw new Error('Invalid URL format');\n }\n if (typeof url === 'string') {\n return {\n path: url.split('/').slice(1),\n query: [],\n variable: [],\n };\n }\n if (typeof url.path === 'string') {\n return {\n path: url.path.split('/').slice(1),\n query: (url.query ?? []).map(coerceQuery),\n variable: (url.variable ?? []).map(coerceVariable),\n };\n }\n return {\n path: (url.path ?? []).map((p) => {\n if (typeof p === 'string') {\n return p;\n }\n throw new Error('Invalid URL path format');\n }),\n query: (url.query ?? []).map(coerceQuery),\n variable: (url.variable ?? []).map(coerceVariable),\n };\n}\n\nfunction coerceResponseHeader(header?: Headers) {\n if (!header) {\n return [];\n }\n if (typeof header === 'string') {\n throw new Error(`Invalid header format: ${header}`);\n }\n return header.map((h) => {\n if (typeof h === 'string') {\n return {\n key: h,\n value: null,\n };\n }\n return h;\n });\n}\n\n/**\n * Process an auth scheme and add it to securitySchemes\n */\nfunction processAuthScheme(\n auth: Auth,\n securitySchemes: Record<string, SecuritySchemeObject>,\n): string | null {\n if (!auth || auth.type === 'noauth') return null;\n\n const getAuthAttr = (key: string): string | undefined => {\n if (!auth || auth.type === 'noauth') return undefined;\n const authType = auth[auth.type];\n if (!authType) return undefined;\n const attr = authType.find((a) => a.key === key);\n return attr ? String(attr.value) : undefined;\n };\n\n const schemeId = `${auth.type}Auth`;\n\n switch (auth.type) {\n case 'apikey': {\n const key = getAuthAttr('key') || 'api_key';\n const in_ = getAuthAttr('in') || 'header';\n securitySchemes[schemeId] = {\n type: 'apiKey',\n name: key,\n in: in_ as 'header' | 'query' | 'cookie',\n description: 'API key authentication',\n };\n break;\n }\n case 'basic':\n securitySchemes[schemeId] = {\n type: 'http',\n scheme: 'basic',\n description: 'Basic HTTP authentication',\n };\n break;\n case 'bearer': {\n const token = getAuthAttr('token');\n securitySchemes[schemeId] = {\n type: 'http',\n scheme: 'bearer',\n description: 'Bearer token authentication',\n ...(token ? { bearerFormat: 'JWT' } : {}),\n };\n break;\n }\n case 'oauth2': {\n const flowType = getAuthAttr('grant_type') || 'implicit';\n securitySchemes[schemeId] = {\n type: 'oauth2',\n description: 'OAuth 2.0 authentication',\n flows: {\n [flowType === 'authorization_code' ? 'authorizationCode' : flowType]:\n {\n authorizationUrl:\n getAuthAttr('authUrl') || 'https://example.com/oauth/authorize',\n tokenUrl:\n getAuthAttr('tokenUrl') || 'https://example.com/oauth/token',\n scopes: {},\n },\n },\n };\n break;\n }\n case 'digest':\n securitySchemes[schemeId] = {\n type: 'http',\n scheme: 'digest',\n description: 'Digest authentication',\n };\n break;\n case 'awsv4':\n securitySchemes[schemeId] = {\n type: 'apiKey',\n name: 'Authorization',\n in: 'header',\n description: 'AWS Signature v4 authentication',\n };\n break;\n default:\n securitySchemes[schemeId] = {\n type: 'apiKey',\n name: 'Authorization',\n in: 'header',\n description: `${auth.type} authentication`,\n };\n }\n\n return schemeId;\n}\n\nfunction generateSecurityRequirement(\n auth: Auth,\n securitySchemes: Record<string, SecuritySchemeObject>,\n) {\n if (!auth || auth.type === 'noauth') return [];\n\n const schemeId = `${auth.type}Auth`;\n\n // Only include if the scheme was successfully processed\n if (securitySchemes[schemeId]) {\n return [{ [schemeId]: [] }];\n }\n\n return [];\n}\n\nfunction requestToOperation(\n item: Exclude<Item, 'name' | 'request'> & {\n name: string;\n request: PostmanRequest;\n },\n securitySchemes: Record<string, SecuritySchemeObject>,\n) {\n const url = coerceUrl(item.request.url);\n const headers = Array.isArray(item.request.header)\n ? item.request.header\n : ([] as Header[]);\n\n const parameters: ParameterObject[] = [\n ...url.query\n .filter((param) => !param.disabled)\n .map((param) => {\n return {\n in: 'query',\n name: param.key,\n required: false,\n description: param.description,\n schema: {\n ...(param.value && !isNaN(Number(param.value))\n ? { type: 'number' }\n : param.value === 'true' || param.value === 'false'\n ? { type: 'boolean' }\n : { type: 'string' }),\n },\n } satisfies ParameterObject;\n }),\n\n ...url.variable.map((param) => {\n return {\n in: 'path',\n name: param.key,\n required: true,\n description: param.description,\n schema: {\n ...(param.value && !isNaN(Number(param.value))\n ? { type: 'number' }\n : param.value === 'true' || param.value === 'false'\n ? { type: 'boolean' }\n : { type: 'string' }),\n },\n } satisfies ParameterObject;\n }),\n\n ...headers\n .filter(\n (h) =>\n !h.disabled &&\n h.key.toLowerCase() !== 'accept' &&\n h.key.toLowerCase() !== 'content-type',\n )\n .map((header) => {\n return {\n in: 'header',\n name: header.key,\n required: false,\n description: descriptionToText(header.description),\n schema: {\n type: 'string',\n },\n } satisfies ParameterObject;\n }),\n ];\n\n // Extract Accept and Content-Type headers\n const acceptHeaderIdx = headers.findIndex(\n (h) => h.key.toLowerCase() === 'accept',\n );\n const contentTypeIdx = headers.findIndex(\n (h) => h.key.toLowerCase() === 'content-type',\n );\n const [acceptHeaderValue] =\n acceptHeaderIdx !== -1\n ? headers.splice(acceptHeaderIdx, 1).map((h) => h.value)\n : [];\n const [contentTypeValue] =\n contentTypeIdx !== -1\n ? headers.splice(contentTypeIdx, 1).map((h) => h.value)\n : [];\n\n let security;\n if (item.request.auth) {\n const schemeId = processAuthScheme(item.request.auth, securitySchemes);\n if (schemeId) {\n security = [{ [schemeId]: [] }];\n }\n }\n\n return {\n path: `/${url.path.join('/')}`.replace(/:([^/]+)/g, '{$1}'),\n method: (item.request.method ?? 'get').toLowerCase(),\n operation: {\n summary: item.name,\n description: descriptionToText(item.request.description),\n parameters,\n security,\n responses:\n !item.response || item.response.length === 0\n ? {\n 200: {\n description: 'Successful response',\n },\n }\n : item.response.reduce((acc, response) => {\n const headers = coerceResponseHeader(response.header);\n const contentTypeIdx = headers.findIndex(\n (h) => h.key.toLowerCase() === 'content-type',\n );\n const [contentTypeValue] =\n contentTypeIdx !== -1\n ? headers.splice(contentTypeIdx).map((h) => h.value)\n : [];\n const contentType = response.body\n ? contentTypeValue || 'application/json'\n : 'application/octet-stream';\n\n return {\n ...acc,\n [response.code ?? 200]: {\n description: response.name\n ? response.name\n : `Response for ${response.code}`,\n content: {\n [contentType]: {\n schema: bodyToSchema(response.body),\n },\n },\n } satisfies ResponseObject,\n };\n }, {}),\n requestBody: item.request.body\n ? requestBodyToOperationBody(\n contentTypeValue || 'application/json',\n item.request.body,\n )\n : undefined,\n } satisfies OperationObject,\n };\n}\n\n/**\n * Helper function to determine the likely type of a value\n */\nfunction inferSchemaType(value: string | null): { type: string } {\n if (!value) return { type: 'string' };\n\n // Check if value is a number\n if (!isNaN(Number(value))) {\n return { type: 'number' };\n }\n\n // Check if value is a boolean\n if (value === 'true' || value === 'false') {\n return { type: 'boolean' };\n }\n\n // Default to string\n return { type: 'string' };\n}\n\nfunction requestBodyToOperationBody(\n contentType: string,\n body: RequestBody,\n): RequestBodyObject {\n if (body.mode === 'raw') {\n return {\n content: {\n [contentType]: {\n schema: bodyToSchema(body.raw),\n },\n },\n };\n } else if (body.mode === 'urlencoded') {\n const properties: Record<string, any> = {};\n (body.urlencoded || [])\n .filter((param) => !param.disabled)\n .forEach((param) => {\n properties[param.key] = {\n type: 'string',\n description: descriptionToText(param.description),\n };\n });\n\n return {\n content: {\n 'application/x-www-form-urlencoded': {\n schema: {\n type: 'object',\n properties,\n },\n },\n } satisfies ContentObject,\n };\n } else if (body.mode === 'formdata') {\n const properties: SchemaObject['properties'] = {};\n (body.formdata || [])\n .filter((param) => !param.disabled)\n .forEach((param) => {\n if (param.type === 'text') {\n properties[param.key] = {\n type: 'string',\n description: descriptionToText(param.description),\n };\n } else if (param.type === 'file') {\n properties[param.key] = {\n type: 'string',\n format: 'binary',\n description: descriptionToText(param.description),\n };\n }\n });\n\n return {\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n properties,\n },\n },\n } satisfies ContentObject,\n };\n }\n\n throw new Error(\n `Unsupported request body mode: ${body.mode}. Supported modes are: raw, urlencoded, formdata`,\n );\n}\n\nfunction bodyToSchema(bodyString?: string | null): SchemaObject | undefined {\n if (!bodyString) {\n return undefined;\n }\n\n let body: unknown;\n try {\n body = JSON.parse(bodyString);\n } catch (error) {\n console.warn(\n `Failed to parse JSON body: ${bodyString}. Treating as plain string.`,\n error,\n );\n return { type: 'string', example: bodyString };\n }\n\n return toSchema(body);\n}\n\nfunction toSchema(body: unknown | unknown[]): any {\n const typeMap: Record<string, string> = {\n '<number>': 'number',\n '<string>': 'string',\n '<boolean>': 'boolean',\n false: 'boolean',\n true: 'boolean',\n };\n if (Array.isArray(body)) {\n return {\n type: 'array',\n items: toSchema(body[0]),\n };\n }\n if (typeof body === 'object' && body !== null) {\n const properties: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(body)) {\n properties[key] = toSchema(value);\n }\n return {\n type: 'object',\n properties,\n };\n }\n if (typeof body === 'string') {\n return {\n type: typeMap[body] ?? 'string',\n };\n }\n if (typeof body === 'number') {\n return {\n type: 'number',\n };\n }\n if (typeof body === 'boolean') {\n return {\n type: 'boolean',\n };\n }\n if (body === null) {\n return {\n type: 'null',\n };\n }\n console.warn(`Unknown type for body: ${body}. Defaulting to string.`, body);\n return {\n type: 'string',\n };\n}\n\nexport function convertPostmanToOpenAPI(\n collection: PostmanCollection,\n): OpenAPIObject {\n const tags: TagObject[] = [];\n const paths: PathsObject = {};\n const securitySchemes: Record<string, SecuritySchemeObject> = {};\n\n if (collection.auth) {\n processAuthScheme(collection.auth, securitySchemes);\n }\n processItems(collection.item, [], tags, paths, securitySchemes);\n return {\n openapi: '3.1.0',\n info: {\n title: collection.info.name,\n version: '1.0.0',\n description: descriptionToText(collection.info.description),\n },\n tags,\n paths,\n // Only add security at top level if there's collection auth\n security: collection.auth\n ? generateSecurityRequirement(collection.auth, securitySchemes)\n : undefined,\n components:\n Object.keys(securitySchemes).length > 0\n ? {\n securitySchemes,\n }\n : undefined,\n };\n}\n", "import { extname } from 'node:path';\nimport { parse } from 'yaml';\n\nexport async function loadRemote<T>(location: string): Promise<T> {\n const extName = extname(location);\n const response = await fetch(location);\n switch (extName) {\n case '.json':\n return response.json() as Promise<T>;\n case '.yaml':\n case '.yml': {\n const text = await response.text();\n return parse(text);\n }\n default:\n try {\n // try to parse it as json first\n return response.json() as Promise<T>;\n } catch {\n // parse as yaml\n const text = await response.text();\n return parse(text) as Promise<T>;\n }\n }\n}\n", "import type { OpenAPIObject } from 'openapi3-ts/oas31';\n\nimport { loadLocal } from './local-loader.js';\nimport { convertPostmanToOpenAPI } from './postman/postman-converter.js';\nimport type { PostmanCollection } from './postman/spec-types.js';\nimport { loadRemote } from './remote-loader.js';\n\nfunction isPostman(content: unknown): content is PostmanCollection {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'info' in content &&\n typeof content.info === 'object' &&\n content.info !== null &&\n 'item' in content &&\n Array.isArray(content.item) &&\n 'schema' in content.info &&\n typeof content.info.schema === 'string' &&\n content.info.schema.includes('//schema.getpostman.com/')\n );\n}\nexport async function loadSpec(location: string): Promise<OpenAPIObject> {\n const content = await loadFile(location);\n if (isPostman(content)) {\n return convertPostmanToOpenAPI(content);\n }\n return content as OpenAPIObject;\n}\n\nexport function loadFile<T>(location: string): Promise<T> {\n const [protocol] = location.split(':');\n if (protocol === 'http' || protocol === 'https') {\n return loadRemote(location);\n }\n return loadLocal(location);\n}\n", "import type {\n OpenAPIObject,\n OperationObject,\n ParameterObject,\n ReferenceObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return camelcase(operation.operationId);\n }\n const metadata = operation['x-oaiMeta'];\n if (metadata && metadata.name) {\n return camelcase(metadata.name);\n }\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0] || determineGenericTag(path, operation);\n },\n};\n\nexport type TunedOperationObject = OperationObject & {\n operationId: string;\n parameters: (ParameterObject | ReferenceObject)[];\n};\n\nexport interface OperationEntry {\n name?: string;\n method: string;\n path: string;\n groupName: string;\n tag: string;\n}\nexport type Operation = {\n entry: OperationEntry;\n operation: TunedOperationObject;\n};\n\nexport function forEachOperation<T>(\n config: GenerateSdkConfig,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(config.spec.paths ?? {})) {\n const { parameters = [], ...methods } = pathItem;\n\n // Convert Express-style routes (:param) to OpenAPI-style routes ({param})\n const fixedPath = path.replace(/:([^/]+)/g, '{$1}');\n\n for (const [method, operation] of Object.entries(methods) as [\n string,\n OperationObject,\n ][]) {\n const formatOperationId = config.operationId ?? defaults.operationId;\n const formatTag = config.tag ?? defaults.tag;\n const operationName = formatOperationId(operation, fixedPath, method);\n const operationTag = formatTag(operation, fixedPath);\n const metadata = operation['x-oaiMeta'] ?? {};\n result.push(\n callback(\n {\n name: metadata.name,\n method,\n path: fixedPath,\n groupName: operationTag,\n tag: operationTag,\n },\n {\n ...operation,\n parameters: [...parameters, ...(operation.parameters ?? [])],\n operationId: operationName,\n },\n ),\n );\n }\n }\n return result;\n}\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\n\n// --- Function Definition (determineGenericTag, sanitizeTag, reservedKeywords, commonVerbs) ---\n/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\nconst reservedKeywords = new Set([\n 'abstract',\n 'arguments',\n 'await',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n // Potentially problematic identifiers / Common Verbs used as tags\n 'object',\n 'string',\n 'number',\n 'any',\n 'unknown',\n 'never',\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make, check\n]);\n\n/**\n * Sanitizes a potential tag name (assumed to be already camelCased)\n * to avoid conflicts with reserved keywords or invalid starting characters (numbers).\n * Appends an underscore if the tag matches a reserved keyword.\n * Prepends an underscore if the tag starts with a number.\n * @param camelCasedTag The potential tag name, already camelCased.\n * @returns The sanitized tag name.\n */\nfunction sanitizeTag(camelCasedTag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(camelCasedTag)) {\n return `_${camelCasedTag}`;\n }\n // Append underscore if it's a reserved keyword\n return reservedKeywords.has(camelCasedTag)\n ? `${camelCasedTag}_`\n : camelCasedTag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make', // Added make\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n\nexport function parseJsonContentType(contentType: string | null | undefined) {\n if (!contentType) {\n return null;\n }\n\n // 1. Trim whitespace\n let mainType = contentType.trim();\n\n // 2. Remove parameters (anything after the first ';')\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n mainType = mainType.substring(0, semicolonIndex).trim(); // Trim potential space before ';'\n }\n\n // 3. Convert to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n if (mainType.endsWith('/json')) {\n return mainType.split('/')[1];\n } else if (mainType.endsWith('+json')) {\n return mainType.split('+')[1];\n }\n return null;\n}\n\n/**\n * Checks if a given content type string represents Server-Sent Events (SSE).\n * Handles case-insensitivity, parameters (like charset), and leading/trailing whitespace.\n *\n * @param contentType The content type string to check (e.g., from a Content-Type header).\n * @returns True if the content type is 'text/event-stream', false otherwise.\n */\nexport function isSseContentType(\n contentType: string | null | undefined,\n): boolean {\n if (!contentType) {\n return false; // Handle null, undefined, or empty string\n }\n\n // 1. Trim whitespace from the input string\n let mainType = contentType.trim();\n\n // 2. Find the position of the first semicolon (if any) to remove parameters\n const semicolonIndex = mainType.indexOf(';');\n if (semicolonIndex !== -1) {\n // Extract the part before the semicolon and trim potential space\n mainType = mainType.substring(0, semicolonIndex).trim();\n }\n\n // 3. Convert the main type part to lowercase for case-insensitive comparison\n mainType = mainType.toLowerCase();\n\n // 4. Compare against the standard SSE MIME type\n return mainType === 'text/event-stream';\n}\n\nexport function isStreamingContentType(\n contentType: string | null | undefined,\n): boolean {\n return contentType === 'application/octet-stream';\n}\n\nexport function isSuccessStatusCode(statusCode: number | string): boolean {\n statusCode = Number(statusCode);\n return statusCode >= 200 && statusCode < 300;\n}\n", "import { Option } from 'commander';\n\nexport const specOption = new Option(\n '-s, --spec <spec>',\n 'Path to OpenAPI specification file',\n);\n\nexport const outputOption = new Option(\n '-o, --output <output>',\n 'Output directory for the generated SDK',\n);\n", "import { Command } from 'commander';\nimport { execFile, execSync } from 'node:child_process';\n\nimport { loadSpec } from '@sdk-it/spec';\nimport { generate } from '@sdk-it/typescript';\n\nimport { outputOption, specOption } from '../options.ts';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n framework?: string;\n install: boolean;\n verbose: boolean;\n defaultFormatter: boolean;\n outputType?: 'default' | 'status';\n errorAsValue?: boolean;\n}\n\nexport default new Command('typescript')\n .alias('ts')\n .description('Generate TypeScript SDK')\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option(\n '--useTsExtension [value]',\n 'Use .ts extension for generated files',\n (value) => (value === 'false' ? false : true),\n true,\n )\n .option('-l, --language <language>', 'Programming language for the SDK')\n .option(\n '-m, --mode <mode>',\n 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option(\n '-f, --framework <framework>',\n 'Framework that is integrating with the SDK',\n )\n .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .option(\n '--install',\n 'Install dependencies using npm (only in full mode)',\n true,\n )\n .option('--output-type <outputType>', 'Endpoint output type', 'default')\n .option(\n '--error-as-value <errorAsValue>',\n 'Treat errors as values instead of throwing them',\n (value) => (value === 'false' ? false : true),\n true,\n )\n .option('--no-default-formatter', 'Do not use the default formatter')\n .option('--no-install', 'Do not install dependencies')\n .option('-v, --verbose', 'Verbose output', false)\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'minimal',\n name: options.name,\n style: {\n name: 'github',\n outputType: options.outputType,\n errorAsValue: options.errorAsValue,\n },\n useTsExtension: options.useTsExtension,\n formatCode: ({ env, output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, {\n env: { ...env, SDK_IT_OUTPUT: output },\n });\n } else if (options.defaultFormatter) {\n execSync('npx -y prettier $SDK_IT_OUTPUT --write', {\n env: {\n ...env,\n SDK_IT_OUTPUT: output,\n NODE_OPTIONS: '--experimental-strip-types',\n },\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n }\n },\n });\n\n // Install dependencies if in full mode and install option is enabled\n\n if (options.install && options.mode === 'full') {\n console.log('Installing dependencies...');\n execSync('npm install', {\n cwd: options.output,\n stdio: options.verbose ? 'inherit' : 'pipe',\n });\n }\n });\n"],
|
|
5
|
+
"mappings": ";;;AACA,SAAS,WAAAA,UAAS,eAAe;;;ACDjC,SAAS,eAAe;AACxB,SAAS,UAAU,gBAAgB;AAEnC,SAAS,gBAAgB;;;ACHzB,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,eAAsB,UAAU,UAAkB;AAChD,QAAM,UAAU,QAAQ,QAAQ;AAChC,QAAM,OAAO,MAAM,SAAS,UAAU,OAAO;AAC7C,UAAQ,SAAS;IACf,KAAK;AACH,aAAO,KAAK,MAAM,IAAI;IACxB,KAAK;IACL,KAAK;AACH,aAAO,MAAM,IAAI;IACnB;AACE,YAAM,IAAI,MAAM,+BAA+B,OAAO,EAAE;EAC5D;AACF;;;ACcA,SAAS,kBAAkB,aAA2B;AACpD,MAAI,CAAC,aAAa;AAChB,WAAO;EACT;AACA,MAAI,OAAO,gBAAgB,UAAU;AACnC,WAAO;EACT;AACA,MAAI,YAAY,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se", "Command", "execFile", "execSync", "generate", "Command", "generate", "execFile", "execSync", "generate", "Command"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/lib/langs/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;;
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/lib/langs/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;;AA6BpC,wBA6EK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^13.1.0",
|
|
23
|
-
"@sdk-it/typescript": "0.
|
|
24
|
-
"@sdk-it/dart": "0.
|
|
25
|
-
"@sdk-it/spec": "0.
|
|
23
|
+
"@sdk-it/typescript": "0.19.0",
|
|
24
|
+
"@sdk-it/dart": "0.19.0",
|
|
25
|
+
"@sdk-it/spec": "0.19.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|