MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / validateSpecAgainstSchema

Function validateSpecAgainstSchema

cli/cmd/specs.go:142–156  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

140// (after a successful gRPC GetSpecSchema) and by the Hub-API path in
141// validateConfig.
142func 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
158func parseJSONSchema(jsonSchema string) (*jsonschema.Schema, error) {
159 c := jsonschema.NewCompiler()

Callers 2

validatePluginSpecFunction · 0.85
validateViaHubAPIFunction · 0.85

Calls 2

parseJSONSchemaFunction · 0.85
ValidateMethod · 0.45

Tested by

no test coverage detected