cloud-service-broker icon indicating copy to clipboard operation
cloud-service-broker copied to clipboard

[FR] Extend support for Json Schema

Open gberche-orange opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe.

  • As a brokerpack author
  • in order to propose generated forms to my users for parameters of type array
  • I need more complete support of JsonSchema syntax than the current on in CSB 0.2.1

Describe the solution you'd like

The Json schema for array (see https://json-schema.org/understanding-json-schema/reference/array.html#list-validation ) requires support for the items element

{
  "type": "array",
  "items": {
    "type": "number"
  }
}

Without this element, OSB client form generator such as https://github.com/cloudfoundry/stratos don't generate the entry for the parameter of type array

details of rendering without `items` keyword

Json schema generated by CSB, which is missing the itemselement

{
    "$schema": "http://json-schema.org/draft-04/schema#",
                                    "properties": {
                                        "endpoints": {
                                            "description": "The endpoints of all app instances",
                                            "title": "Endpoints",
                                            "type": "array"
                                        },
                                        "healthcheck_uri": {
                                            "default": "/",
                                            "description": "The healthcheck endpoint",
                                            "title": "Healthcheck URI",
                                            "type": "string"
                                        },
                                        "method": {
                                            "default": "GET",
                                            "description": "The HTTP method",
                                            "enum": [
                                                "GET",
                                                "HEAD",
                                                "POST",
                                                "PUT"
                                            ],
                                            "title": "Method",
                                            "type": "string"
                                        },
                                        "port": {
                                            "default": 443,
                                            "description": "The TCP port",
                                            "maximum": 65535,
                                            "minimum": 1,
                                            "title": "Port",
                                            "type": "number"
                                        },
                                        "scheme": {
                                            "default": "https",
                                            "description": "The scheme",
                                            "enum": [
                                                "http",
                                                "https"
                                            ],
                                            "title": "Scheme",
                                            "type": "string"
                                        },
                                        "tags": {
                                            "default": [],
                                            "description": "The tags",
                                            "title": "Tags",
                                            "type": "array"
                                        },
                                        "type": {
                                            "default": "http",
                                            "description": "The service type (http or tcp)",
                                            "enum": [
                                                "http",
                                                "tcp"
                                            ],
                                            "title": "Type",
                                            "type": "string"
                                        }
                                    }
}

Rendering without items json schema element image

Rendering with items json schema element (note the yellow button to add new array entries) image

Json schema fragment with items

                                       "endpoints": {
                                            "description": "The endpoints of all app instances",
                                            "title": "Endpoints",
                                            "type": "array",
                                            "items": { "type":"string"}
                                        },

See https://hamidihamza.com/ajsf/?set=ng-jsf&example=ng-jsf-nested-arrays&framework=material-design&language=en for live demo of Json schema form generation

Describe alternatives you've considered

  • add just support for items constraint element
  • modify CSB to blindly include any constraint element without validation
  • add alternative CSB support for providing full Json schema (i.e. independently of input variables and constraints)

Additional Context

Currently adding a constraint with the following produces no error message at build or serving, but the served v2/catalog does not include the items element in the JSON Schema.

provision:
  plan_inputs: [ ]
  user_inputs:
    - required: true
      field_name: endpoints
      type: array
      details: The endpoints of all app instances
      constraints:
        items:
          type: string

Fails at catalog serving with output:

{"timestamp":"1611160181.886161089","source":"cloud-service-broker","message":"cloud-service-broker.encoding response","log_level":2,"data":{"data_dump":"lager.Data{\"error\":\"json: unsupported type: map[interface {}]interface {}\", \"r
esponse\":brokerapi.CatalogResponse{Services:[]brokerapi.Service{brokerapi.Service{ID:\"357f0f4f-c905-46b8-b4ee-dfc559537c03\", Name:\"global-server-load-balancer\", Description:\"Global Server Load Balancing\", Bindable:true, InstancesR
etrievable:false, BindingsRetrievable:false, Tags:[]string{\"gslb\", \"gtm\", \"load-balancer\", \"dns\"}, PlanUpdatable:true, Plans:[]brokerapi.ServicePlan{brokerapi.ServicePlan{ID:\"50d8f38b-37d3-47b7-a4aa-0830eb3bb34d\", Name:\"standa
rd\", Description:\"Standard HA Plan\", Free:(*bool)(0xc000597680), Bindable:(*bool)(nil), Metadata:(*brokerapi.ServicePlanMetadata)(0xc0001eddb0), Schemas:(*brokerapi.ServiceSchemas)(0xc00059cde0), MaintenanceInfo:(*brokerapi.Maintenanc
eInfo)(nil)}}, Requires:[]brokerapi.RequiredPermission(nil), Metadata:(*brokerapi.ServiceMetadata)(0xc0001916c0), DashboardClient:(*brokerapi.ServiceDashboardClient)(nil)}}}, \"status\":200}","lager serialisation error":"json: unsupporte
d type: map[interface {}]interface {}"}}

Priority

Priority Context

Platform

Applicable Services

gberche-orange avatar Jan 20 '21 14:01 gberche-orange

Thank you for your PR in support of this feature @gberche-orange!

This is not currently prioritized by the CSB team, so I have marked it as "help-wanted."

We will follow up if anything changes 💯

omerbensaadon avatar Jan 25 '21 20:01 omerbensaadon

Hi @gberche-orange, is this something you still want? We don't still have bandwidth to tackle this request and it has been open for contributions for a long time now. Would you be able to submit a PR?

pivotal-marcela-campo avatar Mar 30 '22 13:03 pivotal-marcela-campo