Skip to content

Commit afe44d1

Browse files
committed
Update project documentations
1 parent 0b6b121 commit afe44d1

File tree

12 files changed

+69
-59
lines changed

12 files changed

+69
-59
lines changed

JsonSchema.Tests/JsonSchema.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<Description>This project contains test cases for JsonSchema project.</Description>
66
<Authors>Relogic Labs</Authors>
77
<Company>Relogic Labs</Company>
8-
<Version>1.12.0</Version>
9-
<AssemblyVersion>1.12.0</AssemblyVersion>
8+
<Version>1.12.1</Version>
9+
<AssemblyVersion>1.12.1</AssemblyVersion>
1010
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
1111
<NeutralLanguage>en</NeutralLanguage>
1212
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0</TargetFrameworks>

JsonSchema.Tests/RelogicLabs/JsonSchema/Tests/External/ExternalFunctions.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public bool Even(JNumber target)
2424
bool result = target % 2 == 0;
2525
if(!result) return FailWith(new JsonSchemaException(
2626
new ErrorDetail(EVENFUNC01, "Number is not even"),
27-
new ExpectedDetail(target, "even number"),
27+
new ExpectedDetail(Function, "even number"),
2828
new ActualDetail(target, $"number {target} is odd")));
2929
return true;
3030
}
@@ -43,7 +43,7 @@ public bool CheckAccess(JInteger target, JReceiver userRole)
4343
string role = userRole.GetValueNode<JString>();
4444
if(role == "user" && target > 5) return FailWith(new JsonSchemaException(
4545
new ErrorDetail(ERRACCESS01, "Data access incompatible with 'use' role"),
46-
new ExpectedDetail(target, "an access at most 5 for 'user' role"),
46+
new ExpectedDetail(Function, "an access at most 5 for 'user' role"),
4747
new ActualDetail(target, $"found access {target} which is greater than 5")));
4848
return true;
4949
}
@@ -55,7 +55,7 @@ public bool Condition(JInteger target, JReceiver receiver)
5555
bool result = threshold < target;
5656
if(!result) return FailWith(new JsonSchemaException(
5757
new ErrorDetail(CONDFUNC01, "Number does not satisfy the condition"),
58-
new ExpectedDetail(target, $"a number > {threshold} of '{receiver.Name}'"),
58+
new ExpectedDetail(Function, $"a number > {threshold} of '{receiver.Name}'"),
5959
new ActualDetail(target, $"found number {target} <= {threshold}")));
6060
return result;
6161
}
@@ -69,13 +69,15 @@ public bool ConditionAll(JInteger target, JReceiver receiver)
6969
bool result = list.All(i => i < target);
7070
if(!result) return FailWith(new JsonSchemaException(
7171
new ErrorDetail(CONDFUNC02, "Number does not satisfy the condition"),
72-
new ExpectedDetail(target, $"a number > any of {values} of '{receiver.Name}'"),
72+
new ExpectedDetail(Function, $"a number > any of {values} of '{receiver.Name}'"),
7373
new ActualDetail(target, $"found number {target} <= some of {values}")));
7474
return true;
7575
}
7676

7777
public FutureValidator SumEqual(JInteger target, JReceiver receiver)
7878
{
79+
// Capture the current value of the function for future lambda
80+
var caller = Function;
7981
return () =>
8082
{
8183
var values = receiver.GetValueNodes<JInteger>();
@@ -86,14 +88,16 @@ public FutureValidator SumEqual(JInteger target, JReceiver receiver)
8688
if(result != target)
8789
return FailWith(new JsonSchemaException(
8890
new ErrorDetail(SUMEQUAL01, $"Number != sum of {expression} = {result}"),
89-
new ExpectedDetail(target, $"a number = sum of numbers {result}"),
91+
new ExpectedDetail(caller, $"a number = sum of numbers {result}"),
9092
new ActualDetail(target, $"found number {target} != {result}")));
9193
return true;
9294
};
9395
}
9496

