1111import org .openapitools .codegen .*;
1212import org .openapitools .codegen .config .CodegenConfigurator ;
1313import org .openapitools .codegen .languages .TypeScriptAngularClientCodegen ;
14+ import org .openapitools .codegen .model .OperationMap ;
15+ import org .openapitools .codegen .model .OperationsMap ;
1416import org .openapitools .codegen .typescript .TypeScriptGroups ;
1517import org .testng .Assert ;
1618import org .testng .annotations .Test ;
1921import java .io .IOException ;
2022import java .nio .file .Files ;
2123import java .nio .file .Paths ;
24+ import java .util .ArrayList ;
2225import java .util .HashMap ;
26+ import java .util .List ;
2327import java .util .Map ;
2428
2529import static org .assertj .core .api .Assertions .assertThat ;
2630
27-
2831@ Test (groups = {TypeScriptGroups .TYPESCRIPT , TypeScriptGroups .TYPESCRIPT_ANGULAR })
2932public class TypeScriptAngularClientCodegenTest {
3033 @ Test
@@ -117,14 +120,14 @@ public void testModelFileSuffix() {
117120 @ Test
118121 public void testOperationIdParser () {
119122 OpenAPI openAPI = TestUtils .createOpenAPI ();
120- Operation operation1 = new Operation ().operationId ("123_test_@#$%_special_tags" ).responses (new ApiResponses ().addApiResponse ("201" , new ApiResponse ().description ("OK" )));
123+ Operation operation1 = new Operation ().operationId ("123_test_@#$%_special_tags" ).responses (new ApiResponses ().addApiResponse ("201"
124+ , new ApiResponse ().description ("OK" )));
121125 openAPI .path ("another-fake/dummy/" , new PathItem ().get (operation1 ));
122126 final TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen ();
123127 codegen .setOpenAPI (openAPI );
124128
125129 CodegenOperation co1 = codegen .fromOperation ("/another-fake/dummy/" , "get" , operation1 , null );
126130 org .testng .Assert .assertEquals (co1 .operationId , "_123testSpecialTags" );
127-
128131 }
129132
130133 @ Test
@@ -148,7 +151,6 @@ public void testSnapshotVersion() {
148151 codegen .preprocessOpenAPI (openAPI );
149152
150153 Assert .assertTrue (codegen .getNpmVersion ().matches ("^3.0.0-M1-SNAPSHOT.[0-9]{12}$" ));
151-
152154 }
153155
154156 @ Test
@@ -172,7 +174,6 @@ public void testWithoutSnapshotVersion() {
172174 codegen .preprocessOpenAPI (openAPI );
173175
174176 Assert .assertTrue (codegen .getNpmVersion ().matches ("^3.0.0-M1$" ));
175-
176177 }
177178
178179 @ Test
@@ -426,9 +427,9 @@ public void testBasePath() throws IOException {
426427
427428 // WHEN
428429 final CodegenConfigurator configurator = new CodegenConfigurator ()
429- .setGeneratorName ("typescript-angular" )
430- .setInputSpec (specPath )
431- .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
430+ .setGeneratorName ("typescript-angular" )
431+ .setInputSpec (specPath )
432+ .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
432433
433434 final ClientOptInput clientOptInput = configurator .toClientOptInput ();
434435
@@ -450,9 +451,9 @@ public void testEnumAsConst() throws IOException {
450451
451452 // WHEN
452453 final CodegenConfigurator configurator = new CodegenConfigurator ()
453- .setGeneratorName ("typescript-angular" )
454- .setInputSpec (specPath )
455- .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
454+ .setGeneratorName ("typescript-angular" )
455+ .setInputSpec (specPath )
456+ .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
456457
457458 final ClientOptInput clientOptInput = configurator .toClientOptInput ();
458459
@@ -475,9 +476,9 @@ public void testDeepObject() throws IOException {
475476
476477 // WHEN
477478 final CodegenConfigurator configurator = new CodegenConfigurator ()
478- .setGeneratorName ("typescript-angular" )
479- .setInputSpec (specPath )
480- .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
479+ .setGeneratorName ("typescript-angular" )
480+ .setInputSpec (specPath )
481+ .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
481482
482483 final ClientOptInput clientOptInput = configurator .toClientOptInput ();
483484
@@ -511,7 +512,31 @@ public void testOpenIdCredentialsAreSet() throws IOException {
511512
512513 //THEN
513514 final String fileContents = Files .readString (Paths .get (output + "/api/default.service.ts" ));
514- String credentialsSet = "localVarHeaders = this.configuration.addCredentialToHeaders('oidc', 'Authorization', localVarHeaders, 'Bearer ');" ;
515+ String credentialsSet = "localVarHeaders = this.configuration.addCredentialToHeaders('oidc', 'Authorization', localVarHeaders, " +
516+ "'Bearer ');" ;
515517 assertThat (fileContents ).contains (credentialsSet );
516518 }
519+
520+ @ Test
521+ public void testMergingImports () {
522+ TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen ();
523+
524+ List <Map <String , String >> imports = new ArrayList <>();
525+ imports .add (Map .of ("classname" , "type1" , "import" , "npmPackage" ));
526+ imports .add (Map .of ("classname" , "type2" , "import" , "npmPackage" ));
527+ imports .add (Map .of ("classname" , "type3" , "import" , "npmPackage2" ));
528+ OperationMap operation = new OperationMap ();
529+ operation .setClassname ("classname" );
530+ operation .setOperation (List .of ());
531+ OperationsMap operationsMap = new OperationsMap ();
532+ operationsMap .setImports (imports );
533+ operationsMap .setOperation (operation );
534+
535+ OperationsMap result = codegen .postProcessOperationsWithModels (operationsMap , List .of ());
536+
537+ assertThat (result .getImports ()).containsExactlyInAnyOrder (
538+ Map .of ("classname" , "type1, type2" , "filename" , "npmPackage" , "import" , "npmPackage" ),
539+ Map .of ("classname" , "type3" , "filename" , "npmPackage2" , "import" , "npmPackage2" )
540+ );
541+ }
517542}
0 commit comments