@taico/openapi-sdkgen 0.1.1 → 0.1.2
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/cli.js +3 -1
- package/dist/generator.js +15 -4
- package/dist/parser.js +8 -1
- package/dist/types.d.ts +1 -1
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,9 @@ if (args.length < 2) {
|
|
|
7
7
|
process.exit(1);
|
|
8
8
|
}
|
|
9
9
|
const [inputPath, outputDir] = args;
|
|
10
|
-
const invocationDir = process.env.
|
|
10
|
+
const invocationDir = process.env.npm_lifecycle_event
|
|
11
|
+
? process.cwd()
|
|
12
|
+
: (process.env.INIT_CWD || process.cwd());
|
|
11
13
|
const resolvedInputPath = resolve(invocationDir, inputPath);
|
|
12
14
|
const resolvedOutputDir = resolve(invocationDir, outputDir);
|
|
13
15
|
generate({ inputPath: resolvedInputPath, outputDir: resolvedOutputDir })
|
package/dist/generator.js
CHANGED
|
@@ -32,7 +32,8 @@ function generateTypeDefinition(name, schema) {
|
|
|
32
32
|
for (const [propName, propSchema] of schema.properties) {
|
|
33
33
|
const optional = !schema.required?.includes(propName);
|
|
34
34
|
const propType = schemaToTypeScript(propSchema);
|
|
35
|
-
|
|
35
|
+
const quotedPropName = quoteIfNeeded(propName);
|
|
36
|
+
props.push(` ${quotedPropName}${optional ? '?' : ''}: ${propType};`);
|
|
36
37
|
}
|
|
37
38
|
return `export interface ${name} {\n${props.join('\n')}\n}`;
|
|
38
39
|
}
|
|
@@ -62,14 +63,22 @@ function schemaToTypeScript(schema) {
|
|
|
62
63
|
baseType = 'boolean';
|
|
63
64
|
break;
|
|
64
65
|
case 'array':
|
|
65
|
-
|
|
66
|
+
if (schema.items) {
|
|
67
|
+
const itemType = schemaToTypeScript(schema.items);
|
|
68
|
+
// Wrap in parentheses if the item type contains a union (|) to ensure correct precedence
|
|
69
|
+
baseType = itemType.includes(' | ') ? `(${itemType})[]` : `${itemType}[]`;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
baseType = 'any[]';
|
|
73
|
+
}
|
|
66
74
|
break;
|
|
67
75
|
case 'object':
|
|
68
76
|
if (schema.properties) {
|
|
69
77
|
const props = [];
|
|
70
78
|
for (const [propName, propSchema] of schema.properties) {
|
|
71
79
|
const optional = !schema.required?.includes(propName);
|
|
72
|
-
|
|
80
|
+
const quotedPropName = quoteIfNeeded(propName);
|
|
81
|
+
props.push(`${quotedPropName}${optional ? '?' : ''}: ${schemaToTypeScript(propSchema)}`);
|
|
73
82
|
}
|
|
74
83
|
baseType = `{ ${props.join('; ')} }`;
|
|
75
84
|
}
|
|
@@ -448,7 +457,9 @@ function buildMethodParams(op) {
|
|
|
448
457
|
paramFields.push(`${quotedName}${optional ? '?' : ''}: ${schemaToTypeScript(param.schema)}`);
|
|
449
458
|
}
|
|
450
459
|
if (op.requestBody) {
|
|
451
|
-
|
|
460
|
+
// Try to get the body schema from any content type (prefer application/json)
|
|
461
|
+
const bodySchema = op.requestBody.content.get('application/json') ||
|
|
462
|
+
Array.from(op.requestBody.content.values())[0];
|
|
452
463
|
if (bodySchema) {
|
|
453
464
|
const optional = !op.requestBody.required;
|
|
454
465
|
paramFields.push(`body${optional ? '?' : ''}: ${schemaToTypeScript(bodySchema.schema)}`);
|
package/dist/parser.js
CHANGED
|
@@ -30,7 +30,7 @@ function parseOperations(paths) {
|
|
|
30
30
|
// Parse path-level parameters (common to all operations on this path)
|
|
31
31
|
const pathLevelParams = parseParameters(pathItem.parameters || []);
|
|
32
32
|
for (const [method, operation] of Object.entries(pathItem)) {
|
|
33
|
-
if (!['get', 'post', 'put', 'patch', 'delete'].includes(method)) {
|
|
33
|
+
if (!['get', 'post', 'put', 'patch', 'delete', 'head', 'options'].includes(method)) {
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
const op = operation;
|
|
@@ -119,6 +119,13 @@ function parseSchema(schema) {
|
|
|
119
119
|
if (!schema) {
|
|
120
120
|
return { type: 'any' };
|
|
121
121
|
}
|
|
122
|
+
if (schema.allOf?.length === 1) {
|
|
123
|
+
const merged = parseSchema(schema.allOf[0]);
|
|
124
|
+
return {
|
|
125
|
+
...merged,
|
|
126
|
+
nullable: schema.nullable ?? merged.nullable,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
122
129
|
if (schema.$ref) {
|
|
123
130
|
return {
|
|
124
131
|
type: 'ref',
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taico/openapi-sdkgen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"release": "npm run build && npm publish --access public"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "^11.
|
|
40
|
-
"@nestjs/core": "^11.
|
|
41
|
-
"@nestjs/platform-express": "^11.
|
|
42
|
-
"@nestjs/swagger": "^11.2.
|
|
39
|
+
"@nestjs/common": "^11.1.17",
|
|
40
|
+
"@nestjs/core": "^11.1.17",
|
|
41
|
+
"@nestjs/platform-express": "^11.1.17",
|
|
42
|
+
"@nestjs/swagger": "^11.2.6",
|
|
43
43
|
"@types/node": "^20.0.0",
|
|
44
44
|
"reflect-metadata": "^0.2.0",
|
|
45
45
|
"rxjs": "^7.8.1",
|