spring-cloud / spring-cloud-open-service-broker

Spring Cloud project for creating service brokers that conform to the Open Server Broker API specification
https://spring.io/projects/spring-cloud-open-service-broker
Apache License 2.0
168 stars 118 forks source link

config for catalog json schema does not support arrays (e.g. enums) #161

Closed gberche-orange closed 5 years ago

gberche-orange commented 5 years ago

When json schema need to express arrays, such as the following example with an enum, see example, the SCOSB config does not properly detect the array

spring:
 cloud:
   openservicebroker:
      catalog:
        services:
        - id: noop-ondemand-service
          name: noop-ondemand
          description: "On demand noop dedicated cluster"
          bindable: true
          displayName: ondemand noop
          plans:
            - id: noop-ondemand-plan-2
              name: mysql-sample
              description: mysql sample schema
              free: false
              schemas:
                serviceinstance:
                  create:
                    parameters[$schema]: "http://json-schema.org/draft-04/schema#"
                    parameters:
                      type: object
                      properties:
                        character_set_server:
                          description: Default character set. Note that while the MariaDB default is latin1,
                            we default to utf8.
                          type: string
                          default: utf8
                          enum:
                          - utf8
                          - latin1
                          - latin2
                          - ascii

The resulting served payload by SCOSB in /v2/catalog subset for the enum is

[...]
                    "character_set_server": {
                      "description": "Default character set. Note that while the MariaDB default is latin1, we default to utf8.",
                      "type": "string",
                      "default": "utf8",
                      "enum": {
                        "0": "utf8",
                        "1": "latin1",
                        "2": "latin2",
                        "3": "ascii"
                      }
                    },

As a result, the registration of the broker in cloudfoundry fails with the following message

Server error, status code: 502, error code: 270012, message: Service broker catalog is invalid: 
Service noop-ondemand
  Plan mysql-sample
    Schemas
      Schema service_instance.create.parameters is not valid. Must conform to JSON Schema Draft 04 (experimental support for later versions): The property '#/properties/character_set_server/enum' of type object did not match the following type: array in schema http://json-schema.org/draft-04/schema#

The root cause seems spring boot configuration binding which does not properly infer arrays expressed in properties, unless corresponding configuration classes are defined.

This is similar to #155

However, unlike for #155 which required configuration classes for few cloudfoundry profile metadata fields, the syntax for Json schema is much more complex and would require quite a bit of work to model through configuration classes.

/CC @ldangeard-orange

royclarkson commented 5 years ago

Closed in badfebf08eae017d3acc5d68680eca7083e90ed6