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 ( / e x p o r t c l a s s L e a d e r b o a r d s [ \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 ( / e x p o r t c l a s s \w + [ ^ { ] * { [ \s \S ] * ?(? = e x p o r t | $ ) / ) ;
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 ) ;
0 commit comments