func getType(paramType string) (schema.PrimitiveTypes, error) {
	switch strings.ToLower(paramType) {
	case "string", "enum":
		return []schema.PrimitiveType{schema.StringType}, nil
	case "int", "integer":
		return []schema.PrimitiveType{schema.IntegerType}, nil
	case "object":
		return []schema.PrimitiveType{schema.ObjectType}, nil
	case "array":
		return []schema.PrimitiveType{schema.ArrayType}, nil
	case "bool", "boolean":
		return []schema.PrimitiveType{schema.BooleanType}, nil
	case "number":
		return []schema.PrimitiveType{schema.NumberType}, nil
	case "nil", "null":
		return []schema.PrimitiveType{schema.NullType}, nil
	}
	return nil, fmt.Errorf("Could not find the parameter type for: %v", paramType)
}
getType transforms an apb parameter type to a JSON Schema type
package bundle
import (
	"fmt"
	"regexp"
	"strings"
	"encoding/json"
	schema "github.com/lestrrat/go-jsschema"
)
type formItem struct {
	Key   string        `json:"key,omitempty"`
	Title string        `json:"title,omitempty"`
	Type  string        `json:"type,omitempty"`
	Items []interface{} `json:"items,omitempty"`
}
func ConvertPlansToSchema(plans []Plan) ([]SchemaPlan, error) {
	brokerPlans := make([]SchemaPlan, len(plans))
	for i, plan := range plans {
		schemas, err := parametersToSchema(plan)
		if err != nil {
			return nil, err
		}
		brokerPlans[i] = SchemaPlan{
			ID:          plan.ID,
			Name:        plan.Name,
			Description: plan.Description,
			Metadata:    extractBrokerPlanMetadata(plan),
			Free:        plan.Free,
			Bindable:    plan.Bindable,
			UpdatesTo:   plan.UpdatesTo,
			Schemas:     schemas,
		}
	}
	return brokerPlans, nil
}
func planUpdatable(apbPlans []Plan) bool {
	for _, plan := range apbPlans {
		if len(plan.UpdatesTo) > 0 {
			return true
		}
	}
	return false
}
func extractBrokerPlanMetadata(apbPlan Plan) map[string]interface{} {
	metadata, err := initMetadataCopy(apbPlan.Metadata)
	if err != nil {
		return apbPlan.Metadata
	}
	instanceFormDefn := createFormDefinition(apbPlan.Parameters)
	bindingFormDefn := createFormDefinition(apbPlan.BindParameters)
	metadata["schemas"] = map[string]interface{}{
		"service_instance": map[string]interface{}{
			"create": map[string]interface{}{
				"openshift_form_definition": instanceFormDefn,
			},
			"update": map[string]interface{}{},
		},
		"service_binding": map[string]interface{}{
			"create": map[string]interface{}{
				"openshift_form_definition": bindingFormDefn,
			},
		},
	}
	return metadata
}
func initMetadataCopy(original map[string]interface{}) (map[string]interface{}, error) {
	dst := make(map[string]interface{})
	if original == nil {
		return dst, nil
	}
	bytes, err := json.Marshal(original)
	if err != nil {
		return dst, err
	}
	json.Unmarshal(bytes, &dst)
	if err != nil {
		return dst, err
	}
	return dst, nil
}
func createFormDefinition(params []ParameterDescriptor) []interface{} {
	formDefinition := make([]interface{}, 0)
	if params == nil || len(params) == 0 {
		return formDefinition
	}
	for paramIdx := 0; paramIdx < len(params); {
		var item interface{}
		var numItems int
		pd := params[paramIdx]
		if pd.DisplayGroup == "" {
			item, numItems = createUIFormItem(pd, paramIdx)
		} else {
			item, numItems = createUIFormGroup(params, pd.DisplayGroup, paramIdx)
		}
		paramIdx = paramIdx + numItems
		formDefinition = append(formDefinition, item)
	}
	return formDefinition
}
func createUIFormGroup(params []ParameterDescriptor, groupName string, paramIndex int) (formItem, int) {
	items := []interface{}{}
	for paramIndex < len(params) {
		pd := params[paramIndex]
		if pd.DisplayGroup != groupName {
			break
		}
		item, numItems := createUIFormItem(pd, paramIndex)
		items = append(items, item)
		paramIndex = paramIndex + numItems
	}
	group := formItem{
		Title: groupName,
		Type:  "fieldset",
		Items: items,
	}
	return group, len(items)
}
func createUIFormItem(pd ParameterDescriptor, paramIndex int) (interface{}, int) {
	var item interface{}
	if pd.DisplayType == "" {
		item = pd.Name
	} else {
		item = formItem{
			Key:  pd.Name,
			Type: pd.DisplayType,
		}
	}
	return item, 1
}