Getting invalid JSON Schema, cannot continue error when using the generated schema file in matchesJsonSchemaInClasspath function
nikesh363 opened this issue · 5 comments
Sample Json:
{
"status": 400,
"message": "Bad Request - Send Request in application/json Format",
"response": {}
}
Generated Schema:
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"status": 400,
"message": "Bad Request - Send Request in application/json Format",
"response": {}
}
],
"required": [
"status",
"message",
"response"
],
"additionalProperties": true,
"properties": {
"status": {
"$id": "#/properties/status",
"type": "integer",
"title": "The status schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
400
]
},
"message": {
"$id": "#/properties/message",
"type": "string",
"title": "The message schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Bad Request - Send Request in application/json Format"
]
},
"response": {
"$id": "#/properties/response",
"type": "object",
"title": "The response schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{}
],
"required": [],
"additionalProperties": true,
"properties": {}
}
}
}
### Note: I generated schema for same structured JSON a few days ago. And that is working fine. I can see some difference in older and newer schema files. Below is the file for reference
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The Root Schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"additionalProperties": true,
"required": [
"status",
"message",
"response"
],
"properties": {
"status": {
"$id": "#/properties/status",
"type": "integer",
"title": "The Status Schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1001.0
]
},
"message": {
"$id": "#/properties/message",
"type": "string",
"title": "The Message Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Member does not exist"
]
},
"response": {
"$id": "#/properties/response",
"type": "object",
"title": "The Response Schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{}
],
"additionalProperties": true
}
}
}
Removing : "required": [],", present in response object works.
@nikesh363 How are you validating your JSON document? As a side not, if you don't want the required
keyword, you can always turn if off in the settings:
@jsonsystems I am using restassured json schema validator class. Sample code is below :
import io.restassured.response.Response;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
public class ValidateResponseSchema {
public static void validateResponseSchema(Response response, String schemaFilePath){
response.then().assertThat().body(matchesJsonSchemaInClasspath(schemaFilePath));
}
}
@nikesh363 How are you validating your JSON document? As a side not, if you don't want the
required
keyword, you can always turn if off in the settings:
Thanks, it worked. Just curious to know how it starts generating schema with the required field. Any update happened? I have not done any settings changes.
@nikesh363 you're correct, an update was release that ensured the required
keyword was visible unless explicitly hidden using the settings.