Validate uses the jsonschema to validate the configuration
(config map[string]interface{})
| 82 | |
| 83 | // Validate uses the jsonschema to validate the configuration |
| 84 | func Validate(config map[string]interface{}) error { |
| 85 | schema, err := compileSchema() |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | // santhosh-tekuri doesn't allow derived types |
| 91 | // see https://github.com/santhosh-tekuri/jsonschema/pull/240 |
| 92 | marshaled, err := json.Marshal(config) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | |
| 97 | var raw map[string]interface{} |
| 98 | err = json.Unmarshal(marshaled, &raw) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | err = schema.Validate(raw) |
| 104 | var verr *jsonschema.ValidationError |
| 105 | if ok := errors.As(err, &verr); ok { |
| 106 | return validationError{getMostSpecificError(verr)} |
| 107 | } |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | type validationError struct { |
| 112 | err *jsonschema.ValidationError |
searching dependent graphs…