Skip to content

Commit

Permalink
[Postman Collection] Fix path parameter syntax (#16827)
Browse files Browse the repository at this point in the history
* Format Postman request url

* Generate schema
  • Loading branch information
gcatanese authored Oct 15, 2023
1 parent 3bc4f67 commit b4f9d81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,12 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
for(CodegenOperation codegenOperation : opList) {

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);
}

codegenOperation.summary = getSummary(codegenOperation);

// request headers
Expand Down Expand Up @@ -503,6 +506,15 @@ public String doubleCurlyBraces(String str) {

}

// convert path from /users/{id} to /users/:id
String replacesBracesInPath(String path) {

String s = path.replace("{", ":");
s = s.replace("}", "");

return s;
}

public String extractExampleByName(String ref) {
return ref.substring(ref.lastIndexOf("/") + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public void testBasicGeneration() throws IOException {

// verify request name (from summary)
assertFileContains(path, "\"name\": \"Get User\"");
// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");

}

Expand Down Expand Up @@ -155,6 +157,9 @@ public void testVariables() throws Exception {
TestUtils.assertFileContains(path,
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");

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

}

@Test
Expand Down Expand Up @@ -187,6 +192,9 @@ public void testVariablesInRequestExample() throws Exception {

assertFileContains(path, "{{MY_VAR_NAME}}");

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

}

@Test
Expand Down
18 changes: 9 additions & 9 deletions samples/schema/postman-collection/postman.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "default",
"item": [
{
"name": "/users/{userId} (DEPRECATED)",
"name": "/users/:userId (DEPRECATED)",
"description": "Update the information of an existing user.",
"item": [
{
Expand Down Expand Up @@ -52,13 +52,13 @@
}
},
"url": {
"raw": "{{baseUrl}}/users/{userId}",
"raw": "{{baseUrl}}/users/:userId",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
"{userId}"
":userId"
],
"variable": [
{
Expand All @@ -81,7 +81,7 @@
"name": "advanced",
"item": [
{
"name": "/groups/{groupId}",
"name": "/groups/:groupId",
"description": "Get group of users",
"item": [
{
Expand All @@ -105,13 +105,13 @@
}
},
"url": {
"raw": "{{baseUrl}}/groups/{groupId}",
"raw": "{{baseUrl}}/groups/:groupId",
"host": [
"{{baseUrl}}"
],
"path": [
"groups",
"{groupId}"
":groupId"
],
"variable": [
{
Expand All @@ -129,7 +129,7 @@
]
},
{
"name": "/users/{userId}",
"name": "/users/:userId",
"description": "Retrieve the information of the user with the matching user ID.",
"item": [
{
Expand Down Expand Up @@ -163,13 +163,13 @@
}
},
"url": {
"raw": "{{baseUrl}}/users/{userId}",
"raw": "{{baseUrl}}/users/:userId",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
"{userId}"
":userId"
],
"variable": [
{
Expand Down

0 comments on commit b4f9d81

Please sign in to comment.