forked from loafle/openapi-generator-original
[Postman Collection] Fix path parameter syntax (#16827)
* Format Postman request url * Generate schema
This commit is contained in:
parent
3bc4f67333
commit
b4f9d8103f
@ -217,9 +217,12 @@ public class PostmanCollectionCodegen extends DefaultCodegen implements CodegenC
|
||||
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
|
||||
@ -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) {
|
||||
return ref.substring(ref.lastIndexOf("/") + 1);
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ public class PostmanCollectionCodegenTest {
|
||||
|
||||
// verify request name (from summary)
|
||||
assertFileContains(path, "\"name\": \"Get User\"");
|
||||
// verify request endpoint
|
||||
TestUtils.assertFileContains(path, "\"name\": \"/users/:userId\"");
|
||||
|
||||
}
|
||||
|
||||
@ -155,6 +157,9 @@ public class PostmanCollectionCodegenTest {
|
||||
TestUtils.assertFileContains(path,
|
||||
"key\": \"groupId\", \"value\": \"1\", \"type\": \"number\"");
|
||||
|
||||
// verify request endpoint
|
||||
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -187,6 +192,9 @@ public class PostmanCollectionCodegenTest {
|
||||
|
||||
assertFileContains(path, "{{MY_VAR_NAME}}");
|
||||
|
||||
// verify request endpoint
|
||||
TestUtils.assertFileContains(path, "\"name\": \"/users/{{userId}}\"");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -13,7 +13,7 @@
|
||||
"name": "default",
|
||||
"item": [
|
||||
{
|
||||
"name": "/users/{userId} (DEPRECATED)",
|
||||
"name": "/users/:userId (DEPRECATED)",
|
||||
"description": "Update the information of an existing user.",
|
||||
"item": [
|
||||
{
|
||||
@ -52,13 +52,13 @@
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/{userId}",
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
"{userId}"
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
@ -81,7 +81,7 @@
|
||||
"name": "advanced",
|
||||
"item": [
|
||||
{
|
||||
"name": "/groups/{groupId}",
|
||||
"name": "/groups/:groupId",
|
||||
"description": "Get group of users",
|
||||
"item": [
|
||||
{
|
||||
@ -105,13 +105,13 @@
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/groups/{groupId}",
|
||||
"raw": "{{baseUrl}}/groups/:groupId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"groups",
|
||||
"{groupId}"
|
||||
":groupId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
@ -129,7 +129,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "/users/{userId}",
|
||||
"name": "/users/:userId",
|
||||
"description": "Retrieve the information of the user with the matching user ID.",
|
||||
"item": [
|
||||
{
|
||||
@ -163,13 +163,13 @@
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/users/{userId}",
|
||||
"raw": "{{baseUrl}}/users/:userId",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"users",
|
||||
"{userId}"
|
||||
":userId"
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user