Use postman notation (#17028)

* use Postman notation for path parameter

* Regenerate samples
This commit is contained in:
Beppe Catanese 2023-11-11 17:08:07 +01:00 committed by GitHub
parent 279a92c2ed
commit 09060c6c22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 10 deletions

View File

@ -131,6 +131,7 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
@Override
public void postProcessParameter(CodegenParameter parameter) {
// create Postman variable from every path parameter
if(pathParamsAsVariables && parameter.isPathParam) {
variables.add(new PostmanVariable()
.addName(parameter.paramName)
@ -216,13 +217,16 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
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

View File

@ -39,7 +39,7 @@
{{#pathParams}}
{
"key": "{{paramName}}",
"value": "",
"value": "{{defaultValue}}",
"description": "{{description}}"
}{{^-last}},{{/-last}}
{{/pathParams}}

View File

@ -161,7 +161,9 @@ public class PostmanCollectionCodegenTest {
"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}}\",");
}
@ -196,7 +198,9 @@ public class PostmanCollectionCodegenTest {
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}}\",");
}
@ -303,7 +307,10 @@ public class PostmanCollectionCodegenTest {
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

View File

@ -116,7 +116,7 @@
"variable": [
{
"key": "groupId",
"value": "",
"value": "1",
"description": "group Id"
}
],