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 @Override
public void postProcessParameter(CodegenParameter parameter) { public void postProcessParameter(CodegenParameter parameter) {
// create Postman variable from every path parameter
if(pathParamsAsVariables && parameter.isPathParam) { if(pathParamsAsVariables && parameter.isPathParam) {
variables.add(new PostmanVariable() variables.add(new PostmanVariable()
.addName(parameter.paramName) .addName(parameter.paramName)
@ -216,13 +217,16 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
for(CodegenOperation codegenOperation : opList) { for(CodegenOperation codegenOperation : opList) {
// use Postman notation for path parameter
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
if(pathParamsAsVariables) { if(pathParamsAsVariables) {
// create Postman variable from path parameter // set value of path parameter with corresponding env variable
codegenOperation.path = doubleCurlyBraces(codegenOperation.path); for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
} else { codegenParameter.defaultValue = "{{" + codegenParameter.paramName + "}}";
// use Postman notation for path parameter }
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
} }
codegenOperation.summary = getSummary(codegenOperation); codegenOperation.summary = getSummary(codegenOperation);
// request headers // request headers

View File

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

View File

@ -161,7 +161,9 @@ public class PostmanCollectionCodegenTest {
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\""); "key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");
// verify request endpoint // 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}}"); assertFileContains(path, "{{MY_VAR_NAME}}");
// verify request endpoint // 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"); Path path = Paths.get(output + "/postman.json");
assertFileExists(path); assertFileExists(path);
// verify request name (from 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 @Test

View File

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