diff --git a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ErrorDetail.html b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ErrorDetail.html index f19b421..33b8f11 100644 --- a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ErrorDetail.html +++ b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ErrorDetail.html @@ -150,7 +150,7 @@

Constructors

ErrorDetail(string, string) - +

@@ -187,7 +187,7 @@

Properties

Code - +

@@ -218,7 +218,7 @@

Property Value

Message - +

diff --git a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ExpectedDetail.html b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ExpectedDetail.html index d15a104..a37575e 100644 --- a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ExpectedDetail.html +++ b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Message.ExpectedDetail.html @@ -83,7 +83,7 @@
Table of Contents

Class ExpectedDetail - +

@@ -160,7 +160,7 @@

Constructors

ExpectedDetail(Context, string) - +

@@ -193,7 +193,7 @@

Parameters

ExpectedDetail(JNode, string) - +

@@ -226,7 +226,7 @@

Parameters

- Edit this page + Edit this page
diff --git a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Tree.RuntimeContext.html b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Tree.RuntimeContext.html index b32dc61..c77f092 100644 --- a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Tree.RuntimeContext.html +++ b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Tree.RuntimeContext.html @@ -150,7 +150,7 @@

Properties

Definitions - +

@@ -181,7 +181,7 @@

Property Value

Exceptions - +

@@ -212,7 +212,7 @@

Property Value

FloatingPointTolerance - +

@@ -243,7 +243,7 @@

Property Value

IgnoreObjectPropertyOrder - +

@@ -274,7 +274,7 @@

Property Value

IgnoreUndefinedProperties - +

@@ -305,7 +305,7 @@

Property Value

ThrowException - +

@@ -340,7 +340,7 @@

Methods

AddClass(JInclude) - +

@@ -376,7 +376,7 @@

Returns

AddClass(string, Context?) - +

@@ -409,7 +409,7 @@

Parameters

AddDefinition(JDefinition) - +

@@ -445,7 +445,7 @@

Returns

AddPragma(JPragma) - +

@@ -481,7 +481,7 @@

Returns

GetPragmaValue<T>(string) - +

@@ -522,7 +522,7 @@

Type Parameters

InvokeFunction(JFunction, JNode) - +

diff --git a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JDataType.html b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JDataType.html index 024034d..910fe8f 100644 --- a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JDataType.html +++ b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JDataType.html @@ -83,7 +83,7 @@
Table of Contents

Class JDataType - +

@@ -170,7 +170,7 @@

Properties

Alias - +

@@ -201,7 +201,7 @@

Property Value

Children - +

@@ -232,7 +232,7 @@

Property Value

JsonType - +

@@ -263,7 +263,7 @@

Property Value

Nested - +

@@ -298,7 +298,7 @@

Methods

Equals(object?) - +

Determines whether the specified object is equal to the current object.

@@ -337,7 +337,7 @@

Returns

GetHashCode() - +

Serves as the default hash function.

@@ -370,7 +370,7 @@

Returns

IsApplicable(JNode) - +

@@ -406,7 +406,7 @@

Returns

Match(JNode) - +

Determines whether the specified node matches with the current node.

@@ -446,7 +446,7 @@

Returns

ToString() - +

Returns a JSON string that represents the current object.

@@ -479,7 +479,7 @@

Returns

ToString(bool) - +

@@ -515,7 +515,7 @@

Returns

diff --git a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JValidator.html b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JValidator.html index 7aab281..f0307a7 100644 --- a/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JValidator.html +++ b/JsonSchema/docs/api/RelogicLabs.JsonSchema.Types.JValidator.html @@ -403,7 +403,7 @@

Returns

ToString() - +

Returns a JSON string that represents the current object.

diff --git a/JsonSchema/docs/articles/intro.md b/JsonSchema/docs/articles/intro.md index d4fd3bb..d2b636b 100644 --- a/JsonSchema/docs/articles/intro.md +++ b/JsonSchema/docs/articles/intro.md @@ -21,4 +21,4 @@ JSON, short for JavaScript Object Notation, is one of the most widely used data * [API Reference Documentation](/JsonSchema-DotNet/api/index.html) -
+
\ No newline at end of file diff --git a/JsonSchema/docs/articles/quickstart.html b/JsonSchema/docs/articles/quickstart.html index 2d3e2b4..9a5c281 100644 --- a/JsonSchema/docs/articles/quickstart.html +++ b/JsonSchema/docs/articles/quickstart.html @@ -76,11 +76,8 @@
Table of Contents
- -

Getting Started

+

This guide will walk you through the essential steps to quickly get up and running with New JSON Schema library. It is also assumes a modest familiarity with the .NET SDK and .NET CLI (command-line interface) toolchain including basic familiarity with NuGet packages. Additionally, it considers a certain level of knowledge in C# language.

NuGet Library Package

To get started, launch your preferred IDE (such as Visual Studio, JetBrains Rider, or VS Code) and open the C# project where you intend to include this library package. Within your IDE, navigate to the NuGet package manager and search for the package by the name 'RelogicLabs.JsonSchema'. Subsequently, proceed to add or install the package to your project. Alternatively, you can use the .NET CLI to add the package to your project. Simply run the following command, replacing 1.x.x with either the latest version or your preferred version:

@@ -91,6 +88,7 @@

NuGet Library Package

<PackageReference Include="RelogicLabs.JsonSchema" Version="1.x.x" /> </ItemGroup> +

For additional information regarding this library package, you can visit the NuGet package repository page of this library here.

Write a Sample to Test

With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema.

using RelogicLabs.JsonSchema;
@@ -157,8 +155,7 @@ 

Write a Sample to Test

} }
-

For more information about the schema syntax format and library functionalities, please refer to the reference documentation here.

-

Create Some Validation Errors

+

Create Validation Errors

Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors.

