rest-in-contract-dsl
Contract script DSL for rest-in-contract
Base Types
Middlewares
The base abstract type of all dsl functions.
Feature
The base abstract type of all features implemented by a dsl function.
Evaluator
A dsl function feature which allow evaluating a value from the context.
Comparable
A dsl function feature which allow comparing or validating with a target value.
Mockable
A dsl function feature which allow mocking value.
DSL functions
float
Representing a float number value.
Implementing features
Comparable, Mockable
Options
Option key | Description | Required | Example |
---|---|---|---|
lt | It defines the "less than" criterion. This criterion is used for comparing values and mocking values. | optional | 0.1 |
lte | It defines the "less than equal" criterion. This criterion is used for comparing values and mocking values. | optional | 0.1 |
gt | It defines the "greater than" criterion. This criterion is used for comparing values and mocking values. | optional | 0.9 |
gte | It defines the "greater than equal" criterion. This criterion is used for comparing values and mocking values. | optional | 0.9 |
Sample
var fnInstance = ; fnInstance;//false;fnInstance;//false;fnInstance;//falsefnInstance;//truefnInstance;//falsefnInstance;//false fnInstance;//0.5800135823905961
integer
Representing an integer number value.
Implementing features
Comparable, Mockable
Options
Option key | Description | Required | Example |
---|---|---|---|
lt | It defines the "less than" criterion. This criterion is used for comparing values and mocking values. | optional | 1 |
lte | It defines the "less than equal" criterion. This criterion is used for comparing values and mocking values. | optional | 1 |
gt | It defines the "greater than" criterion. This criterion is used for comparing values and mocking values. | optional | 10 |
gte | It defines the "greater than equal" criterion. This criterion is used for comparing values and mocking values. | optional | 10 |
Sample
var fnInstance = ; fnInstance;//false;fnInstance;//false;fnInstance;//falsefnInstance;//truefnInstance;//falsefnInstance;//false fnInstance;//2fnInstance;//3fnInstance;//3fnInstance;//4 var fnInstance = ; fnInstance;//false;fnInstance;//false;fnInstance;//truefnInstance;//truefnInstance;//truefnInstance;//false fnInstance;//5fnInstance;//2fnInstance;//4fnInstance;//4fnInstance;//1
date
Representing a date value.
Implementing features
Comparable, Mockable
Options
Option key | Description | Required | Example |
---|---|---|---|
format | It defines the date format which is used for comparing values and mocking values | optional | 'YYYY-MM-DD HH:mm:ss' |
type | It may either be "past", "future" or "betwen". Like the worings said, it defines how it would behave for comparing values and mocking values. "past" would only allow date in the past. "future" would only allow date in the future. "between" allow date value between a range. | optional | "past", "future" or "betwen" |
from | It defines the "from" criterion, which is the minimum aceptable value. This criterion is used for comparing values and mocking values. | optional | 10 |
to | It defines the "to" criterion, which is the maximum aceptable value. This criterion is used for comparing values and mocking values. | optional | 10 |
Sample
var fnInstance = ; fnInstance;//false;fnInstance;//false;fnInstance;//true;fnInstance;//true;fnInstance;//true;fnInstance;//false; mockValue = fnInstance;//2000-06-30 21:25:25mockValue = fnInstance;//2001-07-19 14:21:38mockValue = fnInstance;//2001-08-10 18:43:24mockValue = fnInstance;//1999-10-06 12:05:08mockValue = fnInstance;//2000-10-31 03:32:38
regex
Representing a string pattern value.
Implementing features
Comparable, Mockable
Function arguments
regex(pattern)
Argument | Description | Required | Example |
---|---|---|---|
pattern | The string representation of Regex pattern | mandatory | "[0-9]{4},[a-z]{6},[A-Z]{3}" |
Sample
var fnInstance = ;fnInstance);//truefnInstance);//false fnInstance;//9345,wpaump,JEUfnInstance;//4576,fcwlfz,NAPfnInstance;//3047,drfitz,OQCfnInstance;//5510,vpymny,SECfnInstance;//1154,mgppdb,KYW
text
Representing a text value.
Implementing features
Comparable, Mockable
Options
Option key | Description | Required | Example |
---|---|---|---|
type | It defines the type of text criterion. It may be either "word", "words", "sentence" or "paragraphs". | optional | either "word", "words", "sentence" or "paragraphs" |
Sample
var fnInstance = ;fnInstance;//true;fnInstance;//"facilis" fnInstance = ;fnInstance;//true;fnInstance;//"voluptatum porro soluta" fnInstance = ;fnInstance;//true;fnInstance;//"Dolorem ut eum hic." fnInstance = ;fnInstance;//true;fnInstance;//false;fnInstance;//"Omnis ipsam quis. Sed quo molestias. ......"
name
Representing a name value.
Implementing features
Comparable, Mockable
Sample
var fnInstance = ;fnInstance;//true;fnInstance;//"Jacinto Jones"
Representing an email value.
Implementing features
Comparable, Mockable
Sample
var fnInstance = ;fnInstance;//true;fnInstance;//"Hettie56@yahoo.com"
phone
Representing a phone value.
Implementing features
Comparable, Mockable
Sample
var fnInstance = ;fnInstance);//truefnInstance);//truefnInstance);//truefnInstance);//truefnInstance);//truefnInstance);//truefnInstance);//falsefnInstance);//falsefnInstance);//true fnInstance;//1-018-789-4795 x9374fnInstance;//(953) 814-4850fnInstance;//(788) 031-9558fnInstance;//(567) 476-8360 x436fnInstance;//1-430-650-6285 x861
address
Representing an address value.
Implementing features
Comparable, Mockable
Sample
var fnInstance = ;fnInstance);//truefnInstance);//true fnInstance;//"881 Hagenes Cape"fnInstance;//"74087 Nayeli Trace"fnInstance;//"087 Heller Divide"fnInstance;//"495 Parisian Lock"fnInstance;//"2458 Jeromy Village"
uuid4
Representing an uuid4 value.
Implementing features
Comparable, Mockable
Sample
var fnInstance = ;fnInstance);//truefnInstance);//true fnInstance;//"04072af7-b00b-4046-b669-42eeb17fa8da"fnInstance;//"0bd7cfcf-2cd0-48c4-bd4b-6e36e2b3f6cb"fnInstance;//"b4a8512c-addf-4596-82ea-d0a3e385b016"
jsonpath
Evaluating value from context's json path.
Implementing features
Evaluator
Function arguments
jsonpath(expression)
Argument | Description | Required | Example |
---|---|---|---|
expression | The jsonpath expression | mandatory | "$.req.body" |
Sample
var fnInstance = ; fnInstance;//100 fnInstance;//"abc"
sum
Evaluating sum of values
Implementing features
Evaluator
Function arguments
sum(values...)
Argument | Description | Required | Example |
---|---|---|---|
values... | The function arguments are the input values for evaluating the sum | mandatory | 1,2,3,4,... |
Sample
var fnInstance = ;fnInstance;//1256 var fnInstance = ;fnInstance;//55 var fnInstance = ;fnInstance;//101
subtract
Evaluating subtract result of two values
Implementing features
Evaluator
Function arguments
subtract(a, b)
Argument | Description | Required | Example |
---|---|---|---|
a | The number which would be subtracted by b | mandatory | 10 |
b | The number which would be subtracted from a | mandatory | 3 |
Sample
var fnInstance = ;fnInstance;//7 var fnInstance = ;fnInstance;//99
multiply
Evaluating multiply result of values
Implementing features
Evaluator
Function arguments
multiply(values...)
Argument | Description | Required | Example |
---|---|---|---|
values... | The function arguments are the input values for evaluating the multiply result | mandatory | 1,2,3,4,... |
Sample
var fnInstance = ;fnInstance;//80 var fnInstance = ;fnInstance;//120 var fnInstance = ;fnInstance;//200
divide
Evaluating divide result of two values
Implementing features
Evaluator
Function arguments
divide(a, b)
Argument | Description | Required | Example |
---|---|---|---|
a | The number which would be divided by b | mandatory | 12 |
b | The number which would be divided from a | mandatory | 3 |
Sample
var fnInstance = ;fnInstance;//4 var fnInstance = ;fnInstance;//4
anyOf
Allow comparing value or mocking value which is any of the listed values.
Implementing features
Comparable, Mockable
Function arguments
anyOf(values...)
Argument | Description | Required | Example |
---|---|---|---|
values... | The function arguments are the possible values. | mandatory | 'a', 'b', 'c', ... |
Sample
var fnInstance = ;fnInstance;//truefnInstance;//truefnInstance;//truefnInstance;//false fnInstance;//"a"fnInstance;//"c"fnInstance;//"c"fnInstance;//"b"
notAnyOf
Allow comparing value which is not any of the listed values.
Implementing features
Comparable
Function arguments
notAnyOf(values...)
Argument | Description | Required | Example |
---|---|---|---|
values... | The function arguments are the values that shouldn't be | mandatory | 'a', 'b', 'c', ... |
Sample
var fnInstance = ;fnInstance;//falsefnInstance;//falsefnInstance;//falsefnInstance;//true
evalContext
Evaluating value from the context
Implementing features
Evaluator
Function arguments
evalContext(evalFunction)
Argument | Description | Required | Example |
---|---|---|---|
evalFunction | The function for evaluating context | mandatory | function(context){...} |
Sample
var fnInstance = ; fnInstance;//3 var fnInstance = ; fnInstance;//"Hello Mary"
value
Evaluating "Stub" value or "Test" value. During evaluating value, it will look up the context's "isTest" value. If "isTest" is true, then it will evaluating test value, otherwise stub value.
Implementing features
Evaluator
Options
Option key | Description | Required | Example |
---|---|---|---|
stub | The value being evaluated when evaluating stub value | mandatory | any |
test | The value being evaluated when evaluating test value | mandatory | any |
Sample
var fnInstance = ; fnInstance;//"a"fnInstance;//"b" var fnInstance = ; fnInstance;//"abc" fnInstance;//"123"