Skip to content

Commit

Permalink
Merge pull request #61 from gcatanese/mgmt-api-env-variables
Browse files Browse the repository at this point in the history
Management API: use env variables for specific path parameters
  • Loading branch information
gcatanese authored Nov 14, 2023
2 parents 2eaf3a8 + d4f9504 commit f74b3d7
Show file tree
Hide file tree
Showing 5 changed files with 28,676 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@

</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
} 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}}";
}
}
}
}

codegenOperation.summary = getSummary(codegenOperation);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/postman-v2/item.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{{#pathParams}}
{
"key": "{{paramName}}",
"value": "",
"value": "{{defaultValue}}",
"description": "{{description}}"
}{{^-last}},{{/-last}}
{{/pathParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,39 @@ public void testAddToMapUsingDefaultTag() {
assertEquals(1, postmanV2Generator.codegenOperationsByTag.size());
assertEquals(true, postmanV2Generator.codegenOperationsByTag.containsKey("default"));
}

// test special handling of `merchantId` and `companyId` path parameters
@Test
public void testMgmtApi() throws IOException, ParseException {

File output = Files.createTempDirectory("postmantest_").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("postman-v2")
.setInputSpec("./src/test/resources/MgmtApi.json")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(configurator.toClientOptInput()).generate();

System.out.println(files);
files.forEach(File::deleteOnExit);

TestUtils.assertFileExists(Paths.get(output + "/postman.json"));

Path path = Paths.get(output + "/postman.json");
TestUtils.assertFileExists(path);

// verify merchantId default value
TestUtils.assertFileContains(path,
"key\": \"merchantId\", \"value\": \"{{YOUR_MERCHANT_ACCOUNT}}\",");
// verify companyId default value
TestUtils.assertFileContains(path,
"key\": \"companyId\", \"value\": \"{{YOUR_COMPANY_ACCOUNT}}\",");
// verify storeId default value is empty
TestUtils.assertFileContains(path,
"key\": \"storeId\", \"value\": \"\",");
}

}
Loading

0 comments on commit f74b3d7

Please sign in to comment.