{
     "user": {
@@ -196,7 +193,8 @@ 

Create Some Validation Errors

Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, "profile"...ing, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}} is expected but found {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": "Doe", "a...: "123 Some St", "city": "Some town", "country": "Some Country"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {"user": {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, ...ng, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}}} is expected but found {"user": {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": ... "123 Some St", "city": "Some town", "country": "Some Country"}}}}.
-

To utilize this library for test automation and API testing, you can employ the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors:

+

Assertion for Validation

+

To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors:

...
 
 try {
@@ -207,7 +205,7 @@ 

Create Some Validation Errors

...
-

The following presents the printed stack trace for the preceding example. It's important to note that when utilizing JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema:

+

The following presents the printed stack trace for the preceding example. It's important to note that when using JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema:

RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch
 Expected (Schema Line: 6:31): data type #integer
 Actual (Json Line: 3:14): found #string inferred by "not number"
@@ -225,7 +223,6 @@ 

Create Some Validation Errors

at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 -

For more information about the schema syntax format and library functionalities, please refer to the reference documentation here.

diff --git a/JsonSchema/docs/articles/quickstart.md b/JsonSchema/docs/articles/quickstart.md index 47367f4..2ea1088 100644 --- a/JsonSchema/docs/articles/quickstart.md +++ b/JsonSchema/docs/articles/quickstart.md @@ -1,7 +1,3 @@ - - # Getting Started This guide will walk you through the essential steps to quickly get up and running with New JSON Schema library. It is also assumes a modest familiarity with the .NET SDK and .NET CLI (command-line interface) toolchain including basic familiarity with NuGet packages. Additionally, it considers a certain level of knowledge in C# language. @@ -16,6 +12,8 @@ To verify the successful integration of the library into your project, you may m ``` +For additional information regarding this library package, you can visit the NuGet package repository page of this library [here](https://www.nuget.org/packages/RelogicLabs.JsonSchema). + ## Write a Sample to Test With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema. ```c# @@ -83,9 +81,8 @@ public class SampleSchema } } ``` -For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). -## Create Some Validation Errors +## Create Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the `id` within the `user` object to a string type and observe the outcome. Additionally, we'll modify the `username` by inserting a space into its value, thus creating an invalid `username`. Below is the revised JSON representation, now containing these purposeful errors. ```json { @@ -109,7 +106,6 @@ Let's intentionally introduce a few errors by modifying the previous JSON docume } } ``` - To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the `WriteError` method to display the errors if validation fails is as follows: ```c# @@ -120,7 +116,6 @@ if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... ``` - Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. ```accesslog @@ -131,8 +126,8 @@ Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {"id": Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {"user": {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, ...ng, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}}} is expected but found {"user": {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": ... "123 Some St", "city": "Some town", "country": "Some Country"}}}}. ``` -To utilize this library for test automation and API testing, you can employ the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: - +## Assertion for Validation +To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: ```c# ... @@ -144,8 +139,7 @@ try { ... ``` -The following presents the printed stack trace for the preceding example. It's important to note that when utilizing `JsonAssert`, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: - +The following presents the printed stack trace for the preceding example. It's important to note that when using `JsonAssert`, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: ```accesslog RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer @@ -164,7 +158,5 @@ Actual (Json Line: 3:14): found #string inferred by "not number" at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 - ``` - For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). \ No newline at end of file diff --git a/JsonSchema/docs/articles/sourcebuild.html b/JsonSchema/docs/articles/sourcebuild.html index 454446f..6b741cd 100644 --- a/JsonSchema/docs/articles/sourcebuild.html +++ b/JsonSchema/docs/articles/sourcebuild.html @@ -76,11 +76,8 @@
Table of Contents
- -

Build from Source Code

+

This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. Within this document, we will navigate through these steps, presenting them clearly and straightforwardly.

Build the Library

To get started, clone the project from the following URL using your preferred Git client (command line or GUI). You can open a terminal and enter the following Git clone command as shown below:

@@ -164,8 +161,7 @@

Write a Sample to Test

} } -

For more information about the schema syntax format and library functionalities, please refer to the reference documentation here.

-

Create Some Validation Errors

+

Create Validation Errors

Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors.

{
     "user": {
@@ -203,6 +199,38 @@ 

Create Some Validation Errors

Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, "profile"...ing, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}} is expected but found {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": "Doe", "a...: "123 Some St", "city": "Some town", "country": "Some Country"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {"user": {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, ...ng, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}}} is expected but found {"user": {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": ... "123 Some St", "city": "Some town", "country": "Some Country"}}}}.
+

Assertion for Validation

+

To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors:

+
...
+
+try {
+    JsonAssert.IsValid(schema, json);
+} catch(Exception e) {
+    Console.Error.WriteLine(e);
+}
+
+...
+
+

The following presents the printed stack trace for the preceding example. It's important to note that when using JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema:

+
RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch
+Expected (Schema Line: 6:31): data type #integer
+Actual (Json Line: 3:14): found #string inferred by "not number"
+
+   at RelogicLabs.JsonSchema.Tree.RuntimeContext.FailWith(Exception exception)
+   at RelogicLabs.JsonSchema.Types.JNode.FailWith(Exception exception)
+   at RelogicLabs.JsonSchema.Types.JDataType.MatchForReport(JNode node)
+   at RelogicLabs.JsonSchema.Types.JValidator.<>c__DisplayClass22_0.<Match>b__1(JDataType d)
+   at RelogicLabs.JsonSchema.Utilities.CollectionExtension.ForEach[T](IEnumerable`1 enumeration, Action`1 action)
+   at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node)
+   at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node)
+   at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node)
+   at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node)
+   at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node)
+   at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node)
+   at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual)
+   at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61
+
+

For more information about the schema syntax format and library functionalities, please refer to the reference documentation here.

