@@ -36,40 +36,46 @@ async function loadOpenAPISpec(specSource: string): Promise<OpenAPIV3.Document>
36
36
*/
37
37
export async function generateApiClient ( config : OpenAPIConfig ) : Promise < void > {
38
38
try {
39
- // Load the OpenAPI specification
40
- const spec = await loadOpenAPISpec ( config . specSource ) ;
41
- console . log ( 'Generated TypeScript interfaces successfully' ) ;
39
+ // Load specs
40
+ const specs = Array . isArray ( config . specSource )
41
+ ? await Promise . all ( config . specSource . map ( loadOpenAPISpec ) )
42
+ : [ await loadOpenAPISpec ( config . specSource ) ] ;
43
+ // Generate for each spec...
44
+ for ( const spec of specs ) {
45
+ console . log ( 'Generated TypeScript interfaces successfully' ) ;
46
+ const title = spec . info . title . toLowerCase ( ) . replace ( / \s + / g, '-' ) ;
42
47
43
- // Create export directory if it doesn't exist
44
- await mkdir ( config . exportDir , { recursive : true } ) ;
45
-
46
- // Generate and write type definitions
47
- const typeDefinitions = generateTypeDefinitions ( spec ) ;
48
- await writeFile (
49
- resolve ( config . exportDir , 'types.ts' ) ,
50
- typeDefinitions ,
51
- 'utf-8'
52
- ) ;
53
-
54
- // Generate and write API client
55
- const clientCode = generateApiClientCode ( spec ) ;
56
- await writeFile (
57
- resolve ( config . exportDir , 'client.ts' ) ,
58
- clientCode ,
59
- 'utf-8'
60
- ) ;
61
-
62
- // Generate and write React Query options
63
- const queryCode = generateReactQuery ( spec ) ;
64
- await writeFile (
65
- resolve ( config . exportDir , 'queries.ts' ) ,
66
- queryCode ,
67
- 'utf-8'
68
- ) ;
69
-
70
- console . log ( 'Generated API client successfully' ) ;
71
- console . log ( 'Generated React Query options successfully' ) ;
72
-
48
+ // Create export directory if it doesn't exist
49
+ await mkdir ( config . exportDir , { recursive : true } ) ;
50
+
51
+ // Generate and write type definitions
52
+ const typeDefinitions = generateTypeDefinitions ( spec ) ;
53
+ await writeFile (
54
+ resolve ( config . exportDir , `${ title } .schema.ts` ) ,
55
+ typeDefinitions ,
56
+ 'utf-8'
57
+ ) ;
58
+
59
+
60
+ // Generate and write API client
61
+ const clientCode = generateApiClientCode ( spec ) ;
62
+ await writeFile (
63
+ resolve ( config . exportDir , `${ title } .client.ts` ) ,
64
+ clientCode ,
65
+ 'utf-8'
66
+ ) ;
67
+
68
+ // Generate and write React Query options
69
+ const queryCode = generateReactQuery ( spec ) ;
70
+ await writeFile (
71
+ resolve ( config . exportDir , `${ title } .queryOptions.ts` ) ,
72
+ queryCode ,
73
+ 'utf-8'
74
+ ) ;
75
+
76
+ console . log ( 'Generated API client successfully' ) ;
77
+ console . log ( 'Generated React Query options successfully' ) ;
78
+ }
73
79
} catch ( error ) {
74
80
if ( error instanceof Error ) {
75
81
throw new Error ( `Failed to generate API client: ${ error . message } ` ) ;
0 commit comments