Skip to content

Commit 68f8ff5

Browse files
committed
Update project documentations
1 parent 7be9177 commit 68f8ff5

File tree

246 files changed

+2715
-2446
lines changed

Some content is hidden

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

246 files changed

+2715
-2446
lines changed

doc/content/articles/components.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
+++
2+
title = 'Components'
3+
date = 2023-12-15T09:38:53+06:00
4+
weight = 9
5+
+++
6+
7+
# Reusable Components
8+
A schema component, also known as a reusable schema fragment or sub-schema, plays a vital role in improving readability, reducing redundancy, and organizing the structure of a Schema document. In JSON validation, a schema component or fragment defines a validation rule that can be recursively composed of multiple nested validation rules, collectively specifying the expected and valid format of a JSON structure.
9+
10+
These schema components are utilized as extensions of data type validation, as basic data types have a very limited ability to validate the internal structure of a composite JSON value or construct. Therefore, a data type is parameterized with a component to validate the internal structure of such composite JSON constructs. Moreover, schema components can be referenced from any other part of the Schema document, effectively reducing redundancy and enhancing reusability. The following example defines a simple schema component named `$component` where the validation rule describes an object structure with two key-value pairs:
11+
```js
12+
%define $component: { "key1": #integer, "key2": #string }
13+
```
14+
15+
A composite JSON construct is created by combining multiple values as defined by the JSON specification. These nested values can range from simple, like numbers or strings, to more complex, such as arrays or objects. While simple nested values of a composite construct can be validated using only nested data types and functions, handling hierarchical composite constructs with multiple layers of nested structures requires defining schema components.
16+
17+
The second and third rows of the following table illustrate how the component validates the value associated with the data type for which it is used as a parameter. If the associated data type is direct, the component validates the target value itself. Conversely, if the associated data type is nested, the component validates each of the nested values comprising the composite target construct.
18+
19+
| SN | Component Example | Valid Json |
20+
|----|----------------------------------------------------------------------------------|--------------------|
21+
| 1 | `@range*(1, 10) @length(5) #integer* #array` | `[1, 3, 5, 8, 10]` |
22+
| 2 | `%define $cmp: @range*(1, 10) #integer*` <br> `%schema: @length(5) #array($cmp)` | `[1, 3, 5, 8, 10]` |
23+
| 3 | `%define $cmp: @range(1, 10)` <br> `%schema: @length(5) #integer*($cmp) #array` | `[1, 3, 5, 8, 10]` |
24+
25+
In the above table, all three rows have identical validation constraints for the input JSON array. This demonstrates that when dealing with simple and primitive nested values in a composite JSON construct, preferring the nested data types and functions is more convenient due to their simplicity and conciseness. However, in cases where the nested values are complex and composite, the schema component syntax becomes more suitable. The following example illustrates how the component syntax can be used to validate elements of a JSON array that are not as straightforward as the previous examples:
26+
```js
27+
%define $article: {
28+
"id": @range(1, 100) #integer,
29+
"title": @length(10, 100) #string,
30+
"preview": @length(30, 1000) #string,
31+
"tags": @length*(3, 30) @length(1, 5) #string* #array
32+
} #object
33+
34+
%schema: @length(1, 10) #object*($article) #array
35+
```
36+
37+
In practical scenarios, JSON arrays often hold multiple composite JSON constructs as elements, typically sharing a recurring pattern and structure similar to the example above. To facilitate the validation of such elements, using schema components is highly effective. By defining a reusable schema component, one can improve readability, conciseness, and organization of the Schema document with such recurring structures. For instance, consider the following example of a JSON document which is valid against the Schema example above:
38+
```js
39+
[
40+
{
41+
"id": 1,
42+
"title": "Getting Started",
43+
"preview": "This guide will show you through the essential steps to quickly...",
44+
"tags": ["JSON", "Json Schema", "Quick Start"]
45+
},
46+
{
47+
"id": 2,
48+
"title": "Validation Syntax",
49+
"preview": "A JSON document is a structured data format used for the exchange...",
50+
"tags": ["JSON", "Json Schema", "Validation Syntax"]
51+
},
52+
{
53+
"id": 3,
54+
"title": "Constraint Functions",
55+
"preview": "This document serves as a brief overview, providing key insights into...",
56+
"tags": ["JSON", "Json Schema", "Constraint Functions"]
57+
}
58+
]
59+
```

doc/content/articles/directives.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ The `IgnoreObjectPropertyOrder` pragma directive provides a means to enforce a s
6767
```
6868

6969
## Definition / Define Directive
70-
This feature in JSON schemas allows you to define a name for a fragment of schema or validation rules, which can be referenced from various parts of your schema. This means that if you encounter similar validation requirements in different sections of your schema, you can conveniently refer to the named fragment instead of duplicating the same validation rules.
70+
This feature in JSON schemas allows you to define a name for a component or fragment of schema or validation rules, which can be referenced from various parts of your schema. This means that if you encounter similar validation requirements in different sections of your schema, you can conveniently refer to the named component instead of duplicating the same validation rules.
7171

72-
By providing clear and descriptive names for these validation rules or sub-schemas, you enhance the overall clarity and context of your schema. This clarity not only makes it easier to understand the structure and intent of the schema but also contributes to keeping your complex schema well-organized, concise, and more manageable.
72+
By providing clear and descriptive names for these validation rules or sub-schemas, you can enhance the overall clarity and context of your schema. This clarity not only makes it easier to understand the structure and intent of the schema but also contributes to keeping your complex schema well-organized, concise, and more manageable. For more information about the schema component syntax and format, please refer to the documentation [here](/JsonSchema-Java/articles/components).
7373

7474
The name or alias of the directive is always start with `$` which also refers to that they are named fragment defined elsewhere in the schema. Here is a simple example of how to use this directive:
7575
```js