diff --git a/JsonSchema/docs/articles/sourcebuild.md b/JsonSchema/docs/articles/sourcebuild.md index 776f8fb..271aa31 100644 --- a/JsonSchema/docs/articles/sourcebuild.md +++ b/JsonSchema/docs/articles/sourcebuild.md @@ -1,7 +1,3 @@ - - # Build from Source Code This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. Within this document, we will navigate through these steps, presenting them clearly and straightforwardly. @@ -92,9 +88,8 @@ public class SampleSchema } } ``` -For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). -## Create Some Validation Errors +## Create Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the `id` within the `user` object to a string type and observe the outcome. Additionally, we'll modify the `username` by inserting a space into its value, thus creating an invalid `username`. Below is the revised JSON representation, now containing these purposeful errors. ```json { @@ -118,7 +113,6 @@ Let's intentionally introduce a few errors by modifying the previous JSON docume } } ``` - To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the `WriteError` method to display the errors if validation fails is as follows: ```c# @@ -129,7 +123,6 @@ if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... ``` - Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. ```accesslog @@ -138,4 +131,39 @@ Schema (Line: 6:14) [FUNC03]: Function @range(1, 10000) is applicable on #number Schema (Line: 8:20) Json (Line: 4:20) [REGX01]: Regex pattern does not match. String of pattern "[a-z_]{3,30}" is expected but found "john doe" that mismatches with pattern. Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, "profile"...ing, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}} is expected but found {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": "Doe", "a...: "123 Some St", "city": "Some town", "country": "Some Country"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {"user": {"id": @range(1, 10000) #integer, "username": @regex("[a-z_]{3,30}") #string, "role": "user" #string, "isActive": #boolean, ...ng, "country": @regex("[A-Za-z ]{3,50}") #string} #object #null}}} is expected but found {"user": {"id": "not number", "username": "john doe", "role": "user", "isActive": true, "profile": {"firstName": "John", "lastName": ... "123 Some St", "city": "Some town", "country": "Some Country"}}}}. -``` \ No newline at end of file +``` + +## Assertion for Validation +To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: +```c# +... + +try { + JsonAssert.IsValid(schema, json); +} catch(Exception e) { + Console.Error.WriteLine(e); +} + +... +``` +The following presents the printed stack trace for the preceding example. It's important to note that when using `JsonAssert`, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: +```accesslog +RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch +Expected (Schema Line: 6:31): data type #integer +Actual (Json Line: 3:14): found #string inferred by "not number" + + at RelogicLabs.JsonSchema.Tree.RuntimeContext.FailWith(Exception exception) + at RelogicLabs.JsonSchema.Types.JNode.FailWith(Exception exception) + at RelogicLabs.JsonSchema.Types.JDataType.MatchForReport(JNode node) + at RelogicLabs.JsonSchema.Types.JValidator.<>c__DisplayClass22_0.b__1(JDataType d) + at RelogicLabs.JsonSchema.Utilities.CollectionExtension.ForEach[T](IEnumerable`1 enumeration, Action`1 action) + at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) + at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) + at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) + at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) + at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) + at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) + at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) + at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 +``` +For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). \ No newline at end of file diff --git a/JsonSchema/docs/index.html b/JsonSchema/docs/index.html index 070adb4..3002045 100644 --- a/JsonSchema/docs/index.html +++ b/JsonSchema/docs/index.html @@ -144,7 +144,7 @@

Extended Example

%title: "Extended User Profile Dashboard API Response"
 %version: 2.0.0
 %include: RelogicLabs.JsonSchema.Tests.Positive.ExternalFunctions,
-            RelogicLabs.JsonSchema.Tests
+          RelogicLabs.JsonSchema.Tests
 
 %pragma IgnoreUndefinedProperties: true
 
@@ -168,7 +168,7 @@ 

Extended Example

} #object #null } -%define $tags: @length(1, 10) #array($tag) +%define $tags: @length(1, 10) #string*($tag) #array %define $tag: @length(3, 20) @regex("[A-Za-z_]+") #string %schema: @@ -177,10 +177,9 @@

Extended Example

"id": @range(1, 10000) #integer, /*username does not allow special characters*/ "username": @regex("[a-z_]{3,30}") #string, - /*currently only one role is allowed by system*/ - "role": "user" #string, + "role": @enum("user", "admin") #string, "isActive": #boolean, //user account current status - "registeredAt": #time, + "registeredAt": @time("DD-MM-YYYY hh:mm:ss") #string, "profile": { "firstName": @regex("[A-Za-z]{3,50}") #string, "lastName": @regex("[A-Za-z]{3,50}") #string, @@ -214,9 +213,9 @@

Extended Example

