Skip to content

Commit b13ff06

Browse files
Merge pull request #5 from relogiclabs/develop
Add Deferred Validation and Receiver Features
2 parents 5505d4f + be179e3 commit b13ff06

File tree

337 files changed

+9669
-2122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

337 files changed

+9669
-2122
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ The next example represents an expanded version of the previous one, which bring
6868
%title: "Extended User Profile Dashboard API Response"
6969
%version: 2.0.0
7070
%include: com.relogiclabs.json.schema.positive.ExternalFunctions
71+
72+
%pragma DateDataTypeFormat: "DD-MM-YYYY"
73+
%pragma TimeDataTypeFormat: "DD-MM-YYYY hh:mm:ss"
7174
%pragma IgnoreUndefinedProperties: true
7275

7376
%define $post: {
@@ -99,13 +102,14 @@ The next example represents an expanded version of the previous one, which bring
99102
"id": @range(1, 10000) #integer,
100103
/*username does not allow special characters*/
101104
"username": @regex("[a-z_]{3,30}") #string,
102-
"role": @enum("user", "admin") #string,
105+
"role": @enum("user", "admin") #string &role,
103106
"isActive": #boolean, //user account current status
104-
"registeredAt": @time("DD-MM-YYYY hh:mm:ss") #string,
107+
"registeredAt": @after("01-01-2010 00:00:00") #time,
108+
"dataAccess": @checkAccess(&role) #integer,
105109
"profile": {
106110
"firstName": @regex("[A-Za-z]{3,50}") #string,
107111
"lastName": @regex("[A-Za-z]{3,50}") #string,
108-
"dateOfBirth": @date("DD-MM-YYYY") #string,
112+
"dateOfBirth": @before("01-01-2006") #date,
109113
"age": @range(18, 128) #integer,
110114
"email": @email #string,
111115
"pictureURL": @url #string,
@@ -125,7 +129,7 @@ The next example represents an expanded version of the previous one, which bring
125129
},
126130
"products": #object*($product) #array,
127131
"weather": {
128-
"temperature": @range(-50.0, 60.0) #float,
132+
"temperature": @range(-50, 60) #integer #float,
129133
"isCloudy": #boolean
130134
}
131135
}
@@ -139,6 +143,7 @@ The subsequent JSON sample is an illustrative example that successfully validate
139143
"role": "admin",
140144
"isActive": true,
141145
"registeredAt": "06-09-2023 15:10:30",
146+
"dataAccess": 10,
142147
"profile": {
143148
"firstName": "John",
144149
"lastName": "Doe",
@@ -195,7 +200,7 @@ The subsequent JSON sample is an illustrative example that successfully validate
195200
"id": "p1",
196201
"name": "Smartphone",
197202
"brand": "TechGiant",
198-
"price": 599.99,
203+
"price": 1.99,
199204
"inStock": true,
200205
"specs": null
201206
},
@@ -219,4 +224,4 @@ The subsequent JSON sample is an illustrative example that successfully validate
219224
}
220225
}
221226
```
222-
For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](https://relogiclabs.github.io/JsonSchema-Java/api/index.html).
227+
For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](https://relogiclabs.github.io/JsonSchema-Java/api/index.html).

doc/content/articles/datatypes.md

+42-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++
22
title = 'Data Types'
3-
date = 2023-10-08T09:38:53+06:00
3+
date = 2023-12-04T09:38:53+06:00
44
weight = 6
55
+++
66

@@ -16,19 +16,25 @@ In the schema document, data types are denoted by the `#` prefix. Here is an out
1616
```html
1717
#any
1818
19-
├ #object
20-
├ #array
21-
├ #string
19+
├ #primitive
2220
│ ┬
23-
│ ├ #date
24-
│ └ #time
25-
├ #number
26-
│ ┬
27-
│ ├ #integer
28-
│ ├ #float
29-
│ └ #double
30-
├ #boolean
31-
└ #null
21+
│ ├ #string
22+
│ │ ┬
23+
│ │ └ #datetime
24+
│ │ ┬
25+
│ │ ├ #date
26+
│ │ └ #time
27+
│ ├ #number
28+
│ │ ┬
29+
│ │ ├ #integer
30+
│ │ ├ #float
31+
│ │ └ #double
32+
│ ├ #boolean
33+
│ └ #null
34+
└ #composite
35+
36+
├ #array
37+
└ #object
3238
```
3339

