Json Schema, strictProperties for date-time formatMinimum and formatMaximum - json

I'm having problems with Json Schema when I'm trying to validate date-time value between interval of time [2013-11-17T00:00Z, 2015-11-17T00:00Z] I have this Json Schema:
{
"strictProperties": true ,
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"exampleDate": {
"format": "date-time",
"formatMinimum": "2013-11-17T00:00Z",
"formatMaximum": "2015-11-17T00:00Z"
}
}
}
},
"required": [
"data"
]
}
And with this json always out is as valid json:
{
"data": {
"exampleDate": "2010-11-17T00:00:00Z"
}
}
But as you can see, this json is not valid because of the date, it is out of valid range.
I've tested in online tools http://www.jsonschemavalidator.net/, http://jsonschemalint.com/draft4/# and with com.github.fge:json-schema-validator:2.2.6. Could someone help me please? Maybe I missing some configuration besides strictProperties? some step?. Thanks in advance =)

formatMinimum and formatMaximum are not in JSON Schema v4 draft. They are proposed features for v5:
https://github.com/json-schema/json-schema/wiki/formatMinimum-(v5-proposal)
However, this library can validate formatMinimum and formatMaximum using the v5 option:
https://github.com/epoberezkin/ajv#features

Related

How to setup ResponseType (Net Core 6) based on JSON Schema

I have a large number of APIs, each without a strong class definition for output, like this
Return Ok(New With {
.ServerDecryptPass = ServerDecryptPass,
.VmConnectionAdminDecryptPass = VmConnectionAdminDecryptPass,
.DockerHubDecryptPass = DockerHubDecryptPass,
.DockerRegistryDecryptPass = DockerRegistryDecryptPass,
.VmConnectionUserDecryptPass = VmConnectionUserDecryptPass
})
Swagger, of course, doesn't see anything for response type in this case
The simplest way to formalize this JSON result is creating a JSON schema, for example in this case it looks like
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"serverDecryptPass": {
"type": "object",
"properties": {
"item1": {
"type": "array",
"items": {
"type": "number"
}
},
"item2": {
"type": "null"
}
}
},
"vmConnectionAdminDecryptPass": {
...
}
I have a hundreds of APIs and I am searching for a simple way to formalize the output of the APIs in order to generate a frontend automatically from this backend API. I searched for a simple way to setup the attribute, ProducesResponseType, based on XML schema or maybe even an example of an API result.
What is a possible solution?

JSON Schema Validation Error in MarkLogic - XDMP-VALIDATEERRORS

Using MarkLogic version 10.0-4.2, I am trying to validate a simple JSON record against a simple JSON schema.
JSON Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"SourceSystemName": {
"type": "string"
},
"BatchDtTm": {
"type": "string"
},
"SubjectArea": {
"type": "string"
},
"DocumentType": {
"type": "string"
},
"LastUpdatedDt": {
"type": "string"
},
"required": [
"SourceSystemName",
"BatchDtTm",
"SubjectArea",
"DocumentType",
"LastUpdatedDt",
]
}
}
Code being run in Query Console:
let jsonRecord = {"SourceSystemName":"ODH","BatchDtTm":"09/17/21 08:51:48:472723","SubjectArea":"Customer","DocumentType":"Preference","LastUpdatedDt":"09/17/21 03:59:53:629707"};
xdmp.jsonValidate(jsonRecord, cts.doc('/schemas/NewSchema.json').toString());
When I run the above code, I get error
XDMP-JSVALIDATEBADSCHEMA: Invalid schema "": ""
I'm not really sure what is 'invalid' about my schema. Can someone offer some insight into what MarkLogic is viewing as 'invalid'?
The second parameter for $schema is supposed to be the URI of the schema document.
$schema URI of the JSON schema to use for validation.
You are attempting to pass in the stringified content.
Try:
xdmp.jsonValidate(jsonRecord, '/schemas/NewSchema.json');
And ensure that the schema document is inserted into the Schemas database, not the content database.

Generate JSON payload based on JSON schema for API payload validation

I am looking for a way to generate random payloads in JSON based on the provided schema. Looking around I found something useful but with not a lot of github stars. LINK
Objective
To be able to validate multiple possible values for a field in the payload based on the schema provided.
Example
For schema -
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
Possible payloads -
{
"name": "ABCDEFGHIJKLMNOPQRSTUVWXYZA"
}
{
"name": "ERTERER"
}
I hope my request for suggestion was clear.

JSON Schema Validation validate array items not working

Here is the thing I'm trying to validate:
[REMOVED AFTER EDIT - PLEASE SEE EDIT BELOW FOR UP TO DATE CODE]
This should fail because only the item that should be acceptable here is "merchants" - but the validation doesn't fail. It passes.
I've can't work this out. I've tried a few approaches and it's got me nowhere.
What is wrong here?
---------------------- EDIT ----------------------------
I've been asked to provide more code. Here is the payload I need to validate. It's in PHP.
$payload = (object) [];
$payload->query_string = (object) [];
$payload->query_string->include = (object) [
"merchant_channel",
"merchant",
];
Here is the line that will run the validator:
$this->validator->validate(
$payload,
['$ref' => 'file://Schemas/the-json-file.json']
);
And here is the file that I'm running the validator against:
{
"type": "object",
"properties": {
"query_string": {
"type": "object",
"properties": {
"include": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"allOf": [
{
"type": "string",
"enum": [
"language"
]
}
]
}
}
}
}
}
}
}
}
I'm using this package:
https://github.com/justinrainbow/json-schema
This package is quite simply....
A PHP Implementation for validating JSON Structures against a given Schema.
You shouldn't have to know PHP to able to answer my original question which is specific to JSON Schema Validation!
Please don't comment/answer saying something like "You've missed a quote" or "You've missed a closing bracket". Obviously I've had to cut this code down so I can post it on Stack Overflow.
It lacks starting and ending curly braces.

Verifying JSON schema for uri and string together?

I am verifying below JSON schema for two separate JSON response which are same but only one difference is one returns 'system' as a string in format of uri and other returns plain string which cause failing of my second test case because for the second response it also look for a string in uri format.
How can i solve this issue in my schema?
{
"id": "/coding",
"type": "array",
"items": {
"type": "object",
"properties": {
"system": {
"type": "string"
"format": "uri"
}
}
}
}
You could just remove "format": "uri" from your schema.