diff --git a/.gitignore b/.gitignore index a572d48b..9f4596c0 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ _testmain.go .vscode/ tags .vscode/symbols.json +.idea .build-cache submodules/flogo-cicd/.build-cache ./Dockerfile diff --git a/action/config.go b/action/config.go index 92dd7792..4e5e6331 100644 --- a/action/config.go +++ b/action/config.go @@ -5,13 +5,13 @@ import "encoding/json" // Config is the configuration for the Action type Config struct { //inline action - Ref string `json:"ref"` - Type string `json:"type"` //an alias to the ref, can be used if imported - Settings map[string]interface{} `json:"settings"` + Ref string `json:"ref,omitempty"` + Type string `json:"type,omitempty"` //an alias to the ref, can be used if imported + Settings map[string]interface{} `json:"settings,omitempty"` //referenced action - Id string `json:"id"` + Id string `json:"id,omitempty"` //DEPRECATED - Data json.RawMessage `json:"data"` + Data json.RawMessage `json:"data,omitempty"` } diff --git a/app/config.go b/app/config.go index a766f4f2..00d8f158 100644 --- a/app/config.go +++ b/app/config.go @@ -13,11 +13,12 @@ type Config struct { Type string `json:"type"` Version string `json:"version"` Description string `json:"description"` + AppModel string `json:"appModel"` - Imports []string `json:"imports"` - Properties []*data.Attribute `json:"properties"` - Channels []string `json:"channels"` - Triggers []*trigger.Config `json:"triggers"` - Resources []*resource.Config `json:"resources"` - Actions []*action.Config `json:"actions"` + Imports []string `json:"imports,omitempty"` + Properties []*data.Attribute `json:"properties,omitempty"` + Channels []string `json:"channels,omitempty"` + Triggers []*trigger.Config `json:"triggers,omitempty"` + Resources []*resource.Config `json:"resources,omitempty"` + Actions []*action.Config `json:"actions,omitempty"` } \ No newline at end of file diff --git a/go.mod b/go.mod index c8943932..350ce683 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/project-flogo/core require ( + github.com/square-it/jsonschema v1.9.1 // indirect github.com/stretchr/testify v1.2.2 go.uber.org/atomic v1.3.2 // indirect go.uber.org/multierr v1.1.0 // indirect diff --git a/go.sum b/go.sum index 50177947..692c4940 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/project-flogo/core v0.9.0-alpha.3/go.mod h1:BHeB55AxPhvlNGd+it50rE977ag6xE3bD2RluSDeKBA= +github.com/square-it/jsonschema v1.9.1 h1:0pYdNW+bvukTIBqcfal5XXHikgp/AbADeqcP7I0uV4M= +github.com/square-it/jsonschema v1.9.1/go.mod h1:80WJHSuy3YnokzfFopfx+MAt5lVVnVpS6w2Avv+svHk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/schema/assets.go b/internal/schema/assets.go new file mode 100644 index 00000000..9d98e0c7 --- /dev/null +++ b/internal/schema/assets.go @@ -0,0 +1,235 @@ +// Code generated by go-bindata. +// sources: +// schema.json +// DO NOT EDIT! + +package schema + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "strings" + "time" +) + +func bindataRead(data []byte, name string) ([]byte, error) { + gz, err := gzip.NewReader(bytes.NewBuffer(data)) + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + var buf bytes.Buffer + _, err = io.Copy(&buf, gz) + clErr := gz.Close() + + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + if clErr != nil { + return nil, err + } + + return buf.Bytes(), nil +} + +type asset struct { + bytes []byte + info os.FileInfo +} + +type bindataFileInfo struct { + name string + size int64 + mode os.FileMode + modTime time.Time +} + +func (fi bindataFileInfo) Name() string { + return fi.name +} +func (fi bindataFileInfo) Size() int64 { + return fi.size +} +func (fi bindataFileInfo) Mode() os.FileMode { + return fi.mode +} +func (fi bindataFileInfo) ModTime() time.Time { + return fi.modTime +} +func (fi bindataFileInfo) IsDir() bool { + return false +} +func (fi bindataFileInfo) Sys() interface{} { + return nil +} + +var _schemaJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x4d\x6f\x9c\x30\x10\xbd\xef\xaf\xb0\x9c\x1e\x9b\xa5\xb7\x4a\xdc\xa2\x5e\x7a\xa9\xd4\x7b\x95\x83\x83\x0d\xeb\x88\xb5\xa9\x31\x95\xa2\x68\xff\x7b\x85\xf9\x58\x0c\xb6\xf9\x32\x1b\x12\x65\x0f\x91\x18\xdb\xcf\x33\xc3\xcc\xbc\x17\x5e\x0f\x00\x00\x00\xbf\xe4\xd1\x89\x9c\x11\x0c\x01\x3c\x49\x99\x85\x41\xf0\x9c\x73\x76\x5f\x59\x8f\x5c\x24\x01\x16\x28\x96\xf7\xdf\xbe\x07\x95\xed\x0e\x7e\xad\x4e\x0a\xf2\xb7\xa0\x82\x60\x18\x82\x3f\xca\xa2\xac\x0c\x9d\x49\xbd\x43\x3d\xcb\x97\x4c\x7b\xfe\x47\x44\x4e\x39\xeb\x9a\x30\xc9\x23\x41\x33\xd9\x33\xa3\x2c\xfb\xc5\x31\x49\xa1\x32\x3d\xd6\xb7\x66\x82\x67\x44\x48\x4a\x72\x18\x82\xd7\xce\xee\xa8\x3c\xaf\x1b\xd5\x02\x95\xe4\x3c\x34\xaf\x8b\x5d\x47\x11\x24\x2e\x21\xee\x02\x4c\x62\xca\xa8\xf2\x23\xa8\xfc\x39\xfe\xe0\x2c\xa6\x09\xd4\x4e\x5d\x74\x90\x2a\x45\x21\x80\x48\x08\xf4\x72\xdd\x7a\x31\xe5\x62\x10\x5e\x73\x38\x97\x82\xb2\xc4\x7c\x3a\x3a\x21\xc6\x48\x3a\x2f\x39\x36\xe0\x85\x11\x74\x5f\xf2\xa2\x20\xe8\x39\xe3\x42\xbe\x69\x0c\xaa\xb6\x17\x39\x6f\xa9\xda\x31\xff\xb7\x2c\x50\x8c\x24\x3a\x3e\x48\x29\xe8\x53\x21\xc9\xea\xdc\x08\x92\xf3\x42\x44\x3b\x0a\xb0\xf1\xc8\x57\x0f\x4a\x41\x93\x84\x88\xfd\x04\x58\x3b\xe4\x2d\xbe\x6a\xcb\x82\xea\x6e\x66\xfa\xf4\xc3\x87\x0e\x04\x44\x18\xab\x88\x50\xfa\xbb\xdb\x26\x31\x4a\x73\x52\x6f\x69\x80\xf8\xd3\x33\x89\x64\xc3\x40\x9d\x64\xe8\x64\x70\x1c\xba\x62\x64\xab\x76\xb5\xc7\x5a\x7a\x00\x06\xfb\x90\xc5\xda\x25\x33\x9b\xb5\xcb\x3a\xab\x35\xbf\xc7\xde\xeb\x72\xcc\x0b\xe0\x62\xbb\x76\x83\xbd\x24\xdb\x2d\x5e\x4a\xf3\x8a\x36\x97\x05\x9b\xdf\xc5\x0c\x6a\xab\x58\xc7\x31\x3b\x4b\x0e\x40\x4d\x84\x60\x43\xb5\xb2\x67\xbb\x63\x42\xb2\xc7\x2e\xb6\x5c\x0e\x16\x66\xc2\xc5\xb6\x93\x7d\x32\x01\xdb\x58\xf8\xba\x61\x77\xb9\x30\xb2\xf6\x64\x67\x4c\x88\x23\xdd\x09\x76\xd4\x80\x2e\x96\x77\x84\x08\x16\xe6\xda\xae\x02\xf6\x96\x18\xa7\x3a\xd8\x20\x33\x56\xf5\xb0\xb7\xc4\xb8\x54\xc5\x16\x79\x31\xa9\x8e\x01\xe0\x9c\xee\xb4\xa9\x91\xe9\xa0\x4e\x25\x35\xae\x56\x06\x17\xd5\xaa\xc5\xfc\x9f\x9d\xc6\x90\x03\xd9\x32\x26\x04\xca\xfe\x1e\x8f\xb4\xef\x80\x25\x36\x75\x86\x62\xbf\xaf\xa3\x2a\x32\x8f\x80\x39\x91\x92\xb2\xc4\xd1\x49\x4b\xc2\x5e\x59\x87\xb7\x2c\x99\xde\x4c\x1f\xd4\x8c\xe7\xeb\xfa\x93\x72\xa6\xb4\xa6\xd8\xa8\x92\xcb\xba\x5d\x25\x81\x77\x56\xf9\xb7\x2c\x80\x66\x44\x3f\xa8\xd9\xf1\x71\x47\x07\xf5\x3c\x39\x28\xcb\x0a\xe9\x37\x64\x5e\x48\xef\x98\x9f\x13\x73\xab\x86\xf1\x39\xc1\xda\xa4\x1a\xd6\x4e\x88\xe1\xb4\x14\x7b\xab\x26\x5c\x8b\xf2\x5e\x24\xe3\xcf\xca\xe1\x1b\x29\xc7\x4f\xa1\xb2\xc4\xcf\xb7\x68\x3b\xbd\x2e\x66\x76\x9f\xab\xcf\x9a\xcf\x60\xab\xda\xec\xbd\x7c\x4b\x33\xb2\xfe\xd6\x4d\xe6\xff\xe3\x89\x87\xae\xd8\xbc\x86\x0f\xd5\xdf\xcb\xff\x00\x00\x00\xff\xff\x83\xb2\x9c\x13\x24\x1d\x00\x00") + +func schemaJsonBytes() ([]byte, error) { + return bindataRead( + _schemaJson, + "schema.json", + ) +} + +func schemaJson() (*asset, error) { + bytes, err := schemaJsonBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "schema.json", size: 7460, mode: os.FileMode(436), modTime: time.Unix(1547822043, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +// Asset loads and returns the asset for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func Asset(name string) ([]byte, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) + } + return a.bytes, nil + } + return nil, fmt.Errorf("Asset %s not found", name) +} + +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if err != nil { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + +// AssetInfo loads and returns the asset info for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func AssetInfo(name string) (os.FileInfo, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) + } + return a.info, nil + } + return nil, fmt.Errorf("AssetInfo %s not found", name) +} + +// AssetNames returns the names of the assets. +func AssetNames() []string { + names := make([]string, 0, len(_bindata)) + for name := range _bindata { + names = append(names, name) + } + return names +} + +// _bindata is a table, holding each asset generator, mapped to its name. +var _bindata = map[string]func() (*asset, error){ + "schema.json": schemaJson, +} + +// AssetDir returns the file names below a certain +// directory embedded in the file by go-bindata. +// For example if you run go-bindata on data/... and data contains the +// following hierarchy: +// data/ +// foo.txt +// img/ +// a.png +// b.png +// then AssetDir("data") would return []string{"foo.txt", "img"} +// AssetDir("data/img") would return []string{"a.png", "b.png"} +// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// AssetDir("") will return []string{"data"}. +func AssetDir(name string) ([]string, error) { + node := _bintree + if len(name) != 0 { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + } + } + if node.Func != nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + rv := make([]string, 0, len(node.Children)) + for childName := range node.Children { + rv = append(rv, childName) + } + return rv, nil +} + +type bintree struct { + Func func() (*asset, error) + Children map[string]*bintree +} +var _bintree = &bintree{nil, map[string]*bintree{ + "schema.json": &bintree{schemaJson, map[string]*bintree{}}, +}} + +// RestoreAsset restores an asset under the given directory +func RestoreAsset(dir, name string) error { + data, err := Asset(name) + if err != nil { + return err + } + info, err := AssetInfo(name) + if err != nil { + return err + } + err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) + if err != nil { + return err + } + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) + if err != nil { + return err + } + err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) + if err != nil { + return err + } + return nil +} + +// RestoreAssets restores an asset under the given directory recursively +func RestoreAssets(dir, name string) error { + children, err := AssetDir(name) + // File + if err != nil { + return RestoreAsset(dir, name) + } + // Dir + for _, child := range children { + err = RestoreAssets(dir, filepath.Join(name, child)) + if err != nil { + return err + } + } + return nil +} + +func _filePath(dir, name string) string { + cannonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) +} + diff --git a/internal/schema/generate/schema_generator.go b/internal/schema/generate/schema_generator.go new file mode 100644 index 00000000..d72e68cf --- /dev/null +++ b/internal/schema/generate/schema_generator.go @@ -0,0 +1,28 @@ +// +build ignore + +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + + "github.com/square-it/jsonschema" + "github.com/project-flogo/core/app" +) + +func main() { + reflector := &jsonschema.Reflector{ExpandedStruct: true} + schema := reflector.Reflect(&app.Config{}) + schemaJSON, err := json.MarshalIndent(schema, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) + } + err = ioutil.WriteFile("schema.json", schemaJSON, 0644) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) + } +} diff --git a/internal/schema/schema.go b/internal/schema/schema.go new file mode 100644 index 00000000..08743e19 --- /dev/null +++ b/internal/schema/schema.go @@ -0,0 +1,47 @@ +//go:generate go run generate/schema_generator.go +//go:generate go-bindata -pkg schema -o assets.go schema.json + +package schema + +import ( + "bytes" + "errors" + "fmt" + + "github.com/xeipuuv/gojsonschema" +) + +var schema *gojsonschema.Schema + +func init() { + jsonSchema, err := Asset("schema.json") + if err != nil { + panic(err) + } + schemaLoader := gojsonschema.NewStringLoader(string(jsonSchema)) + schema, err = gojsonschema.NewSchema(schemaLoader) + if err != nil { + panic(err) + } +} + +// Validate validates the provided JSON against the v2 JSON schema. +func Validate(JSON []byte) error { + JSONLoader := gojsonschema.NewStringLoader(string(JSON)) + result, err := schema.Validate(JSONLoader) + + if err != nil { + return err + } + + if result.Valid() { + return err + } + var msg bytes.Buffer + + msg.WriteString("The JSON is not valid. See errors:\n") + for _, desc := range result.Errors() { + msg.WriteString(fmt.Sprintf("- %s\n", desc)) + } + return errors.New(msg.String()) +} diff --git a/internal/schema/schema.json b/internal/schema/schema.json new file mode 100644 index 00000000..5d3c5a1f --- /dev/null +++ b/internal/schema/schema.json @@ -0,0 +1,263 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "required": [ + "name", + "type", + "version", + "description", + "appModel" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/action.Config" + }, + "type": "array" + }, + "appModel": { + "type": "string" + }, + "channels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "imports": { + "items": { + "type": "string" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "properties": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/data.Attribute" + }, + "type": "array" + }, + "resources": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/resource.Config" + }, + "type": "array" + }, + "triggers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.Config" + }, + "type": "array" + }, + "type": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "definitions": { + ".": { + "required": [ + "name", + "type", + "version", + "description", + "appModel" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/action.Config" + }, + "type": "array" + }, + "appModel": { + "type": "string" + }, + "channels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "imports": { + "items": { + "type": "string" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "properties": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/data.Attribute" + }, + "type": "array" + }, + "resources": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/resource.Config" + }, + "type": "array" + }, + "triggers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.Config" + }, + "type": "array" + }, + "type": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "action.Config": { + "properties": { + "data": { + "type": "object" + }, + "id": { + "type": "string" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "data.Attribute": { + "additionalProperties": false, + "type": "object" + }, + "resource.Config": { + "required": [ + "id", + "data" + ], + "properties": { + "data": { + "type": "object" + }, + "id": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.ActionConfig": { + "properties": { + "data": { + "type": "object" + }, + "id": { + "type": "string" + }, + "if": { + "type": "string" + }, + "input": { + "type": "object" + }, + "output": { + "type": "object" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.Config": { + "required": [ + "id", + "settings", + "handlers" + ], + "properties": { + "handlers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.HandlerConfig" + }, + "type": "array" + }, + "id": { + "type": "string" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.HandlerConfig": { + "required": [ + "settings", + "actions" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.ActionConfig" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "settings": { + "type": "object" + } + }, + "additionalProperties": false, + "type": "object" + } + } +} \ No newline at end of file diff --git a/schema.json b/schema.json new file mode 100644 index 00000000..9a1a164d --- /dev/null +++ b/schema.json @@ -0,0 +1,288 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "required": [ + "name", + "type", + "version", + "description", + "imports", + "properties", + "channels", + "triggers", + "resources", + "actions" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/action.Config" + }, + "type": "array" + }, + "channels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "imports": { + "items": { + "type": "string" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "properties": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/data.Attribute" + }, + "type": "array" + }, + "resources": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/resource.Config" + }, + "type": "array" + }, + "triggers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.Config" + }, + "type": "array" + }, + "type": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "definitions": { + ".": { + "required": [ + "name", + "type", + "version", + "description", + "imports", + "properties", + "channels", + "triggers", + "resources", + "actions" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/action.Config" + }, + "type": "array" + }, + "channels": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "imports": { + "items": { + "type": "string" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "properties": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/data.Attribute" + }, + "type": "array" + }, + "resources": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/resource.Config" + }, + "type": "array" + }, + "triggers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.Config" + }, + "type": "array" + }, + "type": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "action.Config": { + "required": [ + "ref", + "type", + "settings", + "id", + "data" + ], + "properties": { + "data": { + "type": "object" + }, + "id": { + "type": "string" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "data.Attribute": { + "additionalProperties": false, + "type": "object" + }, + "resource.Config": { + "required": [ + "id", + "data" + ], + "properties": { + "data": { + "type": "object" + }, + "id": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.ActionConfig": { + "required": [ + "ref", + "type", + "settings", + "id", + "data", + "Act" + ], + "properties": { + "Act": { + "additionalProperties": true, + "type": "object" + }, + "data": { + "type": "object" + }, + "id": { + "type": "string" + }, + "if": { + "type": "string" + }, + "input": { + "type": "object" + }, + "output": { + "type": "object" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.Config": { + "required": [ + "id", + "type", + "ref", + "settings", + "handlers" + ], + "properties": { + "handlers": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.HandlerConfig" + }, + "type": "array" + }, + "id": { + "type": "string" + }, + "ref": { + "type": "string" + }, + "settings": { + "type": "object" + }, + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "trigger.HandlerConfig": { + "required": [ + "settings", + "actions" + ], + "properties": { + "actions": { + "items": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/trigger.ActionConfig" + }, + "type": "array" + }, + "name": { + "type": "string" + }, + "settings": { + "type": "object" + } + }, + "additionalProperties": false, + "type": "object" + } + } +} \ No newline at end of file diff --git a/trigger/config.go b/trigger/config.go index 4bc61036..0f544af8 100644 --- a/trigger/config.go +++ b/trigger/config.go @@ -12,8 +12,8 @@ import ( // Config is the configuration for a Trigger type Config struct { Id string `json:"id"` - Type string `json:"type"` //an alias to the ref, can be used if imported - Ref string `json:"ref"` + Type string `json:"type,omitempty"` //an alias to the ref, can be used if imported + Ref string `json:"ref,omitempty"` Settings map[string]interface{} `json:"settings"` Handlers []*HandlerConfig `json:"handlers"` } @@ -94,7 +94,7 @@ type ActionConfig struct { Input map[string]interface{} `json:"input,omitempty"` Output map[string]interface{} `json:"output,omitempty"` - Act action.Action + Act action.Action `json:"-,omitempty"` } // UnmarshalJSON overrides the default UnmarshalJSON for TaskInst