Skip to main content

Schema

  • YoBulk enables a developer to create a Template by loading a schema.
  • YoBulk provides an editor where you can write a schema.
  • A developer can write complex validation rules using YoBulk schema.

link link

Writing a YoBulk Template schema:

  • By Default, YoBulk supports JSON and AJV schema.YoBulk parses JSON format on the fly.
  • Before copying any JSON schema, please get it validated through https://jsonformatter.curiousconcept.com/
  • Developers can create an AJV JSON template using the text generative console provided.
  • The YoBulk AI console takes input/query in pure english and generate schema on the fly in the console.

Rules for Writing a YoBulk Schema:

A sample AJV schema will have the following parameters. YoBulk understands all the keywords like type,properties,required defined in AJV schema.

info

Info : At present,YoBulk does not recognise keyword like $schema", so please ensure to remove it from the schema, if it's added through YoBulk AI.

Example of a YoBulk schema:

{

"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 2,
"maxLength": 50
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
},
"email": {
"type": "string",
"format": "email"
},
"required": ["name", "age", "email"]
}

YoBulk fields:

YoBulk supports basic field formats like integer,string,email For date and boolean fields,Yobulk has added two custom formats custom-date-time and custom-boolean which has to be of string type.

For example, to validate that a property called email in an object is a valid email address, you could use the following schema:

info

Info : If you are using date field , it can only validate date format in YYYY-MM-DD (2016-02-06) format.

We strongly suggest to use custom-date-time format type which supports all the date formats. An extra validation can be added by adding pattern key.

The Regex has to be passed as a string and has to be JSON escaped.Please use this website JSON ESCAPE to make the regex JSON escaped.

Example to add dd-mm-yyyy date validation by adding a regex :

"date":{
"type":"string",
"format":"custom-date-time",
"pattern":"^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}$",
"minLength":1
}

Type keyword is used to specify the expected type of the JSON value being validated. When using the type keyword for email and date validation, it would typically be used in conjunction with the format keyword, which specifies the expected format of the string value being validated.

example, to validate that a property called email in an object is a valid email address, you could use the following schema:

 
"email": {
"type": "string",
"format": "email"
}

In this above schema, the type keyword specifies that the value of the email property must be a string, and the format keyword specifies that the string must conform to the email format.

Note that the type keyword alone does not provide email validation, but it is used to ensure that the value being validated is a string before applying a format validation.

YoBulk Custom function validator:

YoBulk allows you to write your valiator function.By default,the field type has to be string type. Developers can use the keyword validate and can add any custom function.

info

Info : The regex passed inside the validate field has to be in string format and JSON escaped.

Example: link link

Passing a Regex in YoBulk Schema:

Developers can pass a regex by using pattern keyword.Please ensure the field type has to of string type and the Regex has to be JSON escaped.

Example of YoBulk Schema:

{
"type":"object",
"properties":{
"id":{
"type":"integer"
},
"first_name":{
"type":"string",
"format":"first_name",
"validate":"(x) => {\r\n let regex = new RegExp(\"([a-z][a-zA-Z]*)\");\r\n return regex.test(x);\r\n }"
},
"email":{
"type":"string",
"format":"email",
"minLength":1
},
"date":{
"type":"string",
"format":"custom-date-time",
"minLength":1
},
"status":{
"type":"string",
"format":"custom-boolean"
}
},
"required":[
"id",
"first_name",
"email",
"date",
"status"
],
"errorMessage":{
"properties":{
"first_name":"Only string(With character A-Z) type is accepted.",
"id":"Only valid integer format type is accepted",
"email":"Only Valid email ID format is accepted",
"date":"Only valid date format is accepted",
"status":"Only boolean is accepted"
}
}
}

Adding custom error messages

Developers can make use of errorMessage field to send custom validation errors to end user.

Example:

"errorMessage":{
"properties":{
"first_name":"Only string(With character A-Z) type is accepted.",
"id":"Only valid integer format type is accepted",
"email":"Only Valid email ID format is accepted",
"date":"Only valid date format is accepted",
"status":"Only boolean is accepted"
}
}