Skip to content

Commit 09060c6

Browse files
authored
Use postman notation (#17028)
* use Postman notation for path parameter * Regenerate samples
1 parent 279a92c commit 09060c6

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public PostmanCollectionCodegen() {
131131

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

217218
for(CodegenOperation codegenOperation : opList) {
218219

220+
// use Postman notation for path parameter
221+
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
222+
219223
if(pathParamsAsVariables) {
220-
// create Postman variable from path parameter
221-
codegenOperation.path = doubleCurlyBraces(codegenOperation.path);
222-
} else {
223-
// use Postman notation for path parameter
224-
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
224+
// set value of path parameter with corresponding env variable
225+
for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
226+
codegenParameter.defaultValue = "{{" + codegenParameter.paramName + "}}";
227+
}
225228
}
229+
226230
codegenOperation.summary = getSummary(codegenOperation);
227231

228232
// request headers

modules/openapi-generator/src/main/resources/postman-collection/item.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{{#pathParams}}
4040
{
4141
"key": "{{paramName}}",
42-
"value": "",
42+
"value": "{{defaultValue}}",
4343
"description": "{{description}}"
4444
}{{^-last}},{{/-last}}
4545
{{/pathParams}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/postman/PostmanCollectionCodegenTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ public void testVariables() throws Exception {
161161
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");
162162

163163
// verify request endpoint
164-
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
164+
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
165+
// verify path parameter value
166+
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");
165167

166168
}
167169

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

198200
// verify request endpoint
199-
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
201+
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
202+
// verify path parameter value
203+
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");
200204

201205
}
202206

@@ -303,7 +307,10 @@ public void testNamingRequestsWithUrl() throws Exception {
303307
Path path = Paths.get(output + "/postman.json");
304308
assertFileExists(path);
305309
// verify request name (from path)
306-
assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
310+
assertFileContains(path, "\"name\": \"/users/:userId\"");
311+
// verify path parameter value
312+
TestUtils.assertFileContains(path, "key\": \"userId\", \"value\": \"{{userId}}\",");
313+
307314
}
308315

309316
@Test

samples/schema/postman-collection/postman.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"variable": [
117117
{
118118
"key": "groupId",
119-
"value": "",
119+
"value": "1",
120120
"description": "group Id"
121121
}
122122
],

0 commit comments

Comments
 (0)