doc/content/articles/functions.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,12 @@ Validates that the `target` number is less than or equal to the `maximum` number
121121
| `@maximum(10.5)` | `10.50`; `10.49`; `-1000.1` | `10.51`; `11.0`; `1000.1` |
122122
| `@maximum(0, true)` | `-0.001`; `-1.01`; `-1000.1` | `0`; `0.01`; `100.1` |
123123

124-
### String Enum
124+
### Enum String and Number
125125
```stylus
126126
#string target - @enum(#string... items)
127-
```
128-
Validates that the `target` string is equal to one of the strings specified by the `items` parameter. If not, a validation error will generate.
129-
130-
### Number Enum
131-
```stylus
132127
#number target - @enum(#number... items)
133128
```
134-
Validates that the `target` number is equal to one of the numbers specified by the `items` parameter. If not, a validation error will generate.
129+
Validates that the `target` string or number is equal to one of the strings or numbers respectively, specified by the `items` parameter. If not, a validation error will generate.
135130

136131
### Array Elements
137132
```stylus

doc/content/articles/intro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ JSON, short for JavaScript Object Notation, is one of the most widely used data
1515
* <font size="4">[Data Types & Validation](/JsonSchema-Java/articles/datatypes)</font>
1616
* <font size="4">[Functions & Validation](/JsonSchema-Java/articles/functions)</font>
1717
* <font size="4">[Date & Time Patterns](/JsonSchema-Java/articles/datetime)</font>
18+
* <font size="4">[Reusable Components of Validation](/JsonSchema-Java/articles/components)</font>
1819
* <font size="4">[Build from Source Code](/JsonSchema-Java/articles/sourcebuild)</font>
1920
* <font size="4">[API Reference Documentation](/JsonSchema-Java/api/index.html)</font>
2021

doc/content/articles/quickstart.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,14 @@ com.relogiclabs.json.schema.exception.JsonSchemaException: DTYP04: Data type mis
147147
Expected (Schema Line: 6:31): data type #integer
148148
Actual (Json Line: 3:14): found #string inferred by "not number"
149149

150-
at com.relogiclabs.json.schema.type.JDataType.matchForReport(JDataType.java:90)
151-
at com.relogiclabs.json.schema.type.JDataType.matchForReport(JDataType.java:72)
152-
at com.relogiclabs.json.schema.type.JValidator.lambda$matchDataType$4(JValidator.java:74)
153-
at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:74)
154-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:64)
150+
at com.relogiclabs.json.schema.tree.ExceptionRegistry.failWith(ExceptionRegistry.java:31)
151+
at com.relogiclabs.json.schema.type.JNode.failWith(JNode.java:75)
152+
at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:89)
153+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:78)
155154
at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57)
156-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:59)
155+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:73)
157156
at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57)
158-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:59)
157+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:73)
159158
at com.relogiclabs.json.schema.type.JRoot.match(JRoot.java:50)
160159
at com.relogiclabs.json.schema.tree.SchemaTree.match(SchemaTree.java:33)
161160
at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:61)

doc/content/articles/sourcebuild.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+++
22
title = 'Source Build'
33
date = 2023-12-04T09:38:53+06:00
4-
weight = 9
4+
weight = 10
55
+++
66

77
# Build from Source Code
@@ -158,15 +158,14 @@ com.relogiclabs.json.schema.exception.JsonSchemaException: DTYP04: Data type mis
158158
Expected (Schema Line: 6:31): data type #integer
159159
Actual (Json Line: 3:14): found #string inferred by "not number"
160160

161-
at com.relogiclabs.json.schema.type.JDataType.matchForReport(JDataType.java:90)
162-
at com.relogiclabs.json.schema.type.JDataType.matchForReport(JDataType.java:72)
163-
at com.relogiclabs.json.schema.type.JValidator.lambda$matchDataType$4(JValidator.java:74)
164-
at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:74)
165-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:64)
161+
at com.relogiclabs.json.schema.tree.ExceptionRegistry.failWith(ExceptionRegistry.java:31)
162+
at com.relogiclabs.json.schema.type.JNode.failWith(JNode.java:75)
163+
at com.relogiclabs.json.schema.type.JValidator.matchDataType(JValidator.java:89)
164+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:78)
166165
at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57)
167-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:59)
166+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:73)
168167
at com.relogiclabs.json.schema.type.JObject.match(JObject.java:57)
169-
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:59)
168+
at com.relogiclabs.json.schema.type.JValidator.match(JValidator.java:73)
170169
at com.relogiclabs.json.schema.type.JRoot.match(JRoot.java:50)
171170
at com.relogiclabs.json.schema.tree.SchemaTree.match(SchemaTree.java:33)
172171
at com.relogiclabs.json.schema.JsonAssert.isValid(JsonAssert.java:61)

0 commit comments

Comments
 (0)