9597
public FutureValidator Minmax(JInteger target, JReceiver min, JReceiver max)
9698
{
99+
// Capture the current value of the function for future lambda
100+
var caller = Function;
97101
return () =>
98102
{
99103
var intMin = min.GetValueNode<JInteger>();
@@ -104,7 +108,7 @@ public FutureValidator Minmax(JInteger target, JReceiver min, JReceiver max)
104108
if(!result)
105109
return FailWith(new JsonSchemaException(
106110
new ErrorDetail(MINMAX01, "Number is outside of range"),
107-
new ExpectedDetail(target, $"a number in range [{intMin}, {intMax}]"),
111+
new ExpectedDetail(caller, $"a number in range [{intMin}, {intMax}]"),
108112
new ActualDetail(target, $"found number {target} not in range")));
109113
return true;
110114
};

JsonSchema/JsonSchema.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<AssemblyName>RelogicLabs.JsonSchema</AssemblyName>
99
<Authors>Relogic Labs</Authors>
1010
<Company>Relogic Labs</Company>
11-
<Version>1.12.0</Version>
12-
<PackageVersion>1.12.0</PackageVersion>
13-
<AssemblyVersion>1.12.0</AssemblyVersion>
14-
<PackageTags>JsonSchema;Schema;Json;Validation;Assert;Test</PackageTags>
11+
<Version>1.12.1</Version>
12+
<PackageVersion>1.12.1</PackageVersion>
13+
<AssemblyVersion>1.12.1</AssemblyVersion>
14+
<PackageTags>JSchema;JsonSchema;Schema;Json;Validation;Assert;Test</PackageTags>
1515
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
1616
<NeutralLanguage>en</NeutralLanguage>
1717
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0</TargetFrameworks>

JsonSchema/doc/articles/components.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Reusable Components | Json Schema </title>
5+
<title>Schema Components | Json Schema </title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="title" content="Reusable Components | Json Schema ">
7+
<meta name="title" content="Schema Components | Json Schema ">
88

99
<link rel="icon" href="../images/favicon.ico">
1010
<link rel="stylesheet" href="../public/docfx.min.css">
@@ -84,10 +84,11 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
8484
</div>
8585

8686
<article data-uid="">
87-
<h1 id="reusable-components">Reusable Components</h1>
87+
<h1 id="schema-components">Schema Components</h1>
8888

89-
<p>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.</p>
90-
<p>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 <code>$component</code> where the validation rule describes an object structure with two key-value pairs:</p>
89+
<p>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 construct.</p>
90+
<p>These schema components are used as an extension of data type validation, as core data types have limited features to validate the internal structure of a composite JSON value or construct. Therefore, a data type is parameterized with a schema component to validate the internal structure of such composite JSON constructs.</p>
91+
<p>The name or alias of a schema component always starts with <code>$</code> which also refers to the fact that they are named schema components or fragments defined elsewhere in the schema. Schema components can be referenced from any other part of the schema document, effectively reducing redundancy and enhancing reusability and readability. The following example defines a simple schema component named <code>$component</code> where the validation rule describes an object structure with two key-value pairs:</p>
9192
<pre><code class="lang-js">%define $component: { &quot;key1&quot;: #integer, &quot;key2&quot;: #string }
9293
</code></pre>
9394
<p>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.</p>
@@ -128,7 +129,8 @@ <h1 id="reusable-components">Reusable Components</h1>
128129

129130
%schema: @length(1, 10) #object*($article) #array
130131
</code></pre>
131-
<p>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:</p>
132+
<p>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.</p>
133+
<p>By defining a reusable schema component with a clear and descriptive name, one can improve the overall clarity and readability of the Schema document with recurring structures. 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 instance, consider the following example of a JSON document which is valid against the schema example provided above, demonstrating the usage of a schema component:</p>
132134
<pre><code class="lang-js">[
133135
{
134136
&quot;id&quot;: 1,

JsonSchema/doc/articles/components.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Reusable Components
2-
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.
1+
# Schema Components
2+
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 construct.
33

4-
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:
4+
These schema components are used as an extension of data type validation, as core data types have limited features to validate the internal structure of a composite JSON value or construct. Therefore, a data type is parameterized with a schema component to validate the internal structure of such composite JSON constructs.
5+
6+
The name or alias of a schema component always starts with `$` which also refers to the fact that they are named schema components or fragments defined elsewhere in the schema. Schema components can be referenced from any other part of the schema document, effectively reducing redundancy and enhancing reusability and readability. The following example defines a simple schema component named `$component` where the validation rule describes an object structure with two key-value pairs:
57
```js
68
%define $component: { "key1": #integer, "key2": #string }
79
```
@@ -28,7 +30,9 @@ In the above table, all three rows have identical validation constraints for the
2830
%schema: @length(1, 10) #object*($article) #array
2931
```
3032

31-
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:
33+
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.
34+
35+
By defining a reusable schema component with a clear and descriptive name, one can improve the overall clarity and readability of the Schema document with recurring structures. 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 instance, consider the following example of a JSON document which is valid against the schema example provided above, demonstrating the usage of a schema component:
3236
```js
3337
[
3438
{

JsonSchema/doc/articles/directives.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ <h3 id="ignore-object-property-order">Ignore Object Property Order</h3>
128128
<pre><code class="lang-stylus">%pragma IgnoreObjectPropertyOrder: false
129129
</code></pre>
130130
<h2 id="definition--define-directive">Definition / Define Directive</h2>
131-
<p>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.</p>
132-
<p>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 <a href="/JSchema-DotNet/articles/components.html">here</a>.</p>
133-
<p>The name or alias of the directive is always start with <code>$</code> 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:</p>
131+
<p>This feature in JSON schemas allows you to define a name for a schema component or fragment, 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 schema component instead of duplicating the same validation rules. For more information about the schema component syntax and format, please refer to the documentation <a href="/JSchema-DotNet/articles/components.html">here</a>. Here is a simple example of how to use this directive:</p>
134132
<pre><code class="lang-stylus">%define $product: {
135133
&quot;id&quot;: @length(2, 10) @regex(&quot;[a-z][a-z0-9]+&quot;) #string,
136134
&quot;name&quot;: @length(5, 100) #string,

JsonSchema/doc/articles/directives.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ The `IgnoreObjectPropertyOrder` pragma directive provides a means to enforce a s
6262
```
6363

6464
## Definition / Define Directive
65-
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.
66-
67-
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](/JSchema-DotNet/articles/components.html).
68-
69-
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:
65+
This feature in JSON schemas allows you to define a name for a schema component or fragment, 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 schema component instead of duplicating the same validation rules. For more information about the schema component syntax and format, please refer to the documentation [here](/JSchema-DotNet/articles/components.html). Here is a simple example of how to use this directive:
7066
```stylus
7167
%define $product: {
7268
"id": @length(2, 10) @regex("[a-z][a-z0-9]+") #string,

0 commit comments

Comments
 (0)