"user": { "id": 1234, "username": "johndoe", - "role": "user", + "role": "admin", "isActive": true, - "registeredAt": "2023-09-06T15:10:30.639Z", + "registeredAt": "06-09-2023 15:10:30", "profile": { "firstName": "John", "lastName": "Doe", @@ -284,9 +283,9 @@

Extended Example

"price": 1299.99, "inStock": false, "specs": { - "cpu": "Intel i7", - "ram": "16GB", - "storage": "512GB SSD" + "cpu": "Intel i11", + "ram": "11GB", + "storage": "11GB SSD" } } ], diff --git a/JsonSchema/docs/index.json b/JsonSchema/docs/index.json index 98f690b..c35f8d4 100644 --- a/JsonSchema/docs/index.json +++ b/JsonSchema/docs/index.json @@ -417,12 +417,12 @@ "articles/quickstart.html": { "href": "articles/quickstart.html", "title": "Getting Started | Json Schema", - "keywords": "pre code { font-size: 1.1em; } Getting Started This guide will walk you through the essential steps to quickly get up and running with New JSON Schema library. It is also assumes a modest familiarity with the .NET SDK and .NET CLI (command-line interface) toolchain including basic familiarity with NuGet packages. Additionally, it considers a certain level of knowledge in C# language. NuGet Library Package To get started, launch your preferred IDE (such as Visual Studio, JetBrains Rider, or VS Code) and open the C# project where you intend to include this library package. Within your IDE, navigate to the NuGet package manager and search for the package by the name 'RelogicLabs.JsonSchema'. Subsequently, proceed to add or install the package to your project. Alternatively, you can use the .NET CLI to add the package to your project. Simply run the following command, replacing 1.x.x with either the latest version or your preferred version: dotnet add package RelogicLabs.JsonSchema --version 1.x.x To verify the successful integration of the library into your project, you may manually inspect your project file, typically named .csproj, using a text editor, and search for the following XML snippet within the file: Write a Sample to Test With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema. using RelogicLabs.JsonSchema; namespace CSharpApplication; public class SampleSchema { public bool CheckIsValid() { var schema = \"\"\" %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } \"\"\"; var json = \"\"\" { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } \"\"\"; JsonSchema jsonSchema = new(schema); return jsonSchema.IsValid(json); } } For more information about the schema syntax format and library functionalities, please refer to the reference documentation here. Create Some Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors. { \"user\": { \"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the WriteError method to display the errors if validation fails is as follows: ... JsonSchema jsonSchema = new(schema); if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. Schema (Line: 6:31) Json (Line: 3:14) [DTYP04]: Data type mismatch. Data type #integer is expected but found #string inferred by \"not number\". Schema (Line: 6:14) [FUNC03]: Function @range(1, 10000) is applicable on #number but applied on #string of \"not number\" Schema (Line: 8:20) Json (Line: 4:20) [REGX01]: Regex pattern does not match. String of pattern \"[a-z_]{3,30}\" is expected but found \"john doe\" that mismatches with pattern. Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, \"profile\"...ing, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}} is expected but found {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": \"Doe\", \"a...: \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {\"user\": {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, ...ng, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}}} is expected but found {\"user\": {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": ... \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}}. To utilize this library for test automation and API testing, you can employ the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: ... try { JsonAssert.IsValid(schema, json); } catch(Exception e) { Console.Error.WriteLine(e); } ... The following presents the printed stack trace for the preceding example. It's important to note that when utilizing JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer Actual (Json Line: 3:14): found #string inferred by \"not number\" at RelogicLabs.JsonSchema.Tree.RuntimeContext.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JNode.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JDataType.MatchForReport(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.<>c__DisplayClass22_0.b__1(JDataType d) at RelogicLabs.JsonSchema.Utilities.CollectionExtension.ForEach[T](IEnumerable`1 enumeration, Action`1 action) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 For more information about the schema syntax format and library functionalities, please refer to the reference documentation here." + "keywords": "Getting Started This guide will walk you through the essential steps to quickly get up and running with New JSON Schema library. It is also assumes a modest familiarity with the .NET SDK and .NET CLI (command-line interface) toolchain including basic familiarity with NuGet packages. Additionally, it considers a certain level of knowledge in C# language. NuGet Library Package To get started, launch your preferred IDE (such as Visual Studio, JetBrains Rider, or VS Code) and open the C# project where you intend to include this library package. Within your IDE, navigate to the NuGet package manager and search for the package by the name 'RelogicLabs.JsonSchema'. Subsequently, proceed to add or install the package to your project. Alternatively, you can use the .NET CLI to add the package to your project. Simply run the following command, replacing 1.x.x with either the latest version or your preferred version: dotnet add package RelogicLabs.JsonSchema --version 1.x.x To verify the successful integration of the library into your project, you may manually inspect your project file, typically named .csproj, using a text editor, and search for the following XML snippet within the file: For additional information regarding this library package, you can visit the NuGet package repository page of this library here. Write a Sample to Test With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema. using RelogicLabs.JsonSchema; namespace CSharpApplication; public class SampleSchema { public bool CheckIsValid() { var schema = \"\"\" %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } \"\"\"; var json = \"\"\" { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } \"\"\"; JsonSchema jsonSchema = new(schema); return jsonSchema.IsValid(json); } } Create Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors. { \"user\": { \"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the WriteError method to display the errors if validation fails is as follows: ... JsonSchema jsonSchema = new(schema); if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. Schema (Line: 6:31) Json (Line: 3:14) [DTYP04]: Data type mismatch. Data type #integer is expected but found #string inferred by \"not number\". Schema (Line: 6:14) [FUNC03]: Function @range(1, 10000) is applicable on #number but applied on #string of \"not number\" Schema (Line: 8:20) Json (Line: 4:20) [REGX01]: Regex pattern does not match. String of pattern \"[a-z_]{3,30}\" is expected but found \"john doe\" that mismatches with pattern. Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, \"profile\"...ing, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}} is expected but found {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": \"Doe\", \"a...: \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {\"user\": {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, ...ng, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}}} is expected but found {\"user\": {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": ... \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}}. Assertion for Validation To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: ... try { JsonAssert.IsValid(schema, json); } catch(Exception e) { Console.Error.WriteLine(e); } ... The following presents the printed stack trace for the preceding example. It's important to note that when using JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer Actual (Json Line: 3:14): found #string inferred by \"not number\" at RelogicLabs.JsonSchema.Tree.RuntimeContext.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JNode.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JDataType.MatchForReport(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.<>c__DisplayClass22_0.b__1(JDataType d) at RelogicLabs.JsonSchema.Utilities.CollectionExtension.ForEach[T](IEnumerable`1 enumeration, Action`1 action) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 For more information about the schema syntax format and library functionalities, please refer to the reference documentation here." }, "articles/sourcebuild.html": { "href": "articles/sourcebuild.html", "title": "Build from Source Code | Json Schema", - "keywords": "pre code { font-size: 1.1em; } Build from Source Code This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. Within this document, we will navigate through these steps, presenting them clearly and straightforwardly. Build the Library To get started, clone the project from the following URL using your preferred Git client (command line or GUI). You can open a terminal and enter the following Git clone command as shown below: git clone https://github.com/relogiclabs/JsonSchema-DotNet.git Next, use .NET build command dotnet build to build the project and Retrieve the DLL file, RelogicLabs.JsonSchema.dll from the bin folder. Add the Library to Your Project To integrate the library with your project, you can create a libs folder within your project directory and place the retrieved DLL file into the designated folder. Alternatively, if your IDE supports adding references, you can conveniently select the DLL from the libs folder. Alternatively, you can manually modify your project file .csproj using a text editor and include the following XML snippet: libs\\RelogicLabs.JsonSchema.dll Additionally, this project has a dependency on ANTLR runtime, which you can integrate by executing the following command: dotnet add package Antlr4.Runtime.Standard --version 4.13.1 Write a Sample to Test With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema. using RelogicLabs.JsonSchema; namespace CSharpApplication; public class SampleSchema { public bool CheckIsValid() { var schema = \"\"\" %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } \"\"\"; var json = \"\"\" { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } \"\"\"; JsonSchema jsonSchema = new(schema); return jsonSchema.IsValid(json); } } For more information about the schema syntax format and library functionalities, please refer to the reference documentation here. Create Some Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors. { \"user\": { \"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the WriteError method to display the errors if validation fails is as follows: ... JsonSchema jsonSchema = new(schema); if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. Schema (Line: 6:31) Json (Line: 3:14) [DTYP04]: Data type mismatch. Data type #integer is expected but found #string inferred by \"not number\". Schema (Line: 6:14) [FUNC03]: Function @range(1, 10000) is applicable on #number but applied on #string of \"not number\" Schema (Line: 8:20) Json (Line: 4:20) [REGX01]: Regex pattern does not match. String of pattern \"[a-z_]{3,30}\" is expected but found \"john doe\" that mismatches with pattern. Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, \"profile\"...ing, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}} is expected but found {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": \"Doe\", \"a...: \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {\"user\": {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, ...ng, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}}} is expected but found {\"user\": {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": ... \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}}." + "keywords": "Build from Source Code This comprehensive guide illustrates the procedures for retrieving source code from a GitHub repository, compiling the project source code into a library, and seamlessly integrating the compiled library into your project. Within this document, we will navigate through these steps, presenting them clearly and straightforwardly. Build the Library To get started, clone the project from the following URL using your preferred Git client (command line or GUI). You can open a terminal and enter the following Git clone command as shown below: git clone https://github.com/relogiclabs/JsonSchema-DotNet.git Next, use .NET build command dotnet build to build the project and Retrieve the DLL file, RelogicLabs.JsonSchema.dll from the bin folder. Add the Library to Your Project To integrate the library with your project, you can create a libs folder within your project directory and place the retrieved DLL file into the designated folder. Alternatively, if your IDE supports adding references, you can conveniently select the DLL from the libs folder. Alternatively, you can manually modify your project file .csproj using a text editor and include the following XML snippet: libs\\RelogicLabs.JsonSchema.dll Additionally, this project has a dependency on ANTLR runtime, which you can integrate by executing the following command: dotnet add package Antlr4.Runtime.Standard --version 4.13.1 Write a Sample to Test With the necessary components in place, you are now prepared to create a sample schema and validate a corresponding JSON against the schema. The subsequent example presents a C# class featuring a method designed for validating a sample JSON based on a provided schema. using RelogicLabs.JsonSchema; namespace CSharpApplication; public class SampleSchema { public bool CheckIsValid() { var schema = \"\"\" %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } \"\"\"; var json = \"\"\" { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } \"\"\"; JsonSchema jsonSchema = new(schema); return jsonSchema.IsValid(json); } } Create Validation Errors Let's intentionally introduce a few errors by modifying the previous JSON document and then examine the validation results. To begin, we'll alter the id within the user object to a string type and observe the outcome. Additionally, we'll modify the username by inserting a space into its value, thus creating an invalid username. Below is the revised JSON representation, now containing these purposeful errors. { \"user\": { \"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } To achieve the desired outcome, please make the following changes to the preceding code. Specifically, ensure that any schema validation errors are displayed in the console. The modified code snippet that invokes the WriteError method to display the errors if validation fails is as follows: ... JsonSchema jsonSchema = new(schema); if(!jsonSchema.IsValid(json)) jsonSchema.WriteError(); ... Here is the error as displayed in the console. More specific errors will be listed first, followed by more general errors. Consequently, the specific errors will precisely pinpoint the issues within the JSON document, while the generic errors will provide contextual information about where the errors occurred. Schema (Line: 6:31) Json (Line: 3:14) [DTYP04]: Data type mismatch. Data type #integer is expected but found #string inferred by \"not number\". Schema (Line: 6:14) [FUNC03]: Function @range(1, 10000) is applicable on #number but applied on #string of \"not number\" Schema (Line: 8:20) Json (Line: 4:20) [REGX01]: Regex pattern does not match. String of pattern \"[a-z_]{3,30}\" is expected but found \"john doe\" that mismatches with pattern. Schema (Line: 5:12) Json (Line: 2:12) [VALD01]: Validation Failed. Value {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, \"profile\"...ing, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}} is expected but found {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": \"Doe\", \"a...: \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}. Schema (Line: 4:0) Json (Line: 1:0) [VALD01]: Validation Failed. Value {\"user\": {\"id\": @range(1, 10000) #integer, \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": \"user\" #string, \"isActive\": #boolean, ...ng, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string} #object #null}}} is expected but found {\"user\": {\"id\": \"not number\", \"username\": \"john doe\", \"role\": \"user\", \"isActive\": true, \"profile\": {\"firstName\": \"John\", \"lastName\": ... \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\"}}}}. Assertion for Validation To utilize this library for test automation and API testing, you can use the following alternative code snippet to perform assertions on input JSON against a specified schema. For instance, let's examine how to assert the JSON, which has been intentionally altered to introduce some errors, against the aforementioned schema. The following demonstrates the adjusted code for asserting the JSON with errors: ... try { JsonAssert.IsValid(schema, json); } catch(Exception e) { Console.Error.WriteLine(e); } ... The following presents the printed stack trace for the preceding example. It's important to note that when using JsonAssert, it throws an exception upon encountering the first error, thus preventing the continuation of processing the rest of the schema: RelogicLabs.JsonSchema.Exceptions.JsonSchemaException: DTYP04: Data type mismatch Expected (Schema Line: 6:31): data type #integer Actual (Json Line: 3:14): found #string inferred by \"not number\" at RelogicLabs.JsonSchema.Tree.RuntimeContext.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JNode.FailWith(Exception exception) at RelogicLabs.JsonSchema.Types.JDataType.MatchForReport(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.<>c__DisplayClass22_0.b__1(JDataType d) at RelogicLabs.JsonSchema.Utilities.CollectionExtension.ForEach[T](IEnumerable`1 enumeration, Action`1 action) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JObject.Match(JNode node) at RelogicLabs.JsonSchema.Types.JValidator.Match(JNode node) at RelogicLabs.JsonSchema.Types.JRoot.Match(JNode node) at RelogicLabs.JsonSchema.JsonAssert.IsValid(String schemaExpected, String jsonActual) at CSharpApplication.SampleSchema.CheckIsValid() in /SampleSchema.cs:line 61 For more information about the schema syntax format and library functionalities, please refer to the reference documentation here." }, "articles/specification.html": { "href": "articles/specification.html", @@ -437,6 +437,6 @@ "index.html": { "href": "index.html", "title": "A New JSON Schema | Json Schema", - "keywords": "pre code { font-size: 1.1em; } A New JSON Schema A JSON Schema is crucial for making communication, interoperability, validation, testing, documentation, and specification seamless. All of this combined contributes to better maintenance and evolution of data-driven applications and systems. For a comprehensive overview of the roles and uses of JSON Schema in modern web applications, we invite you to explore our dedicated post available here. Design Goals The traditional standard JSON Schema rigorously follows the conventional JSON structure, which unfortunately comes at the expense of simplicity, conciseness, and readability. Our goal is to develop a new JSON Schema that promotes these essential aspects that were previously missing. This new schema is simple, lucid, easy to grasp, and doesn't require much prior knowledge to understand it. It also offers a shallow learning curve for both reading and writing. Additionally, its simplicity and conciseness allow us and machines to read-write more efficiently. Moreover, a large set of constraint data types and functions within the core schema promotes the precise definition of JSON documents, significantly reducing the potential for communication gaps among collaborators. Furthermore, its inherent extensibility not only facilitates the test automation process in API testing but also simplifies the integrations of new constraints and functionalities to meet the diverse requirements of modern web services. Basic Example Let's explore an example of our schema for a typical JSON API response containing information about a user profile or account. The schema is very self-explanatory and thus almost no prior knowledge is required to understand the schema and the JSON responses specified by this schema. %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"registeredAt\": #time, \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"dateOfBirth\": #date, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } In the above example, two types of constraint or rule descriptors are used: constraint functions (also known as validation functions, such as @range(1, 10000)) and constraint data types (also known as validation data types, such as #integer). All constraint functions begin with the @ symbol, while all constraint data types start with #. C-style comments are also permitted in the schema. Please note that address can be null (eg. an optional input for users) and if it is null then no constraints of address are applicable. The following JSON is one of the examples which can successfully validate against the above schema. To start your journey with the JSON validation library, please consult the documentation available here. { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"registeredAt\": \"2023-09-06T15:10:30.639Z\", \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"dateOfBirth\": \"1993-06-17\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } Extended Example The next example represents an expanded version of the previous one, which brings more complexity. To effectively construct such schemas with multiple layers of nested structures, it's beneficial to have a fundamental understanding of this schema format. While the syntax may seem difficult at first, it becomes straightforward once you have a basic understanding of it. For more detailed information, reference documentation is available here. %title: \"Extended User Profile Dashboard API Response\" %version: 2.0.0 %include: RelogicLabs.JsonSchema.Tests.Positive.ExternalFunctions, RelogicLabs.JsonSchema.Tests %pragma IgnoreUndefinedProperties: true %define $post: { \"id\": @range(1, 1000) #integer, \"title\": @length(10, 100) #string, \"content\": @length(30, 1000) #string, \"tags\": $tags } #object %define $product: { \"id\": @length(2, 10) @regex(\"[a-z][a-z0-9]+\") #string, \"name\": @length(5, 30) #string, \"brand\": @length(5, 30) #string, \"price\": @range(0.1, 1000000), \"inStock\": #boolean, \"specs\": { \"cpu\": @length(5, 30) #string, \"ram\": @regex(\"[0-9]{1,2}GB\") #string, \"storage\": @regex(\"[0-9]{1,4}GB (SSD|HDD)\") #string } #object #null } %define $tags: @length(1, 10) #array($tag) %define $tag: @length(3, 20) @regex(\"[A-Za-z_]+\") #string %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"registeredAt\": #time, \"profile\": { \"firstName\": @regex(\"[A-Za-z]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z]{3,50}\") #string, \"dateOfBirth\": @date(\"DD-MM-YYYY\") #string, \"age\": @range(18, 128) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null, \"hobbies\": !? }, \"posts\": @length(0, 1000) #object*($post) #array, \"preferences\": { \"theme\": @enum(\"light\", \"dark\") #string, \"fontSize\": @range(9, 24) #integer, \"autoSave\": #boolean } }, \"products\": #object*($product) #array, \"weather\": { \"temperature\": @range(-50.0, 60.0) #float, \"isCloudy\": #boolean } } The subsequent JSON sample is an illustrative example that successfully validates against the expanded schema mentioned earlier. Within this example, recurring JSON structure appear that can be validated through defining components. By reusing defined components, you can achieve a clear and concise schema when validating large JSON with repetitive structures instead of duplicating large and complex validation constraints across the schema. This improves the overall readability and maintainability of the schema. { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"registeredAt\": \"2023-09-06T15:10:30.639Z\", \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"dateOfBirth\": \"17-06-1993\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } }, \"posts\": [ { \"id\": 1, \"title\": \"Introduction to JSON\", \"content\": \"JSON (JavaScript Object Notation) is a lightweight data interchange format...\", \"tags\": [ \"JSON\", \"tutorial\", \"data\" ] }, { \"id\": 2, \"title\": \"Working with JSON in C#\", \"content\": \"C# provides built-in support for working with JSON...\", \"tags\": [ \"CSharp\", \"JSON\", \"tutorial\" ] }, { \"id\": 3, \"title\": \"Introduction to JSON Schema\", \"content\": \"A JSON schema defines the structure and data types of JSON objects...\", \"tags\": [ \"Schema\", \"JSON\", \"tutorial\" ] } ], \"preferences\": { \"theme\": \"dark\", \"fontSize\": 14, \"autoSave\": true } }, \"products\": [ { \"id\": \"p1\", \"name\": \"Smartphone\", \"brand\": \"TechGiant\", \"price\": 599.99, \"inStock\": true, \"specs\": null }, { \"id\": \"p2\", \"name\": \"Laptop\", \"brand\": \"SuperTech\", \"price\": 1299.99, \"inStock\": false, \"specs\": { \"cpu\": \"Intel i7\", \"ram\": \"16GB\", \"storage\": \"512GB SSD\" } } ], \"weather\": { \"temperature\": 25.5, \"isCloudy\": true, \"conditions\": null } } For more information about the schema syntax format and library functionalities, please refer to the reference documentation here." + "keywords": "pre code { font-size: 1.1em; } A New JSON Schema A JSON Schema is crucial for making communication, interoperability, validation, testing, documentation, and specification seamless. All of this combined contributes to better maintenance and evolution of data-driven applications and systems. For a comprehensive overview of the roles and uses of JSON Schema in modern web applications, we invite you to explore our dedicated post available here. Design Goals The traditional standard JSON Schema rigorously follows the conventional JSON structure, which unfortunately comes at the expense of simplicity, conciseness, and readability. Our goal is to develop a new JSON Schema that promotes these essential aspects that were previously missing. This new schema is simple, lucid, easy to grasp, and doesn't require much prior knowledge to understand it. It also offers a shallow learning curve for both reading and writing. Additionally, its simplicity and conciseness allow us and machines to read-write more efficiently. Moreover, a large set of constraint data types and functions within the core schema promotes the precise definition of JSON documents, significantly reducing the potential for communication gaps among collaborators. Furthermore, its inherent extensibility not only facilitates the test automation process in API testing but also simplifies the integrations of new constraints and functionalities to meet the diverse requirements of modern web services. Basic Example Let's explore an example of our schema for a typical JSON API response containing information about a user profile or account. The schema is very self-explanatory and thus almost no prior knowledge is required to understand the schema and the JSON responses specified by this schema. %title: \"User Profile Response\" %version: 1.0.0 %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, /*currently only one role is allowed by system*/ \"role\": \"user\" #string, \"isActive\": #boolean, //user account current status \"registeredAt\": #time, \"profile\": { \"firstName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z ]{3,50}\") #string, \"dateOfBirth\": #date, \"age\": @range(18, 130) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null } } } In the above example, two types of constraint or rule descriptors are used: constraint functions (also known as validation functions, such as @range(1, 10000)) and constraint data types (also known as validation data types, such as #integer). All constraint functions begin with the @ symbol, while all constraint data types start with #. C-style comments are also permitted in the schema. Please note that address can be null (eg. an optional input for users) and if it is null then no constraints of address are applicable. The following JSON is one of the examples which can successfully validate against the above schema. To start your journey with the JSON validation library, please consult the documentation available here. { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"user\", \"isActive\": true, \"registeredAt\": \"2023-09-06T15:10:30.639Z\", \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"dateOfBirth\": \"1993-06-17\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } } } } Extended Example The next example represents an expanded version of the previous one, which brings more complexity. To effectively construct such schemas with multiple layers of nested structures, it's beneficial to have a fundamental understanding of this schema format. While the syntax may seem difficult at first, it becomes straightforward once you have a basic understanding of it. For more detailed information, reference documentation is available here. %title: \"Extended User Profile Dashboard API Response\" %version: 2.0.0 %include: RelogicLabs.JsonSchema.Tests.Positive.ExternalFunctions, RelogicLabs.JsonSchema.Tests %pragma IgnoreUndefinedProperties: true %define $post: { \"id\": @range(1, 1000) #integer, \"title\": @length(10, 100) #string, \"content\": @length(30, 1000) #string, \"tags\": $tags } #object %define $product: { \"id\": @length(2, 10) @regex(\"[a-z][a-z0-9]+\") #string, \"name\": @length(5, 30) #string, \"brand\": @length(5, 30) #string, \"price\": @range(0.1, 1000000), \"inStock\": #boolean, \"specs\": { \"cpu\": @length(5, 30) #string, \"ram\": @regex(\"[0-9]{1,2}GB\") #string, \"storage\": @regex(\"[0-9]{1,4}GB (SSD|HDD)\") #string } #object #null } %define $tags: @length(1, 10) #string*($tag) #array %define $tag: @length(3, 20) @regex(\"[A-Za-z_]+\") #string %schema: { \"user\": { \"id\": @range(1, 10000) #integer, /*username does not allow special characters*/ \"username\": @regex(\"[a-z_]{3,30}\") #string, \"role\": @enum(\"user\", \"admin\") #string, \"isActive\": #boolean, //user account current status \"registeredAt\": @time(\"DD-MM-YYYY hh:mm:ss\") #string, \"profile\": { \"firstName\": @regex(\"[A-Za-z]{3,50}\") #string, \"lastName\": @regex(\"[A-Za-z]{3,50}\") #string, \"dateOfBirth\": @date(\"DD-MM-YYYY\") #string, \"age\": @range(18, 128) #integer, \"email\": @email #string, \"pictureURL\": @url #string, \"address\": { \"street\": @length(10, 200) #string, \"city\": @length(3, 50) #string, \"country\": @regex(\"[A-Za-z ]{3,50}\") #string } #object #null, \"hobbies\": !? }, \"posts\": @length(0, 1000) #object*($post) #array, \"preferences\": { \"theme\": @enum(\"light\", \"dark\") #string, \"fontSize\": @range(9, 24) #integer, \"autoSave\": #boolean } }, \"products\": #object*($product) #array, \"weather\": { \"temperature\": @range(-50.0, 60.0) #float, \"isCloudy\": #boolean } } The subsequent JSON sample is an illustrative example that successfully validates against the expanded schema mentioned earlier. Within this example, recurring JSON structure appear that can be validated through defining components. By reusing defined components, you can achieve a clear and concise schema when validating large JSON with repetitive structures instead of duplicating large and complex validation constraints across the schema. This improves the overall readability and maintainability of the schema. { \"user\": { \"id\": 1234, \"username\": \"johndoe\", \"role\": \"admin\", \"isActive\": true, \"registeredAt\": \"06-09-2023 15:10:30\", \"profile\": { \"firstName\": \"John\", \"lastName\": \"Doe\", \"dateOfBirth\": \"17-06-1993\", \"age\": 30, \"email\": \"john.doe@example.com\", \"pictureURL\": \"https://example.com/picture.jpg\", \"address\": { \"street\": \"123 Some St\", \"city\": \"Some town\", \"country\": \"Some Country\" } }, \"posts\": [ { \"id\": 1, \"title\": \"Introduction to JSON\", \"content\": \"JSON (JavaScript Object Notation) is a lightweight data interchange format...\", \"tags\": [ \"JSON\", \"tutorial\", \"data\" ] }, { \"id\": 2, \"title\": \"Working with JSON in C#\", \"content\": \"C# provides built-in support for working with JSON...\", \"tags\": [ \"CSharp\", \"JSON\", \"tutorial\" ] }, { \"id\": 3, \"title\": \"Introduction to JSON Schema\", \"content\": \"A JSON schema defines the structure and data types of JSON objects...\", \"tags\": [ \"Schema\", \"JSON\", \"tutorial\" ] } ], \"preferences\": { \"theme\": \"dark\", \"fontSize\": 14, \"autoSave\": true } }, \"products\": [ { \"id\": \"p1\", \"name\": \"Smartphone\", \"brand\": \"TechGiant\", \"price\": 599.99, \"inStock\": true, \"specs\": null }, { \"id\": \"p2\", \"name\": \"Laptop\", \"brand\": \"SuperTech\", \"price\": 1299.99, \"inStock\": false, \"specs\": { \"cpu\": \"Intel i11\", \"ram\": \"11GB\", \"storage\": \"11GB SSD\" } } ], \"weather\": { \"temperature\": 25.5, \"isCloudy\": true, \"conditions\": null } } For more information about the schema syntax format and library functionalities, please refer to the reference documentation here." } } \ No newline at end of file diff --git a/JsonSchema/docs/index.md b/JsonSchema/docs/index.md index 04ca5c2..0bec31f 100644 --- a/JsonSchema/docs/index.md +++ b/JsonSchema/docs/index.md @@ -72,7 +72,7 @@ The next example represents an expanded version of the previous one, which bring %title: "Extended User Profile Dashboard API Response" %version: 2.0.0 %include: RelogicLabs.JsonSchema.Tests.Positive.ExternalFunctions, - RelogicLabs.JsonSchema.Tests + RelogicLabs.JsonSchema.Tests %pragma IgnoreUndefinedProperties: true @@ -96,7 +96,7 @@ The next example represents an expanded version of the previous one, which bring } #object #null } -%define $tags: @length(1, 10) #array($tag) +%define $tags: @length(1, 10) #string*($tag) #array %define $tag: @length(3, 20) @regex("[A-Za-z_]+") #string %schema: @@ -105,10 +105,9 @@ The next example represents an expanded version of the previous one, which bring "id": @range(1, 10000) #integer, /*username does not allow special characters*/ "username": @regex("[a-z_]{3,30}") #string, - /*currently only one role is allowed by system*/ - "role": "user" #string, + "role": @enum("user", "admin") #string, "isActive": #boolean, //user account current status - "registeredAt": #time, + "registeredAt": @time("DD-MM-YYYY hh:mm:ss") #string, "profile": { "firstName": @regex("[A-Za-z]{3,50}") #string, "lastName": @regex("[A-Za-z]{3,50}") #string, @@ -143,9 +142,9 @@ The subsequent JSON sample is an illustrative example that successfully validate "user": { "id": 1234, "username": "johndoe", - "role": "user", + "role": "admin", "isActive": true, - "registeredAt": "2023-09-06T15:10:30.639Z", + "registeredAt": "06-09-2023 15:10:30", "profile": { "firstName": "John", "lastName": "Doe", @@ -213,9 +212,9 @@ The subsequent JSON sample is an illustrative example that successfully validate "price": 1299.99, "inStock": false, "specs": { - "cpu": "Intel i7", - "ram": "16GB", - "storage": "512GB SSD" + "cpu": "Intel i11", + "ram": "11GB", + "storage": "11GB SSD" } } ], @@ -226,4 +225,4 @@ The subsequent JSON sample is an illustrative example that successfully validate } } ``` -For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). +For more information about the schema syntax format and library functionalities, please refer to the reference documentation [here](/JsonSchema-DotNet/api/index.html). \ No newline at end of file