Skip to content

Commit b5055e9

Browse files
Copilotsmorimoto
andcommitted
Initial investigation of the TypeScript syntax issue in 13.2.8
Co-authored-by: smorimoto <[email protected]>
1 parent 82daa27 commit b5055e9

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

test-reproduction-issue.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env node
2+
3+
import { generateApi } from './dist/lib.js';
4+
import fs from 'fs/promises';
5+
import path from 'path';
6+
import os from 'os';
7+
8+
// Test schema that should match the issue report more closely
9+
const testSchema = {
10+
"openapi": "3.0.0",
11+
"info": {
12+
"title": "Test API for issue reproduction",
13+
"version": "1.0.0"
14+
},
15+
"paths": {
16+
"/api/leaderboard/{id}": {
17+
"get": {
18+
"operationId": "getLeaderboard",
19+
"summary": "Gets a leaderboard by its ID",
20+
"tags": ["Leaderboards"],
21+
"parameters": [
22+
{
23+
"name": "id",
24+
"in": "path",
25+
"required": true,
26+
"schema": {
27+
"type": "integer"
28+
}
29+
}
30+
],
31+
"responses": {
32+
"200": {
33+
"description": "OK",
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"type": "object",
38+
"properties": {
39+
"id": { "type": "integer" },
40+
"name": { "type": "string" }
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
};
51+
52+
async function reproduce() {
53+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'test-'));
54+
const schemaPath = path.join(tmpDir, 'schema.json');
55+
56+
await fs.writeFile(schemaPath, JSON.stringify(testSchema, null, 2));
57+
58+
console.log('Generating API from schema...');
59+
const result = await generateApi({
60+
input: schemaPath,
61+
output: tmpDir,
62+
fileName: 'api',
63+
silent: true,
64+
// Try different options to see if any trigger the bug
65+
extractRequestParams: false,
66+
modular: false,
67+
apiClassName: 'Leaderboards',
68+
});
69+
70+
const generatedContent = await fs.readFile(path.join(tmpDir, 'api.ts'), 'utf8');
71+
72+
console.log('Generated content (relevant parts):');
73+
console.log('='.repeat(60));
74+
75+
// Find the class definition area with methods
76+
const classMatch = generatedContent.match(/export class Leaderboards[\s\S]*$/);
77+
if (classMatch) {
78+
const classContent = classMatch[0];
79+
console.log(classContent.substring(0, 1000) + '...'); // Show first 1000 chars
80+
} else {
81+
console.log('Leaderboards class not found');
82+
// Try to find any export class
83+
const anyClassMatch = generatedContent.match(/export class \w+[^{]*{[\s\S]*?(?=export|$)/);
84+
if (anyClassMatch) {
85+
console.log('Found other class:');
86+
console.log(anyClassMatch[0].substring(0, 500) + '...');
87+
} else {
88+
console.log('No export class found');
89+
}
90+
}
91+
92+
console.log('='.repeat(60));
93+
94+
// Check if syntax is correct
95+
const hasAssignment = generatedContent.includes('getLeaderboard = ');
96+
const hasColonSyntax = generatedContent.includes('getLeaderboard: ');
97+
98+
console.log(`Has assignment syntax (=): ${hasAssignment}`);
99+
console.log(`Has colon syntax (:): ${hasColonSyntax}`);
100+
101+
// Clean up
102+
await fs.rm(tmpDir, { recursive: true });
103+
}
104+
105+
reproduce().catch(console.error);

test-reproduction.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
3+
import { generateApi } from './dist/lib.js';
4+
import fs from 'fs/promises';
5+
import path from 'path';
6+
import os from 'os';
7+
8+
// Test schema similar to the issue report
9+
const testSchema = {
10+
"openapi": "3.0.0",
11+
"info": {
12+
"title": "Test API for issue reproduction",
13+
"version": "1.0.0"
14+
},
15+
"paths": {
16+
"/": {
17+
"get": {
18+
"operationId": "123getUser",
19+
"summary": "Gets a leaderboard by its ID",
20+
21+
"parameters": [
22+
{
23+
"name": "id",
24+
"in": "path",
25+
"required": true,
26+
"schema": {
27+
"type": "integer"
28+
}
29+
}
30+
],
31+
"responses": {
32+
"200": {
33+
"description": "OK",
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"type": "object",
38+
"properties": {
39+
"id": { "type": "integer" },
40+
"name": { "type": "string" }
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
};
51+
52+
async function reproduce() {
53+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'test-'));
54+
const schemaPath = path.join(tmpDir, 'schema.json');
55+
56+
await fs.writeFile(schemaPath, JSON.stringify(testSchema, null, 2));
57+
58+
console.log('Generating API from schema...');
59+
const result = await generateApi({
60+
input: schemaPath,
61+
output: tmpDir,
62+
fileName: 'api',
63+
silent: true
64+
});
65+
66+
const generatedContent = await fs.readFile(path.join(tmpDir, 'api.ts'), 'utf8');
67+
68+
console.log('Generated content (relevant parts):');
69+
console.log('='.repeat(60));
70+
71+
// Find the class definition area with methods
72+
const classMatch = generatedContent.match(/export class Api[\s\S]*?}$/m);
73+
if (classMatch) {
74+
const classContent = classMatch[0];
75+
console.log(classContent);
76+
} else {
77+
console.log('Class not found');
78+
}
79+
80+
console.log('='.repeat(60));
81+
82+
// Check if syntax is correct
83+
const hasAssignment = generatedContent.includes('123GetUser" = ');
84+
const hasColonSyntax = generatedContent.includes('123GetUser": ');
85+
86+
console.log(`Has assignment syntax (=): ${hasAssignment}`);
87+
console.log(`Has colon syntax (:): ${hasColonSyntax}`);
88+
89+
// Clean up
90+
await fs.rm(tmpDir, { recursive: true });
91+
}
92+
93+
reproduce().catch(console.error);

0 commit comments

Comments
 (0)