Skip to content

Commit 9509ca8

Browse files
author
Chris Wiechmann
committed
Merge branch 'develop' into test-with-7.7-20200130
2 parents 940ad97 + 2b2c627 commit 9509ca8

16 files changed

Lines changed: 114 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Script apim.sh and apim.bat now optionally use AXWAY_APIM_CLI_HOME to setup the classpath (See issue [#100](https://github.com/Axway-API-Management-Plus/apim-cli/issues/100))
1616
- Staging support for applications, users and organizations
1717
- Support for custom properties for applications, users and organizations (See issue [#93](https://github.com/Axway-API-Management-Plus/apim-cli/issues/93))
18+
- Support to read API-Description from a local markdown See issue [#110](https://github.com/Axway-API-Management-Plus/apim-cli/issues/110))
1819

1920
### Fixed
2021
- Avoid NPE during API-Export if custom-properties config is inconsistent (See issue [#90](https://github.com/Axway-API-Management-Plus/apim-cli/issues/90))

build/pull_apim_docker_image.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/sh
22

3+
echo "CACHE_FILE_APIM: $CACHE_FILE_APIM"
4+
echo "SKIP_CACHE: $SKIP_CACHE"
5+
6+
echo "Listing $CACHE_DIR"
7+
ls -l $CACHE_DIR
8+
39
if [ -f $CACHE_FILE_APIM -a "$SKIP_CACHE" != "true" ]
410
then
511
echo "Using cached API-Manager docker image: $APIM_DOCKER_IMAGE from $CACHE_FILE_APIM"

modules/apim-adapter/src/main/java/com/axway/apim/api/API.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class API implements CustomPropertiesEntity {
8383
@APIPropertyAnnotation(isBreaking = false, writableStates = {API.STATE_UNPUBLISHED, API.STATE_PUBLISHED, API.STATE_DEPRECATED})
8484
protected String descriptionUrl = null;
8585

86+
protected String markdownLocal = null;
87+
8688
@APIPropertyAnnotation(isBreaking = true, writableStates = {API.STATE_UNPUBLISHED})
8789
@JsonSetter(nulls=Nulls.SKIP)
8890
protected List<SecurityProfile> securityProfiles = null;
@@ -380,6 +382,14 @@ public void setDescriptionUrl(String descriptionUrl) {
380382
this.descriptionUrl = descriptionUrl;
381383
}
382384

385+
public String getMarkdownLocal() {
386+
return markdownLocal;
387+
}
388+
389+
public void setMarkdownLocal(String markdownLocal) {
390+
this.markdownLocal = markdownLocal;
391+
}
392+
383393
public List<CaCert> getCaCerts() {
384394
return caCerts;
385395
}

modules/apim-adapter/src/test/resources/apimanager/runInstall.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ cd /opt && \
4747
/opt/Axway/apigateway/system/lib/ibmmq \
4848
/opt/Axway/apigateway/system/conf/sql \
4949
/opt/Axway/apigateway/system/conf/snmp \
50-
/opt/Axway/apigateway/system/conf/templates/* \
5150
/opt/Axway/apigateway/system/conf/threat-protection/SpiderLabs-owasp-modsecurity-crs-2.2.9-7-g3e6782b.zip \
5251
/opt/Axway/apigateway/system/conf/oracle-em \
5352
/opt/Axway/apigateway/system/conf/migrate \

modules/apis/src/main/java/com/axway/apim/APIExportApp.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ public static int exportAPI(String args[]) {
4949
} catch (AppException e) {
5050
LOG.error("Error " + e.getMessage());
5151
return e.getErrorCode().getCode();
52-
/*} catch (ParseException e) {
53-
LOG.error("Error " + e.getMessage());
54-
return ErrorCode.MISSING_PARAMETER.getCode();*/
5552
}
5653
APIExportApp apiExportApp = new APIExportApp();
5754
return apiExportApp.exportAPI(params);
5855
}
5956

6057
public int exportAPI(APIExportParams params) {
6158
try {
59+
params.validateRequiredParameters();
6260
deleteInstances();
6361

6462
switch(params.getOutputFormat()) {

modules/apis/src/main/java/com/axway/apim/APIImportApp.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,15 @@ public static int importAPI(String args[]) {
5454
} catch (AppException e) {
5555
LOG.error("Error " + e.getMessage());
5656
return e.getErrorCode().getCode();
57-
58-
/*} catch (ParseException e) {
59-
LOG.error("Error " + e.getMessage());
60-
return ErrorCode.MISSING_PARAMETER.getCode();*/
6157
}
6258
APIImportApp apiImportApp = new APIImportApp();
6359
return apiImportApp.importAPI(params);
6460
}
6561

6662
public int importAPI(APIImportParams params) {
6763
ErrorCodeMapper errorCodeMapper = new ErrorCodeMapper();
68-
try {
64+
try {
65+
params.validateRequiredParameters();
6966
// Clean some Singleton-Instances, as tests are running in the same JVM
7067
APIManagerAdapter.deleteInstance();
7168
ErrorState.deleteInstance();

modules/apis/src/main/java/com/axway/apim/apiimport/APIImportConfigAdapter.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.InputStreamReader;
1111
import java.io.Reader;
1212
import java.nio.charset.StandardCharsets;
13+
import java.nio.file.Files;
1314
import java.nio.file.Path;
1415
import java.nio.file.Paths;
1516
import java.security.KeyManagementException;
@@ -331,10 +332,32 @@ private void validateDescription(API apiConfig) throws AppException {
331332
if(!apiConfig.getDescriptionMarkdown().startsWith("${env.")) {
332333
throw new AppException("descriptionMarkdown must start with an environment variable", ErrorCode.CANT_READ_CONFIG_FILE);
333334
}
335+
} else if(descriptionType.equals("markdownLocal")) {
336+
if(apiConfig.getMarkdownLocal()==null) {
337+
throw new AppException("markdownLocal can't be null with descriptionType set to 'markdownLocal'", ErrorCode.CANT_READ_CONFIG_FILE);
338+
}
339+
try {
340+
File markdownFile = new File(apiConfig.getMarkdownLocal());
341+
if(!markdownFile.exists()) { // The image isn't provided with an absolute path, try to read it relative to the config file
342+
LOG.trace("Error reading markdown description file (absolute): '" + markdownFile.getCanonicalPath() + "'");
343+
String baseDir = this.apiConfigFile.getCanonicalFile().getParent();
344+
markdownFile = new File(baseDir + "/" + apiConfig.getMarkdownLocal());
345+
}
346+
if(!markdownFile.exists()) {
347+
LOG.trace("Error reading markdown description file (relative): '" + markdownFile.getCanonicalPath() + "'");
348+
throw new AppException("Error reading markdown description file: " + apiConfig.getMarkdownLocal(), ErrorCode.CANT_READ_CONFIG_FILE);
349+
}
350+
LOG.debug("Reading local markdown description file: " + markdownFile.getPath());
351+
String markdownDescription = new String(Files.readAllBytes(markdownFile.toPath()), StandardCharsets.UTF_8);
352+
apiConfig.setDescriptionManual(markdownDescription);
353+
apiConfig.setDescriptionType("manual");
354+
} catch (AppException | IOException e) {
355+
throw new AppException("Error reading markdown description file: " + apiConfig.getMarkdownLocal(), ErrorCode.CANT_READ_CONFIG_FILE, e);
356+
}
334357
} else if(descriptionType.equals("original")) {
335358
return;
336359
} else {
337-
throw new AppException("Unknown descriptionType: '"+descriptionType.equals("manual")+"'", ErrorCode.CANT_READ_CONFIG_FILE);
360+
throw new AppException("Unknown descriptionType: '"+descriptionType+"'", ErrorCode.CANT_READ_CONFIG_FILE);
338361
}
339362
}
340363

modules/apis/src/test/java/com/axway/apim/test/ImportTestAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ private void copyImagesAndCertificates(String origConfigFile, TestContext contex
255255
return;
256256
}
257257
}
258-
FileFilter filter = new WildcardFileFilter(new String[] {"*.crt", "*.jpg", "*.png", "*.pem"});
258+
FileFilter filter = new WildcardFileFilter(new String[] {"*.crt", "*.jpg", "*.png", "*.pem", "*.md"});
259259
try {
260-
LOG.info("Copy certificates and images from source: "+sourceDir+" into test-dir: '"+testDir+"'");
260+
LOG.info("Copy certificates and images from source: "+sourceDir+" into test-dir: '"+testDir+"' (Filter: \"*.crt\", \"*.jpg\", \"*.png\", \"*.pem\", \"*.md\")");
261261
FileUtils.copyDirectory(sourceDir, testDir, filter);
262262
} catch (IOException e) {
263263

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.axway.apim.test.description;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.HttpStatus;
5+
import org.testng.annotations.Test;
6+
7+
import com.axway.apim.test.ImportTestAction;
8+
import com.consol.citrus.annotations.CitrusTest;
9+
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
10+
import com.consol.citrus.functions.core.RandomNumberFunction;
11+
import com.consol.citrus.message.MessageType;
12+
13+
@Test
14+
public class LocalMarkdownDescriptionTestIT extends TestNGCitrusTestDesigner {
15+
16+
@Autowired
17+
private ImportTestAction swaggerImport;
18+
19+
@CitrusTest
20+
public void importAPIWithLocalMarkdown() {
21+
description("Import an API with a local markdown file");
22+
23+
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
24+
variable("apiPath", "/localmarkdown-api-${apiNumber}");
25+
variable("apiName", "LocalMarkDown-API-${apiNumber}");
26+
27+
echo("####### Importing API: '${apiName}' on path: '${apiPath}' #######");
28+
29+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
30+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/description/1_api_with_local_mark_down.json");
31+
createVariable("state", "unpublished");
32+
createVariable("descriptionType", "markdownLocal");
33+
createVariable("markdownLocal", "MyLocalMarkdown.md");
34+
createVariable("expectedReturnCode", "0");
35+
action(swaggerImport);
36+
37+
echo("####### Validate API: '${apiName}' has a description based on given local markdown file #######");
38+
http().client("apiManager").send().get("/proxies").name("api").header("Content-Type", "application/json");
39+
40+
http().client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
41+
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
42+
.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
43+
.validate("$.[?(@.path=='${apiPath}')].descriptionType", "manual")
44+
.validate("$.[?(@.path=='${apiPath}')].descriptionManual", "THIS IS THE API-DESCRIPTION FROM A LOCAL MARKDOWN!")
45+
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
46+
}
47+
48+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
"name": "${apiName}",
4+
"path": "${apiPath}",
5+
"state": "${state}",
6+
"version": "1.0.0",
7+
"organization": "API Development ${orgNumber}",
8+
"descriptionType": "${descriptionType}",
9+
"markdownLocal": "${markdownLocal}"
10+
}

0 commit comments

Comments
 (0)