operations = new LinkedHashMap<>();
@JsonAnySetter
- public void setEndpoints(String key, MgwEndpointListDefinition endpoint) {
+ public void setEndpoints(String key, EndpointListDefinition endpoint) {
operations.put(key, endpoint);
}
- public MgwEndpointListDefinition getEndpointListDefinition(String resourceName) {
+ public EndpointListDefinition getEndpointListDefinition(String resourceName) {
return operations.get(resourceName);
}
}
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java
index 906b440165..357600411e 100644
--- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java
@@ -32,7 +32,7 @@
import org.wso2.apimgt.gateway.cli.utils.CodegenUtils;
import org.wso2.apimgt.gateway.cli.utils.GatewayCmdUtils;
import org.wso2.apimgt.gateway.cli.model.config.Etcd;
-import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionUtils;
+import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
@@ -167,36 +167,36 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException {
operation.getValue().setOperationId(operationId);
//if it is the developer first approach
if (isDevFirst) {
- String basePath = MgwDefinitionUtils.getBasePath(openAPI.getInfo().getTitle(),
+ String basePath = MgwDefinitionBuilder.getBasePath(openAPI.getInfo().getTitle(),
openAPI.getInfo().getVersion());
//to add resource level endpoint configuration
- MgwEndpointConfigDTO epConfig = MgwDefinitionUtils.getResourceEpConfigForCodegen(basePath,
+ MgwEndpointConfigDTO epConfig = MgwDefinitionBuilder.getResourceEpConfigForCodegen(basePath,
path.getKey(), operation.getKey());
if (epConfig != null) {
operation.getValue().setEpConfigDTO(epConfig);
}
//todo: need to validate the existence of those functions
//to add request interceptor
- String requestInterceptor = MgwDefinitionUtils.getRequestInterceptor(basePath, path.getKey(),
+ String requestInterceptor = MgwDefinitionBuilder.getRequestInterceptor(basePath, path.getKey(),
operation.getKey());
if (requestInterceptor != null) {
operation.getValue().setRequestInterceptor(requestInterceptor);
}
//to add response interceptor
- String responseInterceptor = MgwDefinitionUtils.getResponseInterceptor(basePath, path.getKey(),
+ String responseInterceptor = MgwDefinitionBuilder.getResponseInterceptor(basePath, path.getKey(),
operation.getKey());
if (responseInterceptor != null) {
operation.getValue().setResponseInterceptor(responseInterceptor);
}
//to add throttle policy
- String throttle_policy = MgwDefinitionUtils.getThrottlePolicy(basePath, path.getKey(),
+ String throttle_policy = MgwDefinitionBuilder.getThrottlePolicy(basePath, path.getKey(),
operation.getKey());
if (throttle_policy != null) {
operation.getValue().setResourceTier(throttle_policy);
}
//to add API level request interceptor
- String apiRequestInterceptor = MgwDefinitionUtils.getApiRequestInterceptor(basePath);
+ String apiRequestInterceptor = MgwDefinitionBuilder.getApiRequestInterceptor(basePath);
if (apiRequestInterceptor != null) {
//if user specify the same interceptor function in both api level and resource level ignore
// api level interceptor
@@ -206,7 +206,7 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException {
}
//to add API level response interceptor
- String apiResponseInterceptor = MgwDefinitionUtils.getApiResponseInterceptor(basePath);
+ String apiResponseInterceptor = MgwDefinitionBuilder.getApiResponseInterceptor(basePath);
if (apiResponseInterceptor != null) {
operation.getValue().setApiResponseInterceptor(apiResponseInterceptor);
}
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java
index bdd209b982..cefcb257af 100644
--- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java
@@ -39,14 +39,14 @@
import org.wso2.apimgt.gateway.cli.model.rest.ext.ExtendedAPI;
import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
@@ -678,8 +678,7 @@ public static String getDeploymentConfigLocation(String projectName) {
* @return path to the given project in the current working directory
*/
public static String getProjectDirectoryPath(String projectName) {
- // TODO: do we need to change this?
- return new File(projectName).getAbsolutePath();
+ return getUserDir() + File.separator + projectName;
}
/**
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java
similarity index 82%
rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java
rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java
index 26515d95cc..2c7b62160a 100644
--- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java
@@ -17,19 +17,18 @@
*/
package org.wso2.apimgt.gateway.cli.utils;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants;
import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException;
+import org.wso2.apimgt.gateway.cli.model.definition.DefinitionConfig;
import org.wso2.apimgt.gateway.cli.model.mgwcodegen.MgwEndpointConfigDTO;
-import org.wso2.apimgt.gateway.cli.model.mgwdefinition.MgwRootDefinition;
import org.wso2.apimgt.gateway.cli.model.rest.APICorsConfigurationDTO;
import org.wso2.apimgt.gateway.cli.model.route.EndpointListRouteDTO;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -40,26 +39,40 @@
/**
- * This class includes the Util functions related to operations on MgwDefinition.
+ * Represents the microgateway definitions file.
+ *
+ * Implementation contains the methods required to build a valid definition object model
+ * from a definition file.
+ *
*/
-public class MgwDefinitionUtils {
-
- private static final ObjectMapper OBJECT_MAPPER_YAML = new ObjectMapper(new YAMLFactory());
- private static final Logger LOGGER = LoggerFactory.getLogger(MgwDefinitionUtils.class);
- private static MgwRootDefinition rootDefinition;
+public class MgwDefinitionBuilder {
+ private static DefinitionConfig definitionConfig;
private static String projectName;
+ private static final Logger LOGGER = LoggerFactory.getLogger(MgwDefinitionBuilder.class);
private static Map requestInterceptorMap = new HashMap<>();
private static Map responseInterceptorMap = new HashMap<>();
- public static void configureMgwDefinition(String project) {
+ /**
+ * Builds the {@link DefinitionConfig} object model for {@link GatewayCliConstants#PROJECT_DEFINITION_FILE}.
+ * Before parsing the yaml file to {@link DefinitionConfig}, validation will be performed on
+ * the the input project definition file.
+ *
+ * @param project microgateway project name
+ */
+ public static void build(String project) {
projectName = project;
+ String definitionPath = GatewayCmdUtils.getProjectMgwDefinitionFilePath(project);
+ File definitionFile = new File(definitionPath);
+
try {
- String definitionFilePath = GatewayCmdUtils.getProjectMgwDefinitionFilePath(project);
- rootDefinition = OBJECT_MAPPER_YAML.readValue(new File(definitionFilePath), MgwRootDefinition.class);
+ InputStream isSchema = MgwDefinitionBuilder.class.getClassLoader()
+ .getResourceAsStream(GatewayCliConstants.DEFINITION_SCHEMA_FILE);
+ definitionConfig = YamlValidator.parse(definitionFile, isSchema, DefinitionConfig.class);
} catch (IOException e) {
throw new CLIRuntimeException("Error while reading the " + GatewayCliConstants.PROJECT_DEFINITION_FILE +
".", e);
}
+
try {
//update the interceptor map
setInterceptors();
@@ -77,37 +90,38 @@ public static void configureMgwDefinition(String project) {
* @return basePath
*/
public static String getBasePath(String apiName, String apiVersion) {
- String basePath = rootDefinition.getApis().getBasepathFromAPI(apiName, apiVersion);
+ String basePath = definitionConfig.getApis().getBasepathFromAPI(apiName, apiVersion);
if (basePath == null) {
throw new CLIRuntimeException("Error: The API '" + apiName + "' and version '" + apiVersion + "' is not " +
"found in the " + GatewayCliConstants.PROJECT_DEFINITION_FILE + ".");
}
+
return basePath;
}
public static EndpointListRouteDTO getProdEndpointList(String basePath) {
- return rootDefinition.getApis().getApiFromBasepath(basePath).getProdEpList();
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getProdEpList();
}
public static EndpointListRouteDTO getSandEndpointList(String basePath) {
- return rootDefinition.getApis().getApiFromBasepath(basePath).getProdEpList();
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getProdEpList();
}
public static String getSecurity(String basePath) {
- return rootDefinition.getApis().getApiFromBasepath(basePath).getSecurity();
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getSecurity();
}
public static APICorsConfigurationDTO getCorsConfiguration(String basePath) {
- return rootDefinition.getApis().getApiFromBasepath(basePath).getCorsConfiguration();
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getCorsConfiguration();
}
public static MgwEndpointConfigDTO getResourceEpConfigForCodegen(String basePath, String path, String operation) {
if (!isResourceAvailable(basePath, path, operation)) {
return null;
}
- EndpointListRouteDTO prodList = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().
+ EndpointListRouteDTO prodList = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().
getMgwResource(path).getEndpointListDefinition(operation).getProdEndpointList();
- EndpointListRouteDTO sandList = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().
+ EndpointListRouteDTO sandList = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().
getMgwResource(path).getEndpointListDefinition(operation).getSandEndpointList();
return RouteUtils.convertToMgwServiceMap(prodList, sandList);
}
@@ -124,9 +138,10 @@ public static String getRequestInterceptor(String basePath, String path, String
if (!isResourceAvailable(basePath, path, operation)) {
return null;
}
- String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
+ String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
getEndpointListDefinition(operation).getRequestInterceptor();
validateInterceptorAvailability(requestInterceptorMap, interceptor, basePath, path, operation);
+
return interceptor;
}
@@ -142,9 +157,10 @@ public static String getResponseInterceptor(String basePath, String path, String
if (!isResourceAvailable(basePath, path, operation)) {
return null;
}
- String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
+ String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
getEndpointListDefinition(operation).getResponseInterceptor();
validateInterceptorAvailability(responseInterceptorMap, interceptor, basePath, path, operation);
+
return interceptor;
}
@@ -152,7 +168,7 @@ public static String getThrottlePolicy(String basePath, String path, String oper
if (!isResourceAvailable(basePath, path, operation)) {
return null;
}
- return rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path).
getEndpointListDefinition(operation).getThrottlePolicy();
}
@@ -165,13 +181,13 @@ public static String getThrottlePolicy(String basePath, String path, String oper
* @return true if the resource is available
*/
private static boolean isResourceAvailable(String basePath, String path, String operation) {
- if (rootDefinition.getApis().getApiFromBasepath(basePath) == null) {
+ if (definitionConfig.getApis().getApiFromBasepath(basePath) == null) {
return false;
}
- if (rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) == null) {
+ if (definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) == null) {
return false;
}
- return rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path)
+ return definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path)
.getEndpointListDefinition(operation) != null;
}
@@ -182,7 +198,7 @@ private static boolean isResourceAvailable(String basePath, String path, String
* @return API response request function name
*/
public static String getApiRequestInterceptor(String basePath) {
- String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getRequestInterceptor();
+ String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getRequestInterceptor();
validateInterceptorAvailability(requestInterceptorMap, interceptor, basePath, null, null);
return interceptor;
}
@@ -194,7 +210,7 @@ public static String getApiRequestInterceptor(String basePath) {
* @return API response interceptor function name
*/
public static String getApiResponseInterceptor(String basePath) {
- String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getResponseInterceptor();
+ String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getResponseInterceptor();
validateInterceptorAvailability(responseInterceptorMap, interceptor, basePath, null, null);
return interceptor;
}
@@ -230,8 +246,8 @@ private static void validateInterceptorAvailability(Map intercep
/**
* To find out the api information which is not used for code generation but included in the definitions.yaml
*/
- public static void FindNotUsedAPIInformation() {
- rootDefinition.getApis().getApisMap().forEach((k, v) -> {
+ public static void FindUnusedAPIInformation() {
+ definitionConfig.getApis().getApisMap().forEach((k, v) -> {
if (!v.getIsDefinitionUsed()) {
String msg = "API '" + v.getTitle() + "' version: '" + v.getVersion() + "' is not used but " +
"added to the " + GatewayCliConstants.PROJECT_DEFINITION_FILE + ".";
@@ -340,3 +356,4 @@ private static void findResponseInterceptors(String balSrcCode, String intercept
findInterceptors(balSrcCode, interceptorFilePath, false, responseInterceptorMap);
}
}
+
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java
index 946f5f8b3f..171532f898 100644
--- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java
@@ -295,19 +295,19 @@ public static String readJson(String filePath) {
* @param api API object
*/
public static void setAdditionalConfigsDevFirst(ExtendedAPI api) {
- String basePath = MgwDefinitionUtils.getBasePath(api.getName(), api.getVersion());
+ String basePath = MgwDefinitionBuilder.getBasePath(api.getName(), api.getVersion());
MgwEndpointConfigDTO mgwEndpointConfigDTO =
- RouteUtils.convertToMgwServiceMap(MgwDefinitionUtils.getProdEndpointList(basePath),
- MgwDefinitionUtils.getSandEndpointList(basePath));
+ RouteUtils.convertToMgwServiceMap(MgwDefinitionBuilder.getProdEndpointList(basePath),
+ MgwDefinitionBuilder.getSandEndpointList(basePath));
api.setEndpointConfigRepresentation(mgwEndpointConfigDTO);
// 0th element represents the specific basepath
api.setSpecificBasepath(basePath);
- String security = MgwDefinitionUtils.getSecurity(basePath);
+ String security = MgwDefinitionBuilder.getSecurity(basePath);
if(security == null){
security = "oauth2";
}
api.setApiSecurity(security);
- api.setCorsConfiguration(MgwDefinitionUtils.getCorsConfiguration(basePath));
+ api.setCorsConfiguration(MgwDefinitionBuilder.getCorsConfiguration(basePath));
}
public static void setAdditionalConfig(ExtendedAPI api){
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java
index 7b1d5cbe5e..a4d284d2e1 100644
--- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java
@@ -18,7 +18,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.wso2.apimgt.gateway.cli.cmd.InitCmd;
import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants;
import org.wso2.apimgt.gateway.cli.exception.CLIInternalException;
@@ -31,7 +30,7 @@
* This class represents the utility functions required for library packages extraction
*/
public class ToolkitLibExtractionUtils {
- private static final Logger LOGGER = LoggerFactory.getLogger(InitCmd.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToolkitLibExtractionUtils.class);
/**
* Extracts the platform and runtime and copy related jars and balos to extracted runtime and platform.
diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java
new file mode 100644
index 0000000000..d308b31cb4
--- /dev/null
+++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.apimgt.gateway.cli.utils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.ValidationException;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * This class provides required functionality to validate a given
+ * yaml file with a given Json Schema
+ */
+public class YamlValidator {
+ private static final Logger logger = LoggerFactory.getLogger(YamlValidator.class);
+
+ /**
+ * Parse the yaml {@code file} to required DTO {@code type} using jackson library.
+ * Before parsing the input file, schema validation will be done to validate the file syntax.
+ *
+ * @param file yaml file to be parsed
+ * @param isSchema json schema definition to be used for schema validation
+ * @param type Jackson object model to parse the yaml content
+ * @param Jackson object model to parse the yaml content
+ * @return Parsed yaml file as a DTO
+ * @throws IOException when failed to read input files
+ */
+ public static T parse(File file, InputStream isSchema, Class type) throws IOException {
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ JsonNode jsonNode = mapper.readTree(file);
+
+ if (jsonNode == null) {
+ throw new IOException("Input file is invalid or empty");
+ }
+
+ JSONObject rawSchema = new JSONObject(new JSONTokener(isSchema));
+ Schema schema = SchemaLoader.load(rawSchema);
+ logger.debug("Loaded json schema");
+
+ try {
+ schema.validate(new JSONObject(jsonNode.toString()));
+ } catch (ValidationException e) {
+ handleValidationException(e, file.getName());
+ }
+
+ return mapper.readValue(file, type);
+ }
+
+ private static void handleValidationException(ValidationException ex, String fileName) {
+ StringBuilder msgBuilder = new StringBuilder();
+ List allMsg = ex.getAllMessages();
+
+ for (String msg : allMsg) {
+ msgBuilder.append('\n' + msg);
+ }
+ throw new CLIRuntimeException("Invalid file: " + fileName + '\n' + msgBuilder.toString(), 1);
+ }
+
+}
diff --git a/components/micro-gateway-cli/src/main/resources/definition-schema.json b/components/micro-gateway-cli/src/main/resources/definition-schema.json
new file mode 100644
index 0000000000..722f7b4802
--- /dev/null
+++ b/components/micro-gateway-cli/src/main/resources/definition-schema.json
@@ -0,0 +1,114 @@
+{
+ "$id": "https://raw.githubusercontent.com/wso2/product-microgateway/master/components/micro-gateway-cli/src/main/resources/definition-schema.json",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "Definition",
+ "type": "object",
+ "properties": {
+ "apis": {
+ "type": "object",
+ "patternProperties": {
+ "\/.*": {
+ "type": "object",
+ "required": ["title", "version","security"],
+ "anyOf": [
+ {
+ "required": ["production_endpoint"]
+ },
+ {
+ "required": ["sandbox_endpoint"]
+ },
+ {
+ "required": ["production_endpoint", "sandbox_endpoint"]
+ }
+ ],
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "version": {
+ "type": "string"
+ },
+ "production_endpoint": {
+ "$ref": "#/definitions/endpoint"
+ },
+ "sandbox_endpoint": {
+ "$ref": "#/definitions/endpoint"
+ },
+ "security": {
+ "type": "string",
+ "enum": ["oauth", "basic"]
+ },
+ "resources": {
+ "type": "object",
+ "patternProperties": {
+ "\/.*": {
+ "type": "object",
+ "patternProperties": {
+ "^[^\\d\\W]+$": {
+ "type": "object",
+ "anyOf": [
+ {
+ "required": ["production_endpoint"]
+ },
+ {
+ "required": ["sandbox_endpoint"]
+ },
+ {
+ "required": ["production_endpoint", "sandbox_endpoint"]
+ }
+ ],
+ "properties": {
+ "production_endpoint": {
+ "$ref": "#/definitions/endpoint"
+ },
+ "sandbox_endpoint": {
+ "$ref": "#/definitions/endpoint"
+ },
+ "throttle_policy": {
+ "type": "string"
+ },
+ "request_interceptor": {
+ "type": "string"
+ },
+ "response_interceptor": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ }
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false,
+ "definitions": {
+ "endpoint": {
+ "type": "object",
+ "required": ["urls", "type"],
+ "additionalProperties": false,
+ "properties": {
+ "urls": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "http",
+ "failover",
+ "load_balance"
+ ]
+ }
+ }
+ }
+ }
+}
diff --git a/distribution/resources/bin/micro-gw b/distribution/resources/bin/micro-gw
index 58a5c1154d..ea0f5ed1f1 100755
--- a/distribution/resources/bin/micro-gw
+++ b/distribution/resources/bin/micro-gw
@@ -30,8 +30,7 @@
# -----------------------------------------------------------------------------
#To update the CLI Class Path
-updateCLIClassPath()
-{
+function update_cli_classpath {
CLI_CLASSPATH=""
if [ -e "$BALLERINA_HOME/bre/lib/bootstrap/tools.jar" ]; then
CLI_CLASSPATH="$JAVA_HOME/lib/tools.jar"
@@ -79,8 +78,12 @@ updateCLIClassPath()
cygwin=false
os400=false
case "`uname`" in
-CYGWIN*) cygwin=true;;
-OS400*) os400=true;;
+ CYGWIN*)
+ cygwin=true
+ ;;
+ OS400*)
+ os400=true
+ ;;
esac
# resolve links - $0 may be a softlink
@@ -117,6 +120,12 @@ export PATH=$BALLERINA_HOME/bin:$PATH
MICRO_GW_PROJECT_DIR=$(pwd)
+# if JAVA_HOME is not set we're not happy
+if [ -z "$JAVA_HOME" ]; then
+ echo "You must set the JAVA_HOME variable before running Micro-Gateway Tooling."
+ exit 1
+fi
+
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
@@ -165,12 +174,6 @@ if [ ! -x "$JAVACMD" ] ; then
exit 1
fi
-# if JAVA_HOME is not set we're not happy
-if [ -z "$JAVA_HOME" ]; then
- echo "You must set the JAVA_HOME variable before running Ballerina."
- exit 1
-fi
-
# ----- Process the input command ----------------------------------------------
ALL_ARGS=()
@@ -179,7 +182,7 @@ while [[ $# -gt 0 ]]
do
key="$1"
case $key in
- --java.debug|-java.debug|java.debug)
+ --java.debug)
CMD="--java.debug"
PORT="$2"
shift # past java.debug argument
@@ -236,7 +239,7 @@ if [ "$CMD" = "--java.debug" ]; then
echo "Please start the remote debugging client to continue..."
fi
-updateCLIClassPath
+update_cli_classpath
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
@@ -283,7 +286,8 @@ if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_
BALLERINA_HOME=`cygpath --absolute --windows "$BALLERINA_HOME"`
fi
- updateCLIClassPath
+
+ update_cli_classpath
MICRO_GW_LABEL_PROJECT_DIR="$MICRO_GW_PROJECT_DIR/$CMD_PRO_NAME_VAL"
pushd $MICRO_GW_LABEL_PROJECT_DIR/gen > /dev/null
# clean the content of target folder
diff --git a/distribution/resources/bin/micro-gw.bat b/distribution/resources/bin/micro-gw.bat
index 3001421d3d..134b751604 100644
--- a/distribution/resources/bin/micro-gw.bat
+++ b/distribution/resources/bin/micro-gw.bat
@@ -44,9 +44,10 @@ REM If the current disk drive ie: `E:\` is different from the drive where this (
if %verbose%==T ( ECHO Switch to drive '%wsasDrive%' if current drive '%curDrive%' not equal to program drive '%wsasDrive%' )
if NOT "%curDrive%" == "%wsasDrive%" %wsasDrive%:
+REM if MICROGW_HOME environment variable not set then set it
if "%MICROGW_HOME%" == "" SET MICROGW_HOME=%PRGDIR%..
-REM set BALLERINA_HOME
+REM set BALLERINA_HOME
SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
if NOT EXIST %BALLERINA_HOME% SET BALLERINA_HOME="%MICROGW_HOME%\lib"
@@ -85,15 +86,13 @@ REM of arguments (up to the command line limit, anyway).
if ""%1""=="""" goto passToJar
if ""%1""==""help"" goto passToJar
if ""%1""==""build"" goto commandBuild
- if ""%1""==""-java.debug"" goto commandDebug
- if ""%1""==""java.debug"" goto commandDebug
if ""%1""==""--java.debug"" goto commandDebug
SHIFT
goto setupArgs
:usageInfo
ECHO Missing command operand
- ECHO "Usage: micro-gw [-v] ([ -l ] setup | build)"
+ ECHO "Use: micro-gw [--verbose] (init | import | build)"
goto :end
:commandBuild
@@ -105,7 +104,7 @@ goto :end
if [%project_name%] == [] ( goto :noName ) else ( goto :nameFound )
:noName
- ECHO "Project name not provided please follow the command usage patterns given below"
+ ECHO "micro-gw: main parameters are required (""), Run 'micro-gw help' for usage."
goto :usageInfo
:nameFound
@@ -121,33 +120,30 @@ goto :end
if ERRORLEVEL 1 goto :end
- :continueBuild
- goto :passToJar
- REM set ballerina home again as the platform is extracted at this point.
- SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
- SET PATH=%PATH%;%BALLERINA_HOME%\bin\
- if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME%
- pushd "%MICRO_GW_PROJECT_DIR%"
- if %verbose%==T ECHO current dir %CD%
- SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target"
- :: /s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.
- :: /q : Runs rmdir in quiet mode. Deletes directories without confirmation.
- if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q )
- call ballerina build src -o %project_name:\=%.balx --experimental --siddhiruntime
- popd
- if %verbose%==T ECHO Ballerina build completed
-
- set %* = %* --compiled
-
- REM Check for a debug param by looping through the remaining args list
- :checkDebug
- SHIFT
- if ""%1""=="""" goto passToJar
-
- if ""%1""==""-java.debug"" goto commandDebug
- if ""%1""==""java.debug"" goto commandDebug
- if ""%1""==""--java.debug"" goto commandDebug
- goto checkDebug
+ :continueBuild
+ call :passToJar
+ REM set ballerina home again as the platform is extracted at this point.
+ SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform
+ SET PATH=%PATH%;%BALLERINA_HOME%\bin\
+ if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME%
+ ECHO MICRO_GW_PROJECT_DIR: "%CURRENT_D%"
+ PUSHD "%CURRENT_D%"
+ PUSHD "%MICRO_GW_PROJECT_DIR%\gen"
+ if %verbose%==T ECHO current dir %CD%
+ SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target"
+ if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q )
+ call ballerina build src -o %project_name:\=%.balx --offline --experimental --siddhiruntime
+ POPD
+
+ if %verbose%==T ECHO Ballerina build completed
+ SET originalArgs=%originalArgs% --compiled
+
+ REM Check for a debug param by looping through the remaining args list
+ :checkDebug
+ SHIFT
+ if ""%1""=="""" goto passToJar
+ if ""%1""==""--java.debug"" goto commandDebug
+ goto checkDebug
goto :passToJar
:commandDebug
@@ -156,13 +152,13 @@ goto :passToJar
SHIFT
SET DEBUG_PORT=%1
if "%DEBUG_PORT%"=="" goto noDebugPort
- if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --debug option.
+ if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --java.debug option.
SET JAVA_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%DEBUG_PORT%
ECHO Please start the remote debugging client to continue...
goto passToJar
:noDebugPort
- ECHO Please specify the debug port after the java.debug option
+ ECHO Please specify the debug port after the --java.debug option
goto end
@@ -200,7 +196,7 @@ goto end
-Dfile.encoding=UTF8 ^
-Dtemplates.dir.path="%MICROGW_HOME%"\resources\templates ^
-Dcli.home="%MICROGW_HOME%" ^
- -Dcurrent.dir=%CURRENT_D%
+ -Dcurrent.dir="%CD%" ^
-DVERBOSE_ENABLED=%verbose%
if %verbose%==T ECHO JAVACMD = !JAVACMD!
@@ -209,6 +205,7 @@ goto end
CD %MICROGW_HOME%
"%JAVA_HOME%\bin\java" %JAVACMD% org.wso2.apimgt.gateway.cli.cmd.Main %originalArgs%
if "%ERRORLEVEL%"=="121" goto runJava
+ if ERRORLEVEL 1 goto :end
:end
goto endlocal
diff --git a/distribution/src/main/assembly/bin.xml b/distribution/src/main/assembly/bin.xml
index 263b5cf475..462c7566b6 100644
--- a/distribution/src/main/assembly/bin.xml
+++ b/distribution/src/main/assembly/bin.xml
@@ -140,6 +140,8 @@
org.wso2.am.microgw:org.wso2.micro.gateway.cli:jar
com.moandjiezana.toml:toml4j:jar
com.beust:jcommander:jar
+ org.everit.json:org.everit.json.schema:jar
+ org.json:json:jar
diff --git a/pom.xml b/pom.xml
index 887b4dd35f..cafa541d9a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -312,6 +312,11 @@
broker-launcher
${broker.version}
+
+ org.everit.json
+ org.everit.json.schema
+ ${json.schema.version}
+
@@ -423,6 +428,7 @@
scm-server
1.1.1
3.2.47
+ 1.5.0