/
derference_schemas.go
48 lines (38 loc) · 1.06 KB
/
derference_schemas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package bundle
import (
"fmt"
"path/filepath"
"github.com/massdriver-cloud/mass/pkg/jsonschema"
"github.com/massdriver-cloud/mass/pkg/restclient"
"github.com/spf13/afero"
)
type DereferenceTarget struct {
schema *map[string]interface{}
label string
}
func (b *Bundle) DereferenceSchemas(path string, c *restclient.MassdriverClient, fs afero.Fs) error {
cwd := filepath.Dir(path)
tasks := []DereferenceTarget{
{schema: &b.Artifacts, label: "artifacts"},
{schema: &b.Params, label: "params"},
{schema: &b.Connections, label: "connections"},
{schema: &b.UI, label: "ui"},
}
for _, task := range tasks {
if task.schema == nil {
*task.schema = map[string]interface{}{
"properties": make(map[string]interface{}),
}
}
dereferencedSchema, err := jsonschema.Dereference(*task.schema, jsonschema.DereferenceOptions{Fs: fs, Client: c, Cwd: cwd})
if err != nil {
return err
}
var ok bool
*task.schema, ok = dereferencedSchema.(map[string]interface{})
if !ok {
return fmt.Errorf("hydrated %s is not a map", task.label)
}
}
return nil
}