1717import java .nio .file .Paths ;
1818import java .util .ArrayList ;
1919import java .util .Arrays ;
20+ import java .util .HashMap ;
2021import java .util .LinkedHashMap ;
2122import java .util .List ;
23+ import java .util .Map ;
2224
2325import static org .junit .jupiter .api .Assertions .*;
2426import static org .openapitools .codegen .TestUtils .*;
@@ -76,6 +78,21 @@ public void testBasicGeneration() throws IOException {
7678 // verify request endpoint
7779 TestUtils .assertFileContains (path , "\" name\" : \" /users/:userId\" " );
7880
81+ ObjectMapper objectMapper = new ObjectMapper ();
82+ JsonNode root = objectMapper .readTree (new File (output + "/postman.json" ));
83+ JsonNode folders = root .get ("item" );
84+
85+ JsonNode basicFolder = null ;
86+ for (JsonNode folder : folders ) {
87+ if ("basic" .equals (folder .get ("name" ).asText ())) {
88+ basicFolder = folder ;
89+ break ;
90+ }
91+ }
92+
93+ assertNotNull (basicFolder );
94+ assertEquals ("Basic tag" , basicFolder .get ("description" ).asText ());
95+
7996 }
8097
8198 @ Test
@@ -101,6 +118,38 @@ public void testBasicGenerationJson() throws IOException {
101118 assertFileContains (path , "\" schema\" : \" https://schema.getpostman.com/json/collection/v2.1.0/collection.json\" " );
102119 }
103120
121+ @ Test
122+ public void testTagDescriptionIsJsonEscaped () throws IOException {
123+ File output = Files .createTempDirectory ("postmantest_" ).toFile ();
124+ output .deleteOnExit ();
125+
126+ final CodegenConfigurator configurator = new CodegenConfigurator ()
127+ .setGeneratorName ("postman-collection" )
128+ .setInputSpec ("src/test/resources/3_0/postman-collection/TagDescriptionEscaping.yaml" )
129+ .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
130+
131+ final ClientOptInput clientOptInput = configurator .toClientOptInput ();
132+ DefaultGenerator generator = new DefaultGenerator ();
133+ List <File > files = generator .opts (clientOptInput ).generate ();
134+
135+ files .forEach (File ::deleteOnExit );
136+
137+ ObjectMapper objectMapper = new ObjectMapper ();
138+ JsonNode root = objectMapper .readTree (new File (output + "/postman.json" ));
139+ JsonNode folders = root .get ("item" );
140+
141+ JsonNode basicFolder = null ;
142+ for (JsonNode folder : folders ) {
143+ if ("basic" .equals (folder .get ("name" ).asText ())) {
144+ basicFolder = folder ;
145+ break ;
146+ }
147+ }
148+
149+ assertNotNull (basicFolder );
150+ assertEquals ("Basic \" quoted\" tag\n second line" , basicFolder .get ("description" ).asText ());
151+ }
152+
104153 @ Test
105154 public void testValidatePostmanJson () throws IOException {
106155
@@ -702,24 +751,26 @@ public void testAddToMap() {
702751
703752 CodegenOperation operationUsers = new CodegenOperation ();
704753 operationUsers .path = "/users" ;
705- operationUsers .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" )));
754+ operationUsers .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" ). description ( "Basic tag" ) ));
706755 postmanV2Generator .addToMap (operationUsers );
707756
708757 CodegenOperation operationGroups = new CodegenOperation ();
709758 operationGroups .path = "/groups" ;
710- operationGroups .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" )));
759+ operationGroups .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" ). description ( "Basic tag" ) ));
711760 postmanV2Generator .addToMap (operationGroups );
712761
713762 CodegenOperation operationUserId = new CodegenOperation ();
714763 operationUserId .path = "/users/{id}" ;
715- operationUserId .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" )));
764+ operationUserId .tags = new ArrayList <>(Arrays .asList (new Tag ().name ("basic" ). description ( "Basic tag" ) ));
716765 postmanV2Generator .addToMap (operationUserId );
717766
767+ PostmanCollectionCodegen .PostmanRequestFolder folder = new PostmanCollectionCodegen .PostmanRequestFolder ("basic" , "Basic tag" );
768+
718769 // verify tag 'basic'
719770 assertEquals (1 , postmanV2Generator .codegenOperationsByTag .size ());
720- assertEquals (true , postmanV2Generator .codegenOperationsByTag .containsKey ("basic" ));
771+ assertEquals (true , postmanV2Generator .codegenOperationsByTag .containsKey (folder ));
721772
722- List <CodegenOperation > operations = postmanV2Generator .codegenOperationsByTag .get ("basic" );
773+ List <CodegenOperation > operations = postmanV2Generator .codegenOperationsByTag .get (folder );
723774 // verify order
724775 assertEquals ("/groups" , operations .get (0 ).path );
725776 assertEquals ("/users" , operations .get (1 ).path );
@@ -737,7 +788,18 @@ public void testAddToMapUsingDefaultTag() {
737788
738789 // verify tag 'default' is used
739790 assertEquals (1 , postmanV2Generator .codegenOperationsByTag .size ());
740- assertEquals (true , postmanV2Generator .codegenOperationsByTag .containsKey ("default" ));
791+ assertEquals (true , postmanV2Generator .codegenOperationsByTag .containsKey (new PostmanCollectionCodegen .PostmanRequestFolder ("Default" , "Default tag" )));
792+ }
793+
794+ @ Test
795+ public void testPostmanRequestFolderInMap () {
796+ PostmanCollectionCodegen .PostmanRequestFolder folder1 = new PostmanCollectionCodegen .PostmanRequestFolder ("test" , "descr" );
797+ Map <PostmanCollectionCodegen .PostmanRequestFolder , String > map = new HashMap <>();
798+ map .put (folder1 , "folder1" );
799+ PostmanCollectionCodegen .PostmanRequestFolder folder2 = new PostmanCollectionCodegen .PostmanRequestFolder ("test" , "descr" );
800+
801+ assertTrue (map .containsKey (folder2 ));
802+ assertEquals ("folder1" , map .get (folder2 ));
741803 }
742804
743805 @ Test
0 commit comments