diff --git a/pkg/brokerapi/schemas.go b/pkg/brokerapi/schemas.go index a026ca4e1f0a..df1746d80b14 100644 --- a/pkg/brokerapi/schemas.go +++ b/pkg/brokerapi/schemas.go @@ -19,13 +19,25 @@ package brokerapi // Schemas represents a plan's schemas for service instance and binding create // and update. type Schemas struct { - ServiceInstances *Schema `json:"service_instances,omitempty"` - ServiceBindings *Schema `json:"service_bindings,omitempty"` + ServiceInstances *ServiceInstanceSchema `json:"service_instance,omitempty"` + ServiceBindings *ServiceBindingSchema `json:"service_binding,omitempty"` } -// Schema represents a plan's schemas for a create and update of an API -// resource. -type Schema struct { - Create interface{} `json:"create,omitempty"` - Update interface{} `json:"update,omitempty"` +// ServiceInstanceSchema represents a plan's schemas for a create and update +// of a service instance. +type ServiceInstanceSchema struct { + Create *InputParameters `json:"create,omitempty"` + Update *InputParameters `json:"update,omitempty"` +} + +// ServiceBindingSchema represents a plan's schemas for the parameters +// accepted for binding creation. +type ServiceBindingSchema struct { + Create *InputParameters `json:"create,omitempty"` +} + +// InputParameters represents a schema for input parameters for creation or +// update of an API resource. +type InputParameters struct { + Parameters interface{} `json:"parameters,omitempty"` } diff --git a/pkg/brokerapi/service_plan.go b/pkg/brokerapi/service_plan.go index cc8fb3ef4d82..8eafb9e741b7 100644 --- a/pkg/brokerapi/service_plan.go +++ b/pkg/brokerapi/service_plan.go @@ -24,6 +24,6 @@ type ServicePlan struct { Description string `json:"description"` Metadata interface{} `json:"metadata,omitempty"` Free bool `json:"free,omitempty"` - Schemas *Schemas `json:"schemas,omitempty"` Bindable *bool `json:"bindable,omitempty"` + Schemas *Schemas `json:"schemas,omitempty"` } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index faae5da89a6f..d023c2267f96 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -432,19 +432,19 @@ func convertServicePlans(plans []brokerapi.ServicePlan) ([]v1alpha1.ServicePlan, if schemas := plans[i].Schemas; schemas != nil { if instanceSchemas := schemas.ServiceInstances; instanceSchemas != nil { - if instanceCreateSchema := instanceSchemas.Create; instanceCreateSchema != nil { - schema, err := json.Marshal(instanceCreateSchema) + if instanceCreateSchema := instanceSchemas.Create; instanceCreateSchema != nil && instanceCreateSchema.Parameters != nil { + schema, err := json.Marshal(instanceCreateSchema.Parameters) if err != nil { - err = fmt.Errorf("Failed to marshal instance create schema \n%+v\n %v", instanceCreateSchema, err) + err = fmt.Errorf("Failed to marshal instance create schema \n%+v\n %v", instanceCreateSchema.Parameters, err) glog.Error(err) return nil, err } ret[i].AlphaInstanceCreateParameterSchema = &runtime.RawExtension{Raw: schema} } - if instanceUpdateSchema := instanceSchemas.Update; instanceUpdateSchema != nil { - schema, err := json.Marshal(instanceUpdateSchema) + if instanceUpdateSchema := instanceSchemas.Update; instanceUpdateSchema != nil && instanceUpdateSchema.Parameters != nil { + schema, err := json.Marshal(instanceUpdateSchema.Parameters) if err != nil { - err = fmt.Errorf("Failed to marshal instance update schema \n%+v\n %v", instanceUpdateSchema, err) + err = fmt.Errorf("Failed to marshal instance update schema \n%+v\n %v", instanceUpdateSchema.Parameters, err) glog.Error(err) return nil, err } @@ -452,10 +452,10 @@ func convertServicePlans(plans []brokerapi.ServicePlan) ([]v1alpha1.ServicePlan, } } if bindingSchemas := schemas.ServiceBindings; bindingSchemas != nil { - if bindingCreateSchema := bindingSchemas.Create; bindingCreateSchema != nil { - schema, err := json.Marshal(bindingCreateSchema) + if bindingCreateSchema := bindingSchemas.Create; bindingCreateSchema != nil && bindingCreateSchema.Parameters != nil { + schema, err := json.Marshal(bindingCreateSchema.Parameters) if err != nil { - err = fmt.Errorf("Failed to marshal binding create schema \n%+v\n %v", bindingCreateSchema, err) + err = fmt.Errorf("Failed to marshal binding create schema \n%+v\n %v", bindingCreateSchema.Parameters, err) glog.Error(err) return nil, err } diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index b2fb579b83f5..2f2f2c2554ba 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -460,17 +460,23 @@ const alphaParameterSchemaCatalogBytes = `{ "d": "e" }, "schemas": { - "service_instances": { + "service_instance": { "create": { - "foo": "bar" + "parameters": { + "foo": "bar" + } }, "update": { - "baz": "zap" + "parameters": { + "baz": "zap" + } } }, - "service_bindings": { + "service_binding": { "create": { - "zoo": "blu" + "parameters": { + "zoo": "blu" + } } } }