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

Function parseJSONSchema

cli/cmd/specs.go:158–185  ·  view source on GitHub ↗
(jsonSchema string)

Source from the content-addressed store, hash-verified

156}
157
158func parseJSONSchema(jsonSchema string) (*jsonschema.Schema, error) {
159 c := jsonschema.NewCompiler()
160 c.DefaultDraft(jsonschema.Draft2020)
161 c.AssertFormat()
162
163 s, err := jsonschema.UnmarshalJSON(strings.NewReader(jsonSchema))
164 if err != nil {
165 return nil, err
166 }
167
168 if err := c.AddResource("schema.json", s); err != nil {
169 return nil, err
170 }
171
172 sc, err := c.Compile("schema.json")
173 if err != nil {
174 var se *jsonschema.SchemaValidationError
175 if errors.As(err, &se); se != nil && se.Err != nil {
176 // We add resource as `file`, but there's none, actually.
177 // So, we need to prettify message a bit.
178 return nil, fmt.Errorf("jsonschema compilation failed: %w",
179 errors.New(strings.Replace(se.Err.Error(), "jsonschema: '' ", "", 1)))
180 }
181 return nil, err
182 }
183
184 return sc, nil
185}
186
187func marshalSpec(spec map[string]any) ([]byte, error) {
188 // All nil or empty values to be marshaled as null

Callers 1

Calls 3

ErrorfMethod · 0.80
UnmarshalJSONMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected