|
|
@ -188,11 +188,11 @@ func ValidateAgainstSchema(values Values, schema Schema) error {
|
|
|
|
// GenerateSchema will create a JSON Schema (in YAML format) for the given values
|
|
|
|
// GenerateSchema will create a JSON Schema (in YAML format) for the given values
|
|
|
|
func GenerateSchema(values Values) Schema {
|
|
|
|
func GenerateSchema(values Values) Schema {
|
|
|
|
schema := Schema{
|
|
|
|
schema := Schema{
|
|
|
|
"type": "object",
|
|
|
|
gojsonschema.KEY_TYPE: gojsonschema.TYPE_OBJECT,
|
|
|
|
"title": "Values",
|
|
|
|
gojsonschema.KEY_TITLE: "Values",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(values) > 0 {
|
|
|
|
if len(values) > 0 {
|
|
|
|
schema["properties"] = parsePropertiesFromValues(values)
|
|
|
|
schema[gojsonschema.STRING_PROPERTIES] = parsePropertiesFromValues(values)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return schema
|
|
|
|
return schema
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -209,19 +209,19 @@ func parsePropertiesFromValues(values Values) map[string]map[string]interface{}
|
|
|
|
// the following types are the only types possible from unmarshalling
|
|
|
|
// the following types are the only types possible from unmarshalling
|
|
|
|
switch v := v.(type) {
|
|
|
|
switch v := v.(type) {
|
|
|
|
case bool:
|
|
|
|
case bool:
|
|
|
|
properties[k]["type"] = "bool"
|
|
|
|
properties[k][gojsonschema.KEY_TYPE] = gojsonschema.TYPE_BOOLEAN
|
|
|
|
case float64:
|
|
|
|
case float64:
|
|
|
|
properties[k]["type"] = "number"
|
|
|
|
properties[k][gojsonschema.KEY_TYPE] = gojsonschema.TYPE_NUMBER
|
|
|
|
case string:
|
|
|
|
case string:
|
|
|
|
properties[k]["type"] = "string"
|
|
|
|
properties[k][gojsonschema.KEY_TYPE] = gojsonschema.TYPE_STRING
|
|
|
|
case []interface{}:
|
|
|
|
case []interface{}:
|
|
|
|
properties[k]["type"] = "array"
|
|
|
|
properties[k][gojsonschema.KEY_TYPE] = gojsonschema.TYPE_ARRAY
|
|
|
|
properties[k]["items"] = parseItemsFromValues(v)
|
|
|
|
properties[k][gojsonschema.KEY_ITEMS] = parseItemsFromValues(v)
|
|
|
|
case map[string]interface{}:
|
|
|
|
case map[string]interface{}:
|
|
|
|
properties[k]["type"] = "object"
|
|
|
|
properties[k][gojsonschema.KEY_TYPE] = gojsonschema.TYPE_OBJECT
|
|
|
|
object := parsePropertiesFromValues(v)
|
|
|
|
object := parsePropertiesFromValues(v)
|
|
|
|
if len(object) > 0 {
|
|
|
|
if len(object) > 0 {
|
|
|
|
properties[k]["object"] = object
|
|
|
|
properties[k][gojsonschema.TYPE_OBJECT] = object
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -234,19 +234,19 @@ func parseItemsFromValues(items []interface{}) map[string]interface{} {
|
|
|
|
// the following types are the only types possible from unmarshalling
|
|
|
|
// the following types are the only types possible from unmarshalling
|
|
|
|
switch v := v.(type) {
|
|
|
|
switch v := v.(type) {
|
|
|
|
case bool:
|
|
|
|
case bool:
|
|
|
|
properties["type"] = "bool"
|
|
|
|
properties[gojsonschema.KEY_TYPE] = gojsonschema.TYPE_BOOLEAN
|
|
|
|
case float64:
|
|
|
|
case float64:
|
|
|
|
properties["type"] = "number"
|
|
|
|
properties[gojsonschema.KEY_TYPE] = gojsonschema.TYPE_NUMBER
|
|
|
|
case string:
|
|
|
|
case string:
|
|
|
|
properties["type"] = "string"
|
|
|
|
properties[gojsonschema.KEY_TYPE] = gojsonschema.TYPE_STRING
|
|
|
|
case []interface{}:
|
|
|
|
case []interface{}:
|
|
|
|
properties["type"] = "array"
|
|
|
|
properties[gojsonschema.KEY_TYPE] = gojsonschema.TYPE_ARRAY
|
|
|
|
properties["items"] = parseItemsFromValues(v)
|
|
|
|
properties[gojsonschema.KEY_ITEMS] = parseItemsFromValues(v)
|
|
|
|
case map[string]interface{}:
|
|
|
|
case map[string]interface{}:
|
|
|
|
properties["type"] = "object"
|
|
|
|
properties[gojsonschema.KEY_TYPE] = gojsonschema.TYPE_OBJECT
|
|
|
|
object := parsePropertiesFromValues(v)
|
|
|
|
object := parsePropertiesFromValues(v)
|
|
|
|
if len(object) > 0 {
|
|
|
|
if len(object) > 0 {
|
|
|
|
properties["object"] = object
|
|
|
|
properties[gojsonschema.TYPE_OBJECT] = object
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return properties
|
|
|
|
return properties
|
|
|
|