Skip to content

Commit

Permalink
Use postman notation (#17028)
Browse files Browse the repository at this point in the history
* use Postman notation for path parameter

* Regenerate samples
  • Loading branch information
gcatanese authored Nov 11, 2023
1 parent 279a92c commit 09060c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public PostmanCollectionCodegen() {

@Override
public void postProcessParameter(CodegenParameter parameter) {
// create Postman variable from every path parameter
if(pathParamsAsVariables && parameter.isPathParam) {
variables.add(new PostmanVariable()
.addName(parameter.paramName)
Expand Down Expand Up @@ -216,13 +217,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo

for(CodegenOperation codegenOperation : opList) {

// use Postman notation for path parameter
codegenOperation.path = replacesBracesInPath(codegenOperation.path);

if(pathParamsAsVariables) {
// create Postman variable from path parameter
codegenOperation.path = doubleCurlyBraces(codegenOperation.path);
} else {
// use Postman notation for path parameter
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
// set value of path parameter with corresponding env variable
for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
codegenParameter.defaultValue = "{{" + codegenParameter.paramName + "}}";
}
}

codegenOperation.summary = getSummary(codegenOperation);

// request headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{{#pathParams}}
{
"key": "{{paramName}}",
"value": "",
"value": "{{defaultValue}}",
"description": "{{description}}"
}{{^-last}},{{/-last}}
{{/pathParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public void testVariables() throws Exception {
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");

// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
// verify path parameter value
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");

}

Expand Down Expand Up @@ -196,7 +198,9 @@ public void testVariablesInRequestExample() throws Exception {
assertFileContains(path, "{{MY_VAR_NAME}}");

// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
// verify path parameter value
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");

}

Expand Down Expand Up @@ -303,7 +307,10 @@ public void testNamingRequestsWithUrl() throws Exception {
Path path = Paths.get(output + "/postman.json");
assertFileExists(path);
// verify request name (from path)
assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
assertFileContains(path, "\"name\": \"/users/:userId\"");
// verify path parameter value
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");

}

@Test
Expand Down
2 changes: 1 addition & 1 deletion samples/schema/postman-collection/postman.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"variable": [
{
"key": "groupId",
"value": "",
"value": "1",
"description": "group Id"
}
],
Expand Down

0 comments on commit 09060c6

Please sign in to comment.