From af0e92e696db55d29e7cf03aa6b9d7f957d28abd Mon Sep 17 00:00:00 2001 From: Mathieu Debove Date: Fri, 18 Jan 2019 15:24:37 +0100 Subject: [PATCH 1/2] Generate JSON schema of Flogo app descriptor (flogo.json) --- .gitignore | 1 + go.mod | 1 + go.sum | 2 + internal/schema/assets.go | 235 +++++++++++++++ internal/schema/generate/schema_generator.go | 28 ++ internal/schema/schema.go | 47 +++ internal/schema/schema.json | 288 +++++++++++++++++++ schema.json | 288 +++++++++++++++++++ 8 files changed, 890 insertions(+) create mode 100644 internal/schema/assets.go create mode 100644 internal/schema/generate/schema_generator.go create mode 100644 internal/schema/schema.go create mode 100644 internal/schema/schema.json create mode 100644 schema.json 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/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..abbac7fc --- /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\x8f\xda\x30\x10\xbd\xf3\x2b\xac\x6c\x8f\x5d\xd2\x5b\x25\x6e\xa8\x97\x1e\x7b\xaf\xf6\xe0\x8d\x0d\x78\x05\x4e\x6a\x4f\x2a\xad\x56\xfc\xf7\x8a\x98\x38\x71\xfc\x01\x26\x0e\x9b\x6a\x37\x07\x24\xc6\xce\x78\x66\x3c\x6f\xde\x83\xb7\x05\x42\x08\x65\x5f\x64\xb1\xa3\x07\x9c\xad\x50\xb6\x03\xa8\x56\x79\xfe\x22\x4b\xfe\xa8\xac\xcb\x52\x6c\x73\x22\xf0\x06\x1e\xbf\x7d\xcf\x95\xed\x21\xfb\xaa\xde\x14\xf4\x4f\xcd\x04\x25\xd9\x0a\xfd\x6e\x2c\x8d\x95\xe3\x03\x3d\xef\x68\xbe\xc3\x6b\x65\x7c\xff\x4b\x85\x64\x25\xef\x9b\x08\x95\x85\x60\x15\x0c\xcc\xec\x50\x95\x02\x64\xdf\x54\x89\xb2\xa2\x02\x18\x35\xac\xc5\x0e\x73\x4e\xf7\x86\x0d\x04\xdb\x6e\xa9\x30\x6c\x82\xca\xb2\x16\x85\xf9\x32\x2e\x4e\xe7\xca\xac\xb1\x3c\x9d\x53\xeb\x9d\xb3\x42\x6f\xf6\xe6\xbe\x51\xc5\x0a\xf4\x60\x9b\xc7\x15\xd8\xf4\x22\xe8\xe6\xe4\xe2\x21\x27\x74\xc3\x38\x6b\xe2\xc8\x55\x3c\xcb\x1f\x25\xdf\xb0\x6d\x66\xbc\x75\x34\x9d\xa8\x7b\x58\xa1\x0c\x0b\x81\x5f\xbb\xad\x47\x57\x1d\x63\xd2\x6b\xfd\x4a\x10\x8c\x8f\x8f\xa1\xdf\x0b\x56\x18\xbe\xb3\x8e\x8e\xae\x79\xc7\x1c\x1a\x08\xdc\x14\xbc\xa7\xef\x2e\xc5\x3f\x65\x8b\x11\x0c\x78\xb9\x06\x10\xec\xb9\x06\x3a\xba\x36\x1d\x06\xe7\x92\x60\x1b\x51\x2a\x14\xe9\xc9\x33\x97\x04\xcf\x01\x25\xcb\x4f\x6d\xb9\xa1\xbb\xdb\xd1\x7f\xfd\xcb\x8b\x9e\x8b\x0c\x13\xd2\x64\x84\xf7\xbf\xfa\x30\xd9\xe0\xbd\xa4\xe7\x2d\xad\xa3\xf2\xf9\x85\x16\xd0\x12\x55\xaf\x18\xe6\x38\x5f\xda\xa1\x38\x49\x4d\xaf\x0e\xc8\xcd\x4c\xc0\x61\xb7\xc9\x4e\x2f\xb9\x49\x4f\x2f\xdb\xe4\xa7\x97\x9c\x24\xa8\x57\x1d\x64\xd8\x85\x69\x93\x62\x2f\x71\x9b\x1c\xf5\xa2\x41\x92\xed\xf3\x34\xe8\x9d\xc0\xf0\x42\x21\xf2\xec\x72\xf6\xe2\x43\x6f\x49\x82\x93\xce\x5b\x2c\xa9\xb6\xcf\xd1\xed\xd4\x07\x9f\xc0\x6b\x7e\xd2\x8d\x29\x4b\x88\xc0\x26\x88\x39\x44\xd2\x57\xc7\xe4\x72\xec\x23\xef\x6e\xc3\xec\x6a\xe1\x24\xfb\xab\x83\x71\x79\xbc\x80\x23\x34\x23\xa8\x84\xc4\x41\x20\x45\x74\x63\xad\xfd\xe2\x61\x6e\x85\x09\x8a\x8a\x09\x2a\xe3\x15\x1d\x73\x2b\x4c\x48\x8c\x4c\x51\x17\x97\x58\xb1\x1c\xc6\xa0\xd3\x27\x62\xae\x77\x1a\x14\x60\x97\x45\x8e\x75\xd0\x59\xec\x38\x25\x97\xc9\x65\x91\x6a\xe7\x74\x81\x11\x62\x47\x52\x00\xc6\xb7\x4e\x01\xc1\x88\x53\x03\x61\xc0\xe3\x34\x45\xe3\xe1\xe2\x55\x0c\x2b\xd4\x3e\x4e\x0a\x22\x69\xfb\x45\xa1\x20\xa1\x43\x5d\xe6\xa4\x69\x8f\x04\xca\x3d\x7b\x7a\x40\x3a\x56\x53\x27\x3e\x6e\x38\xca\x23\x41\xf4\x41\x3a\xff\x9e\x0d\xd0\x72\xc8\xba\x19\x6e\x73\x9e\x6d\x0e\xfb\x7a\x78\x1d\xb1\x17\x7f\x72\xe0\xbd\x27\x4f\xa5\x41\xd4\xf4\x02\xa9\xc6\x74\xca\xcc\x7a\xcf\xe5\x2f\xf1\xd0\x65\xbc\xaa\x03\x65\xbf\x25\xe5\xb2\x86\xe4\x3e\x3f\xc9\x66\xaa\x59\x93\x72\xf8\xfb\x86\x8c\x67\x26\x85\x66\xcf\x0e\x73\xb2\x3f\xe9\xfe\x51\x23\x45\x7b\xf9\x5f\x7e\x3d\xfc\x54\x01\xdf\xe9\x47\xc4\xa7\x24\xbc\x25\xce\xf7\x40\xa9\xd9\x17\x91\x60\x0d\xe1\xec\x43\xfd\x01\xea\xd4\x57\x53\x83\x2c\xfd\xff\x68\x09\x50\x31\x79\x0f\x2f\xd4\xe7\xf1\x5f\x00\x00\x00\xff\xff\x74\xac\x4c\xb6\x8d\x1f\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: 8077, mode: os.FileMode(436), modTime: time.Unix(1547818534, 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..9a1a164d --- /dev/null +++ b/internal/schema/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/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 From 261af9b16a12ed29753d80d960c1f5412057ae17 Mon Sep 17 00:00:00 2001 From: Mathieu Debove Date: Fri, 18 Jan 2019 15:35:55 +0100 Subject: [PATCH 2/2] Add omitempty to fields not present in default flogo.json --- action/config.go | 10 ++++----- app/config.go | 13 ++++++------ internal/schema/assets.go | 4 ++-- internal/schema/schema.json | 41 ++++++++----------------------------- trigger/config.go | 6 +++--- 5 files changed, 25 insertions(+), 49 deletions(-) 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/internal/schema/assets.go b/internal/schema/assets.go index abbac7fc..9d98e0c7 100644 --- a/internal/schema/assets.go +++ b/internal/schema/assets.go @@ -68,7 +68,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _schemaJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x4d\x8f\xda\x30\x10\xbd\xf3\x2b\xac\x6c\x8f\x5d\xd2\x5b\x25\x6e\xa8\x97\x1e\x7b\xaf\xf6\xe0\x8d\x0d\x78\x05\x4e\x6a\x4f\x2a\xad\x56\xfc\xf7\x8a\x98\x38\x71\xfc\x01\x26\x0e\x9b\x6a\x37\x07\x24\xc6\xce\x78\x66\x3c\x6f\xde\x83\xb7\x05\x42\x08\x65\x5f\x64\xb1\xa3\x07\x9c\xad\x50\xb6\x03\xa8\x56\x79\xfe\x22\x4b\xfe\xa8\xac\xcb\x52\x6c\x73\x22\xf0\x06\x1e\xbf\x7d\xcf\x95\xed\x21\xfb\xaa\xde\x14\xf4\x4f\xcd\x04\x25\xd9\x0a\xfd\x6e\x2c\x8d\x95\xe3\x03\x3d\xef\x68\xbe\xc3\x6b\x65\x7c\xff\x4b\x85\x64\x25\xef\x9b\x08\x95\x85\x60\x15\x0c\xcc\xec\x50\x95\x02\x64\xdf\x54\x89\xb2\xa2\x02\x18\x35\xac\xc5\x0e\x73\x4e\xf7\x86\x0d\x04\xdb\x6e\xa9\x30\x6c\x82\xca\xb2\x16\x85\xf9\x32\x2e\x4e\xe7\xca\xac\xb1\x3c\x9d\x53\xeb\x9d\xb3\x42\x6f\xf6\xe6\xbe\x51\xc5\x0a\xf4\x60\x9b\xc7\x15\xd8\xf4\x22\xe8\xe6\xe4\xe2\x21\x27\x74\xc3\x38\x6b\xe2\xc8\x55\x3c\xcb\x1f\x25\xdf\xb0\x6d\x66\xbc\x75\x34\x9d\xa8\x7b\x58\xa1\x0c\x0b\x81\x5f\xbb\xad\x47\x57\x1d\x63\xd2\x6b\xfd\x4a\x10\x8c\x8f\x8f\xa1\xdf\x0b\x56\x18\xbe\xb3\x8e\x8e\xae\x79\xc7\x1c\x1a\x08\xdc\x14\xbc\xa7\xef\x2e\xc5\x3f\x65\x8b\x11\x0c\x78\xb9\x06\x10\xec\xb9\x06\x3a\xba\x36\x1d\x06\xe7\x92\x60\x1b\x51\x2a\x14\xe9\xc9\x33\x97\x04\xcf\x01\x25\xcb\x4f\x6d\xb9\xa1\xbb\xdb\xd1\x7f\xfd\xcb\x8b\x9e\x8b\x0c\x13\xd2\x64\x84\xf7\xbf\xfa\x30\xd9\xe0\xbd\xa4\xe7\x2d\xad\xa3\xf2\xf9\x85\x16\xd0\x12\x55\xaf\x18\xe6\x38\x5f\xda\xa1\x38\x49\x4d\xaf\x0e\xc8\xcd\x4c\xc0\x61\xb7\xc9\x4e\x2f\xb9\x49\x4f\x2f\xdb\xe4\xa7\x97\x9c\x24\xa8\x57\x1d\x64\xd8\x85\x69\x93\x62\x2f\x71\x9b\x1c\xf5\xa2\x41\x92\xed\xf3\x34\xe8\x9d\xc0\xf0\x42\x21\xf2\xec\x72\xf6\xe2\x43\x6f\x49\x82\x93\xce\x5b\x2c\xa9\xb6\xcf\xd1\xed\xd4\x07\x9f\xc0\x6b\x7e\xd2\x8d\x29\x4b\x88\xc0\x26\x88\x39\x44\xd2\x57\xc7\xe4\x72\xec\x23\xef\x6e\xc3\xec\x6a\xe1\x24\xfb\xab\x83\x71\x79\xbc\x80\x23\x34\x23\xa8\x84\xc4\x41\x20\x45\x74\x63\xad\xfd\xe2\x61\x6e\x85\x09\x8a\x8a\x09\x2a\xe3\x15\x1d\x73\x2b\x4c\x48\x8c\x4c\x51\x17\x97\x58\xb1\x1c\xc6\xa0\xd3\x27\x62\xae\x77\x1a\x14\x60\x97\x45\x8e\x75\xd0\x59\xec\x38\x25\x97\xc9\x65\x91\x6a\xe7\x74\x81\x11\x62\x47\x52\x00\xc6\xb7\x4e\x01\xc1\x88\x53\x03\x61\xc0\xe3\x34\x45\xe3\xe1\xe2\x55\x0c\x2b\xd4\x3e\x4e\x0a\x22\x69\xfb\x45\xa1\x20\xa1\x43\x5d\xe6\xa4\x69\x8f\x04\xca\x3d\x7b\x7a\x40\x3a\x56\x53\x27\x3e\x6e\x38\xca\x23\x41\xf4\x41\x3a\xff\x9e\x0d\xd0\x72\xc8\xba\x19\x6e\x73\x9e\x6d\x0e\xfb\x7a\x78\x1d\xb1\x17\x7f\x72\xe0\xbd\x27\x4f\xa5\x41\xd4\xf4\x02\xa9\xc6\x74\xca\xcc\x7a\xcf\xe5\x2f\xf1\xd0\x65\xbc\xaa\x03\x65\xbf\x25\xe5\xb2\x86\xe4\x3e\x3f\xc9\x66\xaa\x59\x93\x72\xf8\xfb\x86\x8c\x67\x26\x85\x66\xcf\x0e\x73\xb2\x3f\xe9\xfe\x51\x23\x45\x7b\xf9\x5f\x7e\x3d\xfc\x54\x01\xdf\xe9\x47\xc4\xa7\x24\xbc\x25\xce\xf7\x40\xa9\xd9\x17\x91\x60\x0d\xe1\xec\x43\xfd\x01\xea\xd4\x57\x53\x83\x2c\xfd\xff\x68\x09\x50\x31\x79\x0f\x2f\xd4\xe7\xf1\x5f\x00\x00\x00\xff\xff\x74\xac\x4c\xb6\x8d\x1f\x00\x00") +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( @@ -83,7 +83,7 @@ func schemaJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "schema.json", size: 8077, mode: os.FileMode(436), modTime: time.Unix(1547818534, 0)} + 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 } diff --git a/internal/schema/schema.json b/internal/schema/schema.json index 9a1a164d..5d3c5a1f 100644 --- a/internal/schema/schema.json +++ b/internal/schema/schema.json @@ -5,12 +5,7 @@ "type", "version", "description", - "imports", - "properties", - "channels", - "triggers", - "resources", - "actions" + "appModel" ], "properties": { "actions": { @@ -20,6 +15,9 @@ }, "type": "array" }, + "appModel": { + "type": "string" + }, "channels": { "items": { "type": "string" @@ -75,12 +73,7 @@ "type", "version", "description", - "imports", - "properties", - "channels", - "triggers", - "resources", - "actions" + "appModel" ], "properties": { "actions": { @@ -90,6 +83,9 @@ }, "type": "array" }, + "appModel": { + "type": "string" + }, "channels": { "items": { "type": "string" @@ -140,13 +136,6 @@ "type": "object" }, "action.Config": { - "required": [ - "ref", - "type", - "settings", - "id", - "data" - ], "properties": { "data": { "type": "object" @@ -188,19 +177,7 @@ "type": "object" }, "trigger.ActionConfig": { - "required": [ - "ref", - "type", - "settings", - "id", - "data", - "Act" - ], "properties": { - "Act": { - "additionalProperties": true, - "type": "object" - }, "data": { "type": "object" }, @@ -232,8 +209,6 @@ "trigger.Config": { "required": [ "id", - "type", - "ref", "settings", "handlers" ], 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