Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@
<artifactId>junit</artifactId>
<version>${junit-version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/adyen/codegen/postman/PostmanV2Generator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.codegen.postman;

import com.adyen.codegen.postman.model.PostmanRequestFolder;
import com.adyen.codegen.postman.model.PostmanRequestItem;
import com.adyen.codegen.postman.model.PostmanResponse;
import com.adyen.codegen.postman.model.PostmanVariable;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class PostmanV2Generator extends DefaultCodegen implements CodegenConfig


// operations grouped by tag
protected Map<String, List<CodegenOperation>> codegenOperationsByTag = new HashMap<>();
protected Map<PostmanRequestFolder, List<CodegenOperation>> codegenOperationsByTag = new HashMap<>();
// list of operations
protected List<CodegenOperation> codegenOperationsList = new ArrayList<>();

Expand Down Expand Up @@ -270,24 +271,33 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
return results;
}


void addToMap(CodegenOperation codegenOperation){

String key;
PostmanRequestFolder folder = new PostmanRequestFolder();
String tagName;
String tagDescription;
if(codegenOperation.tags == null || codegenOperation.tags.isEmpty()) {
key = "default";
tagName = "Default";
Comment thread
gcatanese marked this conversation as resolved.
tagDescription = "Default tag";
} else {
key = codegenOperation.tags.get(0).getName();
// get from spec
tagName = codegenOperation.tags.get(0).getName();
tagDescription = codegenOperation.tags.get(0).getDescription();
if(tagDescription == null) {
tagDescription = tagName + " tag";
}
}
folder.setName(tagName);
folder.setDescription(tagDescription);

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder description is taken from codegenOperation.tags.get(0).getDescription() and then written into JSON via the template. To avoid invalid JSON when the description contains quotes/newlines, it should be formatted/escaped similarly to preprocessOpenAPI’s use of formatDescription (or another JSON-escaping approach) before storing it on the folder object.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback


List<CodegenOperation> list = codegenOperationsByTag.get(key);
List<CodegenOperation> list = codegenOperationsByTag.get(folder);

if(list == null) {
list = new ArrayList<>();
}
list.add(codegenOperation);

codegenOperationsByTag.put(key, list);
codegenOperationsByTag.put(folder, list);

// sort requests by path
list.sort(Comparator.comparing(obj -> obj.path));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.adyen.codegen.postman.model;

import java.util.Objects;

public class PostmanRequestFolder {

String name;
String description;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public PostmanRequestFolder name(String name) {
this.name = name;
return this;
}

public PostmanRequestFolder description(String description) {
this.description = description;
return this;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Comment thread
gcatanese marked this conversation as resolved.
Outdated
PostmanRequestFolder folder = (PostmanRequestFolder) o;
return Objects.equals(name, folder.name) && Objects.equals(description, folder.description);
}

@Override
public int hashCode() {
return Objects.hash(name, description);
}
Comment thread
gcatanese marked this conversation as resolved.
Outdated
}
3 changes: 2 additions & 1 deletion src/main/resources/postman-v2/postman.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{#codegenOperationsByTag}}
{{#entrySet}}
{
"name": "{{key}}",
"name": "{{key.name}}",
"description": "{{key.description}}",
Comment thread
gcatanese marked this conversation as resolved.
"item": [{{#value}}
{{>item}}{{^-last}},{{/-last}}{{/value}}
]
Expand Down
45 changes: 32 additions & 13 deletions src/test/java/com/adyen/codegen/postman/PostmanV2GeneratorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.codegen.postman;

import com.adyen.codegen.postman.model.PostmanRequestFolder;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.adyen.codegen.postman.model.PostmanRequestItem;
import io.swagger.v3.oas.models.tags.Tag;
Expand All @@ -20,9 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -34,8 +33,8 @@ public void testInitialConfigValues() throws Exception {
final PostmanV2Generator postmanV2Generator = new PostmanV2Generator();
postmanV2Generator.processOpts();

Assert.assertEquals(postmanV2Generator.folderStrategy, "Tags");
Assert.assertEquals(postmanV2Generator.postmanFile, "postman.json");
Assert.assertEquals("Tags", postmanV2Generator.folderStrategy);
Assert.assertEquals("postman.json", postmanV2Generator.postmanFile);

Assert.assertNull(postmanV2Generator.additionalProperties().get("codegenOperationsList"));
Assert.assertNotNull(postmanV2Generator.additionalProperties().get("codegenOperationsByTag"));
Expand All @@ -48,7 +47,7 @@ public void testConfigWithFolderStrategyTags() throws Exception {
postmanV2Generator.additionalProperties().put(postmanV2Generator.FOLDER_STRATEGY, "Tags");
postmanV2Generator.processOpts();

Assert.assertEquals(postmanV2Generator.folderStrategy, "Tags");
Assert.assertEquals("Tags", postmanV2Generator.folderStrategy);

Assert.assertNull(postmanV2Generator.additionalProperties().get("codegenOperationsList"));
Assert.assertNotNull(postmanV2Generator.additionalProperties().get("codegenOperationsByTag"));
Expand All @@ -62,7 +61,7 @@ public void testConfigWithCreationPostmanVariables() throws Exception {
postmanV2Generator.processOpts();

Assert.assertTrue(postmanV2Generator.isCreatePostmanVariables());
Assert.assertArrayEquals(postmanV2Generator.postmanVariableNames, new String[]{"VAR1", "VAR2", "VAR3"});
Assert.assertArrayEquals(new String[]{"VAR1", "VAR2", "VAR3"}, postmanV2Generator.postmanVariableNames);
}

@Test
Expand Down Expand Up @@ -91,6 +90,9 @@ public void testBasicGeneration() throws IOException {
TestUtils.assertFileContains(path, "\"name\": \"Get User\"");
// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
// verify folder match tag
TestUtils.assertFileContains(path, "\"name\": \"basic\"");
TestUtils.assertFileContains(path, "\"description\": \"A group of a Basic endpoints\"");

}

Expand All @@ -115,6 +117,11 @@ public void testBasicGenerationJson() throws IOException {
Path path = Paths.get(output + "/postman.json");
TestUtils.assertFileExists(path);
TestUtils.assertFileContains(path, "\"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\"");

// verify folder name
TestUtils.assertFileContains(path, "\"name\": \"Basic\"");
// verify folder description when tag description is not available
TestUtils.assertFileContains(path, "\"description\": \"Basic tag\"");
}

@Test
Expand Down Expand Up @@ -550,24 +557,24 @@ public void testAddToMap() {

CodegenOperation operationUsers = new CodegenOperation();
operationUsers.path = "/users";
operationUsers.tags = new ArrayList<>(Arrays.asList(new Tag().name("basic")));
operationUsers.tags = new ArrayList<>(Collections.singletonList(new Tag().name("basic").description("descr")));
postmanV2Generator.addToMap(operationUsers);

CodegenOperation operationGroups = new CodegenOperation();
operationGroups.path = "/groups";
operationGroups.tags = new ArrayList<>(Arrays.asList(new Tag().name("basic")));
operationGroups.tags = new ArrayList<>(Collections.singletonList(new Tag().name("basic").description("descr")));
postmanV2Generator.addToMap(operationGroups);

CodegenOperation operationUserId = new CodegenOperation();
operationUserId.path = "/users/{id}";
operationUserId.tags = new ArrayList<>(Arrays.asList(new Tag().name("basic")));
operationUserId.tags = new ArrayList<>(Collections.singletonList(new Tag().name("basic").description("descr")));
postmanV2Generator.addToMap(operationUserId);

// verify tag 'basic'
assertEquals(1, postmanV2Generator.codegenOperationsByTag.size());
assertEquals(true, postmanV2Generator.codegenOperationsByTag.containsKey("basic"));
assertTrue(postmanV2Generator.codegenOperationsByTag.containsKey(new PostmanRequestFolder().name("basic").description("descr")));

List<CodegenOperation> operations = postmanV2Generator.codegenOperationsByTag.get("basic");
List<CodegenOperation> operations = postmanV2Generator.codegenOperationsByTag.get(new PostmanRequestFolder().name("basic").description("descr"));
// verify order
assertEquals("/groups", operations.get(0).path);
assertEquals("/users", operations.get(1).path);
Expand All @@ -585,7 +592,7 @@ public void testAddToMapUsingDefaultTag() {

// verify tag 'default' is used
assertEquals(1, postmanV2Generator.codegenOperationsByTag.size());
assertEquals(true, postmanV2Generator.codegenOperationsByTag.containsKey("default"));
assertTrue(postmanV2Generator.codegenOperationsByTag.containsKey(new PostmanRequestFolder().name("Default").description("Default tag")));
}

// test special handling of `merchantId` and `companyId` path parameters
Expand Down Expand Up @@ -925,4 +932,16 @@ public void getGetResponseExample() throws IOException, ParseException {

}

@Test
public void testPostmanRequestFolderInMap() {
PostmanRequestFolder folder = new PostmanRequestFolder()
.name("test")
.description("descr");

Map<PostmanRequestFolder, String> map = new HashMap<>();
map.put(folder, "folder1");

Assert.assertTrue(map.containsKey(folder));
Comment thread
gcatanese marked this conversation as resolved.
Outdated
}

}
8 changes: 3 additions & 5 deletions src/test/java/com/adyen/codegen/postman/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.junit.Assert.*;


public class TestUtils {

Expand All @@ -18,7 +16,7 @@ public static void assertFileContains(Path path, String... lines) {
String file = linearize(generatedFile);
assertNotNull(file);
for (String line : lines)
assertTrue(file.contains(linearize(line)), "File does not contain line [" + line + "]");
assertTrue( "File does not contain line [" + line + "]", file.contains(linearize(line)));
} catch (IOException e) {
fail("Unable to evaluate file " + path);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/Basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ components:
- emailVerified
tags:
- name: basic
description: Basic tag
description: A group of a Basic endpoints
Comment thread
gcatanese marked this conversation as resolved.
Outdated