Skip to content

Commit

Permalink
renamed json.checkExists to json.exists (#146)
Browse files Browse the repository at this point in the history
rename checkExists to exists
  • Loading branch information
awakchau-tibco authored Oct 28, 2021
1 parent 4740d71 commit 9ac17b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion function/json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 4601
# JSON Functions
This function package exposes common json functions.

## checkExists()
## exists()
Check if the key/JSONPath is present in the json object. Refer https://github.com/oliveagle/jsonpath for expression format.
### Input Args

Expand Down
4 changes: 2 additions & 2 deletions function/json/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"homepage": "https://github.com/prject-flogo/contrib/tree/master/function/json",
"functions": [
{
"name": "checkExists",
"name": "exists",
"description": "Check if the key/JSONPath is present in the json object. Refer https://github.com/oliveagle/jsonpath for expression format.",
"example": "json.checkExists(jsonObject, \"$.key\") => value",
"example": "json.exists(jsonObject, \"$.key\") => value",
"args": [
{
"name": "jsonObject",
Expand Down
12 changes: 6 additions & 6 deletions function/json/checkexists.go → function/json/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
)

func init() {
_ = function.Register(&fnCheckExists{})
_ = function.Register(&fnExists{})
}

type fnCheckExists struct {
type fnExists struct {
}

// Name returns the name of the function
func (fnCheckExists) Name() string {
return "checkExists"
func (fnExists) Name() string {
return "exists"
}

// Sig returns the function signature
func (fnCheckExists) Sig() (paramTypes []data.Type, isVariadic bool) {
func (fnExists) Sig() (paramTypes []data.Type, isVariadic bool) {
return []data.Type{data.TypeAny, data.TypeString}, false
}

// Eval executes the function
func (fnCheckExists) Eval(params ...interface{}) (interface{}, error) {
func (fnExists) Eval(params ...interface{}) (interface{}, error) {
expression, ok := params[1].(string)
if !ok {
return false, fmt.Errorf("The JSON key/path must be a string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestFnCheckExists(t *testing.T) {
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
assert.Nil(t, err)

f := &fnCheckExists{}
f := &fnExists{}
v, err := function.Eval(f, inputJSON, "$.store.book[?(@.price == 12.99)].price[0]")
assert.Nil(t, err)
assert.Equal(t, true, v)
Expand All @@ -49,7 +49,7 @@ func TestFnCheckExistsLoop(t *testing.T) {
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
assert.Nil(t, err)

f := &fnCheckExists{}
f := &fnExists{}
v, err := function.Eval(f, inputJSON, "$loop.store.book[?(@.price == 22.99)].price[0]")
assert.NotNil(t, err)
assert.Equal(t, false, v)
Expand All @@ -60,7 +60,7 @@ func TestFnCheckExistsNegative(t *testing.T) {
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
assert.Nil(t, err)

f := &fnCheckExists{}
f := &fnExists{}
v, err := function.Eval(f, inputJSON, "$.store.abc")
assert.NotNil(t, err)
assert.Equal(t, false, v)
Expand All @@ -71,7 +71,7 @@ func TestFnCheckExistsEmpty(t *testing.T) {
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
assert.Nil(t, err)

f := &fnCheckExists{}
f := &fnExists{}
v, err := function.Eval(f, inputJSON, "$.emptyString")
assert.Nil(t, err)
assert.Equal(t, true, v)
Expand Down

0 comments on commit 9ac17b8

Please sign in to comment.