func getManagedUrl(api *whisk.RetApi, relpath string, operation string) (url string) {
	baseUrl := strings.TrimSuffix(api.BaseUrl, "/")
	whisk.Debug(whisk.DbgInfo, "getManagedUrl: baseUrl = '%s', relpath = '%s', operation = '%s'\n", baseUrl, relpath, operation)
	for path := range api.Swagger.Paths {
		whisk.Debug(whisk.DbgInfo, "getManagedUrl: comparing api relpath: '%s'\n", path)
		if path == relpath {
			whisk.Debug(whisk.DbgInfo, "getManagedUrl: relpath matches '%s'\n", relpath)
			for op := range api.Swagger.Paths[path].MakeOperationMap() {
				whisk.Debug(whisk.DbgInfo, "getManagedUrl: comparing operation: '%s'\n", op)
				if strings.ToLower(op) == strings.ToLower(operation) {
					whisk.Debug(whisk.DbgInfo, "getManagedUrl: operation matches: '%s'\n", operation)
					url = baseUrl + path
				}
			}
		}
	}
	return url
}
/*
Pull the managedUrl (external API URL) from the API configuration
package commands
import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"reflect"
	"strconv"
	"strings"
	"github.com/apache/openwhisk-cli/wski18n"
	"github.com/apache/openwhisk-client-go/whisk"
	"encoding/json"
	"github.com/fatih/color"
	"github.com/ghodss/yaml"
	"github.com/spf13/cobra"
	"regexp"
)
const (
	yamlFileExtension = "yaml"
	ymlFileExtension  = "yml"
	formatOptionYaml = "yaml"
	formatOptionJson = "json"
	pathParamRegex        = `\/\{([^\/]+)\}\/|\/\{([^\/]+)\}$|\{([^\/]+)}\/`
	pathSegmentParamRegex = `^\/\{([^\/]+)\}\/$`
)
var apiCmd = &cobra.Command{
	Use:   "api",
	Short: wski18n.T("work with APIs"),
}
var fmtString = "%-30s %7s %20s  %s\n"
var ContextId string
var ApiGwAccessToken string
func IsValidApiVerb(verb string) (error, bool) {
	if _, ok := whisk.ApiVerbs[strings.ToUpper(verb)]; !ok {
		whisk.Debug(whisk.DbgError, "Invalid API verb: '%s'\n", verb)
		errMsg := wski18n.T("'{{.verb}}' is not a valid API verb.  Valid values are: {{.verbs}}",
			map[string]interface{}{
				"verb":  verb,
				"verbs": reflect.ValueOf(whisk.ApiVerbs).MapKeys()})
		whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
			whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
		return whiskErr, false
	}
	return nil, true
}
func hasPathPrefix(path string) (error, bool) {
	if !strings.HasPrefix(path, "/") {
		whisk.Debug(whisk.DbgError, "path does not begin with '/': '%s'\n", path)
		errMsg := wski18n.T("'{{.path}}' must begin with '/'.",
			map[string]interface{}{
				"path": path,
			})
		whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
			whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
		return whiskErr, false
	}
	return nil, true
}
func isValidBasepath(basepath string) (error, bool) {
	if whiskerr, ok := hasPathPrefix(basepath); !ok {
		return whiskerr, false
	}
	return nil, true
}
func isValidRelpath(relpath string) (error, bool) {
	if whiskerr, ok := hasPathPrefix(relpath); !ok {
		return whiskerr, false
	}
	return nil, true
}
func getPathParameterNames(path string) ([]string, error) {
	var pathParameters []string
	regexObj, err := regexp.Compile(pathSegmentParamRegex)
	if err != nil {
		whisk.Debug(whisk.DbgError, "Failed to match path '%s' to regular expressions `%s`\n", path, pathSegmentParamRegex)
	} else {
		segments := strings.Split(path, "/")
		for _, segment := range segments {
			segment = fmt.Sprintf("/%s/", segment)
			matchedItems := regexObj.FindAllStringSubmatch(segment, -1)
			for _, matchedParam := range matchedItems {
				for idx, paramName := range matchedParam {
					whisk.Debug(whisk.DbgInfo, "Path parameter submatch '%v'; idx %v\n", paramName, idx)
					if idx > 0 && len(paramName) > 0 {
						pathParameters = append(pathParameters, paramName)
					}
				}
			}
		}
	}
	return pathParameters, err
}
func hasPathParameters(path string) (bool, error) {
	pathParams, err := getPathParameterNames(path)
	return len(pathParams) > 0, err
}
func isBasepathParameterized(basepath string) (error, bool) {
	hasParams, err := hasPathParameters(basepath)
	if hasParams || err != nil {
		errMsg := wski18n.T("The base path '{{.path}}' cannot have parameters. Only the relative path supports path parameters.",
			map[string]interface{}{"path": basepath})
		whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
			whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
		return whiskErr, false
	}
	return nil, true
}