dubeejw commented on a change in pull request #2966: WIP: Path parameter 
support for API GW
URL: 
https://github.com/apache/incubator-openwhisk/pull/2966#discussion_r162446019
 
 

 ##########
 File path: tests/src/test/scala/whisk/core/cli/test/ApiGwRestTests.scala
 ##########
 @@ -245,4 +247,73 @@ class ApiGwRestTests extends ApiGwTests {
     rr.stderr should include("A valid auth key is required")
   }
 
+  def getSwaggerApiUrl(rr: RunResult): String = {
+    val apiResultRest = rr.asInstanceOf[RestResult]
+    return apiResultRest.getField("gwApiUrl") + "/path"
+  }
+
+  def getParametersFromJson(rr: RunResult, pathName: String): Vector[JsObject] 
= {
+    val apiResult = rr.asInstanceOf[RestResult]
+    val apidoc = apiResult.getFieldJsObject("apidoc")
+    val paths = RestResult.getFieldJsObject(apidoc, "paths")
+    val path = RestResult.getFieldJsObject(paths, pathName)
+    val get = RestResult.getFieldJsObject(path, "get")
+    RestResult.getFieldListJsObject(get, "parameters")
+  }
+
+  behavior of "Wsk rest api creation with path parameters with swagger"
+
+  it should "create the API when swagger file contains path parameters" in 
withAssetCleaner(wskprops) {
+    (wp, assetHelper) =>
+      println("**8****** apihost:")
+      println(wskprops.apihost)
+      val actionName = "cli_apigwtest_path_param_swagger_action"
+      var exception: Throwable = null
+      val apiName = "/guest/v1"
+      val reqPath = "\\$\\(request.path\\)"
+      val testRelPath = "/api2/greeting2/{name}"
+      val testRelPathGet = "/api2/greeting2/name"
+      val hostRegex = "%HOST%".r
+      val namespaceRegex = "%NAMESPACE%".r
+      var file = TestUtils.getTestActionFilename(s"echo-web-http.js")
+      assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { 
(action, _) =>
+        action.create(actionName, Some(file), web = Some("true"))
+      }
+      try {
+        val apiGwURL = "https://"; + wskprops.apihost
+        file = 
TestUtils.getTestApiGwFilename("apigw_path_param_support_test_withPathParameters1.json")
+        var replacements = Map(hostRegex -> apiGwURL, namespaceRegex -> 
"guest")
+        file = replaceStringInFile(file, replacements)
+        var rr = apiCreate(swagger = Some(file), expectedExitCode = 
SUCCESS_EXIT)
+        val apiResult = rr.asInstanceOf[RestResult]
+        val url = apiResult.getField("gwApiUrl") 
//RestResult.getField(apiResult, "gwApiUrl")
+        val params = getParametersFromJson(rr, testRelPath) 
//RestResult.getFieldListJsObject(get, "parameters")
+        println("url: " + url)
+        params.size should be(1)
+        RestResult.getField(params(0), "name") should be("name")
+        RestResult.getField(params(0), "in") should be("path")
+        RestResult.getFieldJsValue(params(0), "required").toString() should 
be("true")
+        RestResult.getField(params(0), "type") should be("string")
+        rr = wsk.api.get(basepathOrApiName = Some(apiName), cliCfgFile = 
Some(cliWskPropsFile.getCanonicalPath()))
+        val apiToInvoke = s"$url$testRelPathGet"
+        println(s"Invoking: '${apiToInvoke}'")
+//        val response = whisk.utils.retry({
 
 Review comment:
   If this retry code isn't needed, can we delete it?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to