validateSpecAgainstSchema validates spec against a JSON schema string. Mirrors the lenient gRPC-side semantics: an empty or unparseable schema is logged and treated as "skip validation". Used both by validatePluginSpec (after a successful gRPC GetSpecSchema) and by the Hub-API path in validateConfig
(jsonSchema string, spec any)
| 140 | // (after a successful gRPC GetSpecSchema) and by the Hub-API path in |
| 141 | // validateConfig. |
| 142 | func validateSpecAgainstSchema(jsonSchema string, spec any) error { |
| 143 | if len(jsonSchema) == 0 { |
| 144 | // This will also be true for Unimplemented response (schema = nil => schema.GetJsonSchema() = "") |
| 145 | log.Info().Msg("empty JSON schema for plugin spec, skipping validation") |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | sc, err := parseJSONSchema(jsonSchema) |
| 150 | if err != nil { |
| 151 | log.Err(err).Msg("failed to parse spec schema, skipping validation") |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | return sc.Validate(spec) |
| 156 | } |
| 157 | |
| 158 | func parseJSONSchema(jsonSchema string) (*jsonschema.Schema, error) { |
| 159 | c := jsonschema.NewCompiler() |
no test coverage detected