@@ -32,6 +32,7 @@ import {
32
32
requestBodyAsParameter ,
33
33
statusStringToType ,
34
34
} from "../common/typescript-common"
35
+ import { TypescriptFetchClientBuilder } from "../typescript-fetch/typescript-fetch-client-builder"
35
36
36
37
function reduceParamsToOpenApiSchema ( parameters : IRParameter [ ] ) : IRModelObject {
37
38
return parameters . reduce (
@@ -446,7 +447,7 @@ export async function generateTypescriptNextJS(
446
447
447
448
const project = new Project ( )
448
449
449
- const routers = (
450
+ const serverRouters = (
450
451
await Promise . all (
451
452
input . groupedOperations ( "route" ) . map ( async ( group ) => {
452
453
const filename = path . join (
@@ -504,10 +505,30 @@ export async function generateTypescriptNextJS(
504
505
)
505
506
) . flat ( )
506
507
508
+ const clientOutputPath = [ generatedDirectory , "clients" , "client.ts" ] . join (
509
+ path . sep ,
510
+ )
511
+ const clientImportBuilder = new ImportBuilder ( { filename : clientOutputPath } )
512
+
513
+ const fetchClientBuilder = new TypescriptFetchClientBuilder (
514
+ clientOutputPath ,
515
+ "ApiClient" ,
516
+ input ,
517
+ clientImportBuilder ,
518
+ rootTypeBuilder . withImports ( clientImportBuilder ) ,
519
+ rootSchemaBuilder . withImports ( clientImportBuilder ) ,
520
+ {
521
+ enableRuntimeResponseValidation : config . enableRuntimeResponseValidation ,
522
+ } ,
523
+ )
524
+
525
+ input . allOperations ( ) . map ( ( it ) => fetchClientBuilder . add ( it ) )
526
+
507
527
await emitGenerationResult (
508
528
config . dest ,
509
529
[
510
- ...routers ,
530
+ ...serverRouters ,
531
+ fetchClientBuilder . toCompilationUnit ( ) ,
511
532
rootTypeBuilder . toCompilationUnit ( ) ,
512
533
rootSchemaBuilder . toCompilationUnit ( ) ,
513
534
] ,
0 commit comments