-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required Fields V2 - Conditionally Required Fields #2099
Merged
+3,266
−13
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
eb1fd29
PoC for direct builder defined JSON Schema with working unit test
nick-Ag f3d7f78
Adds more unit tests
nick-Ag 18eae5d
Renames definition.validSchema to definition.groupConditions and rest…
nick-Ag 4ac8c4b
WIP - implementation of DependsOnConditions conversion to JsonSchema
nick-Ag bf89d62
Merge branch 'main' into required-fields-v2
nick-Ag 06d689e
Generates a basic schema. Passes basic test case
nick-Ag 5e1c154
More unit tests, non-passing
nick-Ag 91f3a01
Merge remote-tracking branch 'origin/main' into required-fields-v2
nick-Ag b5fbb2c
Able to generate schema when there are multiple conditions on one fie…
nick-Ag 80148b2
WIP - unit tests
nick-Ag 1bc68c1
WIP - two cases failing, not from an incorrectly created schema
nick-Ag 6c3e51e
All test cases for multiple conditions on same field passing
nick-Ag 4048746
Can validate a basic object dependency
nick-Ag 0593689
Can validate a basic object dependency with an is_not operator
nick-Ag 933a18c
Adds more object test cases
nick-Ag a677f43
Adds unit tests for different value data types
nick-Ag 49812e3
Can validate simple conditions with undefined values
nick-Ag 7b7d767
Adds new unit tests for multiple conditions with an undefined value. …
nick-Ag 2329819
Some helper methods and DRYing
nick-Ag 30a3ad5
WIP - only test object case
nick-Ag b1704f5
WIP - renames helper method to be more descriptive
nick-Ag f8a7c26
WIP - enable all unit tests
nick-Ag 78a1e69
WIP - factors out singleConditionSingleDependency case
nick-Ag 700f967
WIP - factors out singleConditionSingleDependency case
nick-Ag d1d2773
WIP - simplifies multiple non-object case
nick-Ag 8e75171
WIP - simplifies multiple object case. actually passes multiple: true…
nick-Ag 8caebae
Removes commented out code
nick-Ag b41424b
Fixed incorrect test case, all test cases passing
nick-Ag d4f036a
Removes 3 year old todo unit test
nick-Ag e73ec64
Removes groupConditions as they'll be implemented in a separate PR
nick-Ag f8a0558
Renames fields-to-jsonschema file to indicate it only contains snapsh…
nick-Ag f48807d
Merge branch 'main' into required-fields-v2
nick-Ag c8f0490
Removes dedicated snapshot tests and just makes all existing tests al…
nick-Ag 488753e
Skips conditions when generating types for the stored file
nick-Ag 99c6326
WIP - unit test for null values
nick-Ag 7b899fb
Merge branch 'main' into required-fields-v2
nick-Ag a5ab39f
Adds conditional requirement to Lead V2 action as well
nick-Ag 7713734
Handles explicitly null values as if they were undefined fields
nick-Ag 8c023a0
Removes conditionally required from Lead V2 since that action relies …
nick-Ag 908152d
Consolidates two test cases into one since they share a schema. Remov…
nick-Ag 881a380
WIP - conditionally required object sub-property unit test
nick-Ag 4e29f8b
WIP - working on conditionally required object properties
nick-Ag 15eb5d9
Can validate conditionally required object properties
nick-Ag 8d2d7d9
Unit test for when two fields depend on each other
nick-Ag 44f6926
Updates readme and the description for the required property with inf…
nick-Ag 2fb6b01
Adds dot notation example in readme
nick-Ag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,7 @@ interface InputField { | |
dynamic?: boolean | ||
|
||
/** Whether or not the field is required */ | ||
required?: boolean | ||
required?: boolean | DependsOnConditions | ||
|
||
/** | ||
* Optional definition for the properties of `type: 'object'` fields | ||
|
@@ -358,6 +358,126 @@ const destination = { | |
|
||
In addition to default values for input fields, you can also specify the defaultSubscription for a given action – this is the FQL query that will be automatically populated when a customer configures a new subscription triggering a given action. | ||
|
||
## Required Fields | ||
|
||
You may configure a field to either be always required, not required, or conditionally required. Validation for required fields is performed both when a user is configuring a mapping in the UI and when an event payload is delivered through a `perform` block. | ||
|
||
**An example of each possible value for `required`** | ||
|
||
```js | ||
const destination = { | ||
actions: { | ||
readmeAction: { | ||
fields: { | ||
operation: { | ||
label: 'An operation for the readme action', | ||
required: true // This field is always required and any payloads omitting it will fail | ||
}, | ||
creationName: { | ||
label: "The name of the resource to create, required when operation = 'create'", | ||
required: { | ||
// This field is required only when the 'operation' field has the value 'create' | ||
match: 'all', | ||
conditions: [ | ||
{ | ||
fieldKey: 'operation', | ||
operator: 'is', | ||
value: 'create' | ||
} | ||
] | ||
} | ||
}, | ||
email: { | ||
label: 'The customer email', | ||
required: false // This field is not required. This is the same as not including the 'required' property at all | ||
}, | ||
userIdentifiers: { | ||
phone: { | ||
label: 'The customer phone number', | ||
required: { | ||
// If email is not provided then a phone number is required | ||
conditions: [{ fieldKey: 'email', operator: 'is', value: undefined }] | ||
} | ||
}, | ||
countryCode: { | ||
label: 'The country code for the customer phone number', | ||
required: { | ||
// If a userIdentifiers.phone is provided then the country code is also required | ||
conditions: [ | ||
{ | ||
fieldKey: 'userIdentifiers.phone', // Dot notation may be used to address object fields. | ||
operator: 'is_not', | ||
value: undefined | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Examples of valid and invalid payloads for the fields above** | ||
|
||
```json | ||
// This payload is valid since the only required field, 'operation', is defined. | ||
{ | ||
"operation": "update", | ||
"email": "[email protected]" | ||
} | ||
``` | ||
|
||
```json | ||
// This payload is invalid since 'creationName' is required because 'operation' is 'create' | ||
{ | ||
"operation": "create", | ||
"email": "[email protected]" | ||
} | ||
// This error will be thrown: | ||
"message": "The root value is missing the required field 'creationName'. The root value must match \"then\" schema." | ||
``` | ||
|
||
```json | ||
// This payload is valid since the two required fields, 'operation' and 'creationName' are defined. | ||
{ | ||
"operation": "create", | ||
"creationName": "readme", | ||
"email": "[email protected]" | ||
} | ||
``` | ||
|
||
```json | ||
// This payload is invalid since 'phone' is required when 'email' is missing. | ||
{ | ||
"operation": "update", | ||
} | ||
// This error will be thrown: | ||
"message": "The root value is missing the required field 'phone'. The root value must match \"then\" schema." | ||
``` | ||
|
||
```json | ||
// This payload is invalid since 'countryCode' is required when 'phone' is defined | ||
{ | ||
"operation": "update", | ||
"userIdentifiers": { "phone": "619-555-5555" } | ||
} | ||
// This error will be thrown: | ||
"message": "The root value is missing the required field 'countryCode'. The root value must match \"then\" schema." | ||
``` | ||
|
||
```json | ||
// This payload is valid since all conditionally required fields are included | ||
{ | ||
"operation": "update", | ||
"userIdentifiers": { | ||
"phone": "619-555-5555", | ||
"countryCode": "+1" | ||
} | ||
} | ||
``` | ||
|
||
## Dynamic Fields | ||
|
||
You can setup a field which dynamically fetches inputs from your destination. These dynamic fields can be used to populate a dropdown menu of options for your users to select. | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @nick-Ag .
Can we include an example with dot notation for a reference to an object.property field?