Skip to content

Commit

Permalink
use Postman notation for path parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Nov 14, 2023
1 parent f74b3d7 commit b1aeedf
Showing 1 changed file with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,28 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo

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);
// ad-hoc customisation for specific path parameters:
// companyId: set value as YOUR_COMPANY_ACCOUNT env variable
// merchantId: set value as YOUR_MERCHANT_ACCOUNT env variable
if(codegenOperation.path.contains(":companyId") || codegenOperation.path.contains(":merchantId")) {
for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
if(codegenParameter.paramName.equalsIgnoreCase("companyId")) {
// set default value for `companyId` path parameter
codegenParameter.defaultValue = "{{YOUR_COMPANY_ACCOUNT}}";
}
if(codegenParameter.paramName.equalsIgnoreCase("merchantId")) {
// set default value for `merchantId` path parameter
codegenParameter.defaultValue = "{{YOUR_MERCHANT_ACCOUNT}}";
}
// set value of path parameter with corresponding env variable
for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
codegenParameter.defaultValue = "{{" + codegenParameter.paramName + "}}";
}
}

// ad-hoc customisation for specific path parameters:
// companyId: set value as YOUR_COMPANY_ACCOUNT env variable
// merchantId: set value as YOUR_MERCHANT_ACCOUNT env variable
if(codegenOperation.path.contains(":companyId") || codegenOperation.path.contains(":merchantId")) {
for(CodegenParameter codegenParameter : codegenOperation.pathParams) {
if(codegenParameter.paramName.equalsIgnoreCase("companyId")) {
// set default value for `companyId` path parameter
codegenParameter.defaultValue = "{{YOUR_COMPANY_ACCOUNT}}";
}
if(codegenParameter.paramName.equalsIgnoreCase("merchantId")) {
// set default value for `merchantId` path parameter
codegenParameter.defaultValue = "{{YOUR_MERCHANT_ACCOUNT}}";
}
}
}
Expand Down Expand Up @@ -496,17 +499,6 @@ public String escapeQuotationMark(String input) {
return input.replace("\"", "\\\"");
}

String doubleCurlyBraces(String str) {

// remove doublebraces first
String s = str.replace("{{", "{").replace("}}", "}");
// change all singlebraces to doublebraces
s = s.replace("{", "{{").replace("}", "}}");

return s;

}

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

Expand Down

0 comments on commit b1aeedf

Please sign in to comment.