Fix swagger config file support

Improved API GW CLI error reporting
- Include API GW error message in CLI error instead of jsut the HTTP status code

Include API creation via swagger in the API GW end-to-end health check
diff --git a/tests/src/apigw/healthtests/ApiGwEndToEndTests.scala b/tests/src/apigw/healthtests/ApiGwEndToEndTests.scala
index 56018f0..b401a24 100644
--- a/tests/src/apigw/healthtests/ApiGwEndToEndTests.scala
+++ b/tests/src/apigw/healthtests/ApiGwEndToEndTests.scala
@@ -16,6 +16,9 @@
 
 package apigw.healthtests
 
+import java.io.BufferedWriter
+import java.io.File
+import java.io.FileWriter
 import org.junit.runner.RunWith
 import org.scalatest.FlatSpec
 import org.scalatest.Matchers
@@ -64,7 +67,7 @@
             wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT)
 
             // Create the API
-            var rr = wsk.api.create(basepath = Some(testbasepath), relpath = testrelpath, operation = testurlop, action = actionName, apiname = Some(testapiname))
+            var rr = wsk.api.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
             rr.stdout should include("ok: created API")
             val apiurl = rr.stdout.split("\n")(1)
             println(s"apiurl: '${apiurl}'")
@@ -79,6 +82,23 @@
             rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
             rr.stdout should include(testbasepath + testrelpath)
 
+            // Recreate the API using a JSON swagger file
+            rr = wsk.api.get(basepathOrApiName = Some(testbasepath))
+            val swaggerfile = File.createTempFile("api", ".json")
+            swaggerfile.deleteOnExit()
+            val bw = new BufferedWriter(new FileWriter(swaggerfile))
+            bw.write(rr.stdout)
+            bw.close()
+
+            // Delete API to that it can be recreated again using the generated swagger file
+            val deleteApiResult = wsk.api.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
+
+            // Create the API again, but use the swagger file this time
+            rr = wsk.api.create(swagger = Some(swaggerfile.getAbsolutePath()))
+            rr.stdout should include("ok: created API")
+            val swaggerapiurl = rr.stdout.split("\n")(1)
+            println(s"apiurl: '${swaggerapiurl}'")
+
             // Call the API URL and validate the results
             val response = RestAssured.given().config(sslconfig).get(s"$apiurl?$urlqueryparam=$urlqueryvalue")
             response.statusCode should be(200)
@@ -88,9 +108,9 @@
         }
         finally {
             println("Deleting action: "+actionName)
-            val deleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
+            val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
             println("Deleting API: "+testbasepath)
-            val deleteApiResult = wsk.api.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
+            val finallydeleteApiResult = wsk.api.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
         }
     }
 }
diff --git a/tests/src/common/Wsk.scala b/tests/src/common/Wsk.scala
index 8448ee5..5273e80 100644
--- a/tests/src/common/Wsk.scala
+++ b/tests/src/common/Wsk.scala
@@ -755,15 +755,19 @@
       * if the code is anything but DONTCARE_EXIT, assert the code is as expected
       */
     def create(
-        basepath: Option[String] = Some("/"),
-        relpath: String,
-        operation: String,
-        action: String,
+        basepath: Option[String] = None,
+        relpath: Option[String] = None,
+        operation: Option[String] = None,
+        action: Option[String] = None,
         apiname: Option[String] = None,
         swagger: Option[String] = None,
         expectedExitCode: Int = SUCCESS_EXIT)(
             implicit wp: WskProps): RunResult = {
-        val params = Seq(noun, "create", "--auth", wp.authKey, basepath.get, relpath, operation, action) ++
+        val params = Seq(noun, "create", "--auth", wp.authKey) ++
+          { basepath map { b => Seq(b) } getOrElse Seq() } ++
+          { relpath map { r => Seq(r) } getOrElse Seq() } ++
+          { operation map { o => Seq(o) } getOrElse Seq() } ++
+          { action map { aa => Seq(aa) } getOrElse Seq() } ++
           { apiname map { a => Seq("--apiname", a) } getOrElse Seq() } ++
           { swagger map { s => Seq("--config-file", s) } getOrElse Seq() }
         cli(wp.overrides ++ params, expectedExitCode, showCmd = true)
diff --git a/tests/src/whisk/core/cli/test/ApiGwTests.scala b/tests/src/whisk/core/cli/test/ApiGwTests.scala
index 819d9a4..4fd1041 100644
--- a/tests/src/whisk/core/cli/test/ApiGwTests.scala
+++ b/tests/src/whisk/core/cli/test/ApiGwTests.scala
@@ -42,7 +42,7 @@
     it should "reject an api commands with an invalid path parameter" in {
         val badpath = "badpath"
 
-        var rr = wsk.api.create(basepath = Some("/basepath"), relpath = badpath, operation = "GET", action = "action", expectedExitCode = ANY_ERROR_EXIT)
+        var rr = wsk.api.create(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
         rr.stderr should include (s"'${badpath}' must begin with '/'")
 
         rr = wsk.api.delete(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
@@ -68,7 +68,7 @@
         try {
             println("cli user: "+cliuser+"; cli namespace: "+clinamespace)
 
-            var rr = wsk.api.create(basepath = Some(testbasepath), relpath = testrelpath, operation = testurlop, action = actionName, apiname = Some(testapiname))
+            var rr = wsk.api.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
             rr.stdout should include("ok: created API")
             rr = wsk.api.list(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
             rr.stdout should include("ok: APIs")