3440
### The Any Data Type
@@ -37,10 +43,16 @@ This data type accepts any valid JSON value that conforms to the JSON standard.
3743
#any
3844
```
3945

40-
### The Object Data Type
41-
This data type represents the JSON object type and accepts any JSON object specified by the JSON standard. The specification document for JSON provides details about the different syntax and forms of JSON objects. Following is the syntax for specifying this data type:
46+
### The Primitive Data Type
47+
This serves as the foundational data type for all non-composite or primitive JSON values. While it is not intended for direct use in a schema, it organizes common functionalities across other sub-data types. Nevertheless, it remains valid for use, as illustrated by the following syntax:
4248
```html
43-
#object
49+
#primitive
50+
```
51+
52+
### The Composite Data Type
53+
As the parent data type for two kinds of composite JSON values, namely arrays and objects, this composite type consists of zero or more JSON values. It is not designed to be used in a schema but rather the organization of shared functionalities among other sub-data types. Despite this, it is still valid for use, demonstrated by the following syntax:
54+
```html
55+
#composite
4456
```
4557

4658
### The Array Data Type
@@ -49,20 +61,32 @@ This data type represents the JSON array type and accepts any JSON array specifi
4961
#array
5062
```
5163

64+
### The Object Data Type
65+
This data type represents the JSON object type and accepts any JSON object specified by the JSON standard. The specification document for JSON provides details about the different syntax and forms of JSON objects. Following is the syntax for specifying this data type:
66+
```html
67+
#object
68+
```
69+
5270
### The String Data Type
5371
This is one of the most commonly used data types in a JSON document, designed to accept any JSON string as specified by the JSON standard. The syntax for specifying this data type is as follows:
5472
```html
5573
#string
5674
```
5775

