@taico/openapi-sdkgen 0.1.0 → 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 CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { resolve } from 'path';
2
3
  import { generate } from './index.js';
3
4
  const args = process.argv.slice(2);
4
5
  if (args.length < 2) {
@@ -6,7 +7,12 @@ if (args.length < 2) {
6
7
  process.exit(1);
7
8
  }
8
9
  const [inputPath, outputDir] = args;
9
- generate({ inputPath, outputDir })
10
+ const invocationDir = process.env.npm_lifecycle_event
11
+ ? process.cwd()
12
+ : (process.env.INIT_CWD || process.cwd());
13
+ const resolvedInputPath = resolve(invocationDir, inputPath);
14
+ const resolvedOutputDir = resolve(invocationDir, outputDir);
15
+ generate({ inputPath: resolvedInputPath, outputDir: resolvedOutputDir })
10
16
  .then(() => {
11
17
  console.log('✓ Client generation complete');
12
18
  })
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
- props.push(` ${propName}${optional ? '?' : ''}: ${propType};`);
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
- baseType = schema.items ? `${schemaToTypeScript(schema.items)}[]` : 'any[]';
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
- props.push(`${propName}${optional ? '?' : ''}: ${schemaToTypeScript(propSchema)}`);
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
- const bodySchema = op.requestBody.content.get('application/json');
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
@@ -26,7 +26,7 @@ export interface Operation {
26
26
  }
27
27
  export interface Parameter {
28
28
  name: string;
29
- in: 'path' | 'query' | 'header';
29
+ in: 'path' | 'query' | 'header' | 'cookie';
30
30
  required: boolean;
31
31
  schema: SchemaInfo;
32
32
  description?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taico/openapi-sdkgen",
3
- "version": "0.1.0",
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.0.0",
40
- "@nestjs/core": "^11.0.0",
41
- "@nestjs/platform-express": "^11.0.0",
42
- "@nestjs/swagger": "^11.2.1",
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",