[Postman Collection] Fix path parameter syntax (#16827)

* Format Postman request url

* Generate schema
This commit is contained in:
Beppe Catanese 2023-10-15 03:35:57 +02:00 committed by GitHub
parent 3bc4f67333
commit b4f9d8103f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -217,9 +217,12 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
for(CodegenOperation codegenOperation : opList) { for(CodegenOperation codegenOperation : opList) {
if(pathParamsAsVariables) { if(pathParamsAsVariables) {
// create Postman variable from path parameter
codegenOperation.path = doubleCurlyBraces(codegenOperation.path); codegenOperation.path = doubleCurlyBraces(codegenOperation.path);
} else {
// use Postman notation for path parameter
codegenOperation.path = replacesBracesInPath(codegenOperation.path);
} }
codegenOperation.summary = getSummary(codegenOperation); codegenOperation.summary = getSummary(codegenOperation);
// request headers // request headers
@ -503,6 +506,15 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
} }
// 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) { public String extractExampleByName(String ref) {
return ref.substring(ref.lastIndexOf("/") + 1); return ref.substring(ref.lastIndexOf("/") + 1);
} }

View File

@ -73,6 +73,8 @@ public class PostmanCollectionCodegenTest {
// verify request name (from summary) // verify request name (from summary)
assertFileContains(path, "\"name\": \"Get User\""); assertFileContains(path, "\"name\": \"Get User\"");
// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
} }
@ -155,6 +157,9 @@ public class PostmanCollectionCodegenTest {
TestUtils.assertFileContains(path, TestUtils.assertFileContains(path,
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\""); "key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");
// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
} }
@Test @Test
@ -187,6 +192,9 @@ public class PostmanCollectionCodegenTest {
assertFileContains(path, "{{MY_VAR_NAME}}"); assertFileContains(path, "{{MY_VAR_NAME}}");
// verify request endpoint
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
} }
@Test @Test

View File

@ -13,7 +13,7 @@
"name": "default", "name": "default",
"item": [ "item": [
{ {
"name": "/users/{userId} (DEPRECATED)", "name": "/users/:userId (DEPRECATED)",
"description": "Update the information of an existing user.", "description": "Update the information of an existing user.",
"item": [ "item": [
{ {
@ -52,13 +52,13 @@
} }
}, },
"url": { "url": {
"raw": "{{baseUrl}}/users/{userId}", "raw": "{{baseUrl}}/users/:userId",
"host": [ "host": [
"{{baseUrl}}" "{{baseUrl}}"
], ],
"path": [ "path": [
"users", "users",
"{userId}" ":userId"
], ],
"variable": [ "variable": [
{ {
@ -81,7 +81,7 @@
"name": "advanced", "name": "advanced",
"item": [ "item": [
{ {
"name": "/groups/{groupId}", "name": "/groups/:groupId",
"description": "Get group of users", "description": "Get group of users",
"item": [ "item": [
{ {
@ -105,13 +105,13 @@
} }
}, },
"url": { "url": {
"raw": "{{baseUrl}}/groups/{groupId}", "raw": "{{baseUrl}}/groups/:groupId",
"host": [ "host": [
"{{baseUrl}}" "{{baseUrl}}"
], ],
"path": [ "path": [
"groups", "groups",
"{groupId}" ":groupId"
], ],
"variable": [ "variable": [
{ {
@ -129,7 +129,7 @@
] ]
}, },
{ {
"name": "/users/{userId}", "name": "/users/:userId",
"description": "Retrieve the information of the user with the matching user ID.", "description": "Retrieve the information of the user with the matching user ID.",
"item": [ "item": [
{ {
@ -163,13 +163,13 @@
} }
}, },
"url": { "url": {
"raw": "{{baseUrl}}/users/{userId}", "raw": "{{baseUrl}}/users/:userId",
"host": [ "host": [
"{{baseUrl}}" "{{baseUrl}}"
], ],
"path": [ "path": [
"users", "users",
"{userId}" ":userId"
], ],
"variable": [ "variable": [
{ {