76+
### The Date Time Data Type
77+
The date-time data type serves as the parent data type for both date and time types. It is a subtype of JSON string type and thus formatted as per the JSON string specification. It is not intended to be used directly in a schema, but it provides common functionality for both date and time types.
78+
```html
79+
#datetime
80+
```
81+
5882
### The Date Data Type
59-
The date data type accepts only a type of string which represent a date specified by ISO 8601 standard (date part only). It is a subtype of string data type and thus formatted as per the JSON string specification. Detailed explanations of the ISO 8601 standard can be found in this [document](https://www.iso.org/iso-8601-date-and-time-format.html). Furthermore, you can refer to this [document](/JsonSchema-DotNet/articles/datetime.html) for a detailed description of the date pattern associated with this data type. To define this data type in schema, use the following syntax:
83+
The date data type accepts a string representation of a date, conforming to the ISO 8601 standard (date part only). This is the default configuration, which can be modified using the directive described [here](/JsonSchema-Java/articles/directives). It is a subtype of date-time type and thus also formatted as per the JSON string specification. Detailed explanations of the ISO 8601 standard can be found in this [document](https://www.iso.org/iso-8601-date-and-time-format.html). Furthermore, you can refer to this [document](/JsonSchema-Java/articles/datetime) for a detailed description of the date pattern associated with this data type. To define this data type in schema, use the following syntax:
6084
```html
6185
#date
6286
```
6387

6488
### The Time Data Type
65-
The time data type only accepts strings representing date-time (including both date and time), in accordance with the ISO 8601 standard. Similar to the date data type, it is a subtype of string data type and thus formatted as per the JSON string specification. Here is the ISO 8601 standard [document](https://www.iso.org/iso-8601-date-and-time-format.html), which contains detailed explanations. Furthermore, you can refer to this [document](/JsonSchema-DotNet/articles/datetime.html) for a detailed description of the date-time pattern associated with this data type. To define this data type in schema, use the following syntax:
89+
The time data type accepts a string representation of a time (including both date and time parts), in accordance with the ISO 8601 standard. This default configuration can be modified using the directive described [here](/JsonSchema-Java/articles/directives). Similar to the date data type, it is a subtype of date-time data type and thus also formatted as per the JSON string specification. Here is the ISO 8601 standard [document](https://www.iso.org/iso-8601-date-and-time-format.html), which contains detailed explanations. Furthermore, you can refer to this [document](/JsonSchema-Java/articles/datetime) for a detailed description of the date-time pattern associated with this data type. To define this data type in schema, use the following syntax:
6690
```html
6791
#time
6892
```

doc/content/articles/directives.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++
22
title = 'Directives'
3-
date = 2023-10-08T09:38:53+06:00
3+
date = 2023-12-04T09:38:53+06:00
44
weight = 4
55
+++
66

@@ -42,6 +42,18 @@ The default value of this directive is `false`, which means that by default, und
4242
%pragma IgnoreUndefinedProperties: true
4343
```
4444

45+
### Date Data Type Format
46+
The `DateDataTypeFormat` pragma directive enables you to customize the default format of the `#date` data type. By default, the `#date` data type follows the ISO 8601 standard, precisely using the format `YYYY-MM-DD`. Additional details on date-time patterns and formats are available [here](/JsonSchema-Java/articles/datetime). The subsequent example illustrates the process of defining a customized date format for the `#date` data type:
47+
```js
48+
%pragma DateDataTypeFormat: "DD-MM-YYYY"
49+
```
50+
51+
### Time Data Type Format
52+
To customize the default format of the `#time` data type, utilize the `TimeDataTypeFormat` pragma directive. By default, the `#time` data type follows the ISO 8601 standard, precisely in the format `YYYY-MM-DD'T'hh:mm:ss.FZZ`. Further information on date-time patterns and formats can be found [here](/JsonSchema-Java/articles/datetime). The following example demonstrates how to specify a customized time format for the `#time` data type:
53+
```js
54+
%pragma TimeDataTypeFormat: "DD-MM-YYYY hh:mm:ss"
55+
```
56+
4557
### Floating Point Tolerance
4658
The `FloatingPointTolerance` pragma directive allows you to define the tolerance level for relative errors in floating-point numbers during calculations and computations carried out by the validation process. By default, this directive is set to `1E-10`, indicating a small tolerance. However, you have the flexibility to adjust this value to any desired number. To specify a custom tolerance value of `1E-07`, you can use the following notation as an example:
4759
```js

doc/content/articles/functions.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++
22
title = 'Functions'
3-
date = 2023-10-08T09:38:53+06:00
3+
date = 2023-12-04T09:38:53+06:00
44
weight = 7
55
+++
66

@@ -184,13 +184,51 @@ Validates whether the `target` string is a valid phone number. It follows the IT
184184
```stylus
185185
#string target - @date(pattern)
186186
```
187-
Validates that the `target` string matches the date and time pattern specified by the `pattern` parameter. It fully supports the ISO 8601 date and time format. Beyond this standard, it also allows custom date and time formats, ensuring compatibility with various systems and meeting diverse users and businesses requirements. This [document](/JsonSchema-DotNet/articles/datetime.html) provides a comprehensive overview of the date-time custom patterns.
187+
Validates that the `target` string matches the date and time pattern specified by the `pattern` parameter. It fully supports the ISO 8601 date and time format. Beyond this standard, it also allows custom date and time formats, ensuring compatibility with various systems and meeting diverse users and businesses requirements. This [document](/JsonSchema-Java/articles/datetime) provides a comprehensive overview of the date-time custom patterns.
188188

189189
```
190190
#string target - @time(pattern)
191191
```
192-
Both the `@date` and `@time` functions support a complete range of date-time patterns, enabling the precise definition of any date and time scenario. Therefore, these functions can be used interchangeably. When the sole consideration is the date or day of the month in a year, employing the `@date` function is the more convenient choice. In contrast, when it becomes necessary to specify a particular time on a date, the `@time` function is the more appropriate option. To learn more about date-time patterns, please refer to [this page](/JsonSchema-DotNet/articles/datetime.html).
192+
Both the `@date` and `@time` functions support a complete range of date-time patterns, enabling the precise definition of any date and time scenario. Therefore, these functions can be used interchangeably. When the sole consideration is the date or day of the month in a year, employing the `@date` function is the more convenient choice. In contrast, when it becomes necessary to specify a particular time on a date, the `@time` function is the more appropriate option. To learn more about date-time patterns, please refer to [this page](/JsonSchema-Java/articles/datetime).
193193

194+
### Date and Time Range
195+
```stylus
196+
#datetime target - @range(#string start, #string end)
197+
```
198+
Validates that the `target` date-time satisfies the range requirement specified by the parameters. It checks that the `target` date-time is from or after the `start` date-time specified and simultaneously until and before the `end` date-time specified. If not, a validation error will generate. The `start` and `end` parameters must be the string representation of the `target` data type, which can either be a `#date` or `#time` type.
199+
200+
If either the parameter values for `start` or `end` are unspecified or undefined, the `undefined` symbol `!` can be used in place of either of these parameters. The following examples illustrate the various use cases of the `@range` function of the two variations described above, for the target type:
201+
202+
| Ues Cases | Valid Values | Invalid Values |
203+
|------------------------------------------------------------------|--------------------------------------------------------|------------------------------------------|
204+
| `@range("2010-01-01", "2010-12-31")` | `2010-01-01`; `2010-06-30`; `2010-12-31` | `2009-12-31`; `2011-01-01`; `2030-11-05` |
205+
| `@range("2010-01-01T00:00:00.000Z", "2010-12-31T23:59:59.999Z")` | `2010-01-01T00:00:00.000Z`; `2010-12-31T23:59:59.999Z` | `2009-12-31T23:59:59.999Z` |
206+
| `@range(!, "2010-12-31")` | `1990-01-01`; `2010-12-31` | `2011-01-01`; `2030-11-05` |
207+
| `@range("2010-01-01", !)` | `2010-01-01`; `2030-11-05` | `1990-01-01`; `2009-12-31` |
208+
209+
### Date and Time Start
210+
```stylus
211+
#datetime target - @start(#string reference)
212+
```
213+
Validates that the `target` date-time starts from or finds after the specified `reference` date-time parameter. If the `target` date-time finds before the `reference` date-time, a validation error is triggered. The `reference` parameter must be the string representation of the `target` data type, which can either be a `#date` or `#time` type.
214+
215+
### Date and Time End
216+
```stylus
217+
#datetime target - @end(#string reference)
218+
```
219+
Validates that the `target` date-time finds before or ends at the specified `reference` date-time parameter. If the `target` date-time finds after the `reference` date-time, a validation error is triggered. The `reference` parameter must be the string representation of the `target` data type, which can either be a `#date` or `#time` type.
220+
221+
### Date and Time Before
222+
```stylus
223+
#datetime target - @before(#string reference)
224+
```
225+
Validates that the `target` date-time is exclusively before the `reference` date-time. If the `target` date-time finds on or after the `reference` date-time, a validation error is triggered. The `reference` parameter must be the string representation of the `target` data type, which can either be a `#date` or `#time` type.
226+
227+
### Date and Time After
228+
```stylus
229+
#datetime target - @after(#string reference)
230+
```
231+
Validates that the `target` date-time is exclusively after the `reference` date-time. If the `target` date-time finds on or before the `reference` date-time, a validation error is triggered. The `reference` parameter must be the string representation of the `target` data type, which can either be a `#date` or `#time` type.
194232

195233
### Number Positive
196234
```stylus

doc/content/articles/quickstart.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ Actual (Json Line: 3:14): found #string inferred by "not number"
160160
at org.example.SampleSchema.checkIsValid(SampleSchema.java:64)
161161
at org.example.Main.main(Main.java:5)
162162
```
163-
For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-Java/api/index.html).
163+
For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-Java/api/index.html).

doc/content/articles/sourcebuild.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++
22
title = 'Source Build'
3-
date = 2023-11-03T09:38:53+06:00
3+
date = 2023-12-04T09:38:53+06:00
44
weight = 9
55
+++
66

doc/content/articles/specification.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ validator
7979
alias-name
8080

8181
validator-main
82-
value-opt functions-opt datatypes-opt this-opt
82+
value-opt functions-opt datatypes-opt receivers-opt this-opt
8383

8484
value-opt
8585
''
@@ -98,20 +98,24 @@ functions
9898
function functions
9999

100100
function
101-
function-name function-params-opt
101+
function-name function-args-opt
102102

103103
function-name
104104
'@' identifier
105105
'@' identifier '*'
106106

107-
function-params-opt
107+
function-args-opt
108108
''
109109
'(' ')'
110-
'(' function-params ')'
110+
'(' function-args ')'
111111

112-
function-params
112+
function-args
113+
function-arg
114+
function-arg ',' function-args
115+
116+
function-arg
113117
value
114-
value ',' function-params
118+
receiver
115119

116120
datatypes-opt
117121
''
@@ -121,7 +125,7 @@ datatypes
121125
datatype datatypes
122126

123127
datatype
124-
datatype-name datatype-param-opt
128+
datatype-name datatype-arg-opt
125129

126130
datatype-name
127131
'#' alphas
@@ -130,10 +134,20 @@ datatype-name
130134
alphas
131135
alpha alphas
132136

133-
datatype-param-opt
137+
datatype-arg-opt
134138
''
135139
'(' alias-name ')'
136140

141+
receivers-opt
142+
''
143+
receivers
144+
145+
receivers
146+
receiver receivers
147+
148+
receiver
149+
'&' identifier
150+
137151
this-opt
138152
''
139153
'?'

0 commit comments

Comments
 (0)