Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/test/java/com/networknt/schema/Issue1260Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.networknt.schema;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class Issue1260Test extends BaseJsonSchemaValidatorTest {

private static final String RESOURCE_PREFIX = "issues/1260/";
private static Schema schema;

@BeforeAll
static void setup() {
schema = getJsonSchemaFromClasspath(resource("schema.json"), SpecificationVersion.DRAFT_2020_12);
}

@ParameterizedTest
@ValueSource(strings = {"valid1.json", "valid2.json", "valid3.json"})
void testNoErrorsForValidInput(String validJson) throws IOException {
final var node = getJsonNodeFromClasspath(resource(validJson));
final var errors = schema.validate(node);
assertTrue(errors.isEmpty(), "No validation errors for valid input");
}

@ParameterizedTest
@ValueSource(strings = {"invalid1.json", "invalid2.json", "invalid3.json"})
void testErrorsForInvalidInput(String invalidJson) throws IOException {
final var node = getJsonNodeFromClasspath(resource(invalidJson));
final var errors = schema.validate(node);
assertFalse(errors.isEmpty(), "Validation errors for invalid input");
}

private static String resource(String name) {
return RESOURCE_PREFIX + name;
}
}
16 changes: 16 additions & 0 deletions src/test/resources/issues/1260/invalid1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"questions": null
}
}
}
}
}
21 changes: 21 additions & 0 deletions src/test/resources/issues/1260/invalid2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"onDemandAssessmentExpirationDays": 180,
"questions": {
"assessmentDate": {
"type": "date"
}
}
}
}
}
}
}
21 changes: 21 additions & 0 deletions src/test/resources/issues/1260/invalid3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"onDemandAssessmentExpirationDays": 180,
"questions": {
"expirationDate": {
"type": "date"
}
}
}
}
}
}
}
172 changes: 172 additions & 0 deletions src/test/resources/issues/1260/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"labeledField": {
"type": "object",
"properties": {
"label": {
"type": "string"
}
}
},
"question": {
"type": "object",
"unevaluatedProperties": false,
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"date"
]
}
}
},
"questions": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/question"
}
},
"assessmentDef": {
"type": "object",
"unevaluatedProperties": false,
"required": [
"recurrence"
],
"properties": {
"recurrence": {
"type": "string",
"enum": [
"once",
"monthly",
"ondemand"
],
"default": "once"
},
"relatedObjectType": {
"type": "string",
"enum": [
"otherEntity"
]
},
"onDemandAssessmentExpirationDays": {
"type": "integer",
"minimum": 1
},
"label": {
"type": "string"
},
"questions": {
"$ref": "#/$defs/questions"
}
},
"dependentSchemas": {
"recurrence": {
"oneOf": [
{
"properties": {
"recurrence": {
"enum": [
"monthly"
]
}
}
},
{
"properties": {
"recurrence": {
"enum": [
"once"
]
}
},
"required": [
"relatedObjectType"
]
},
{
"properties": {
"recurrence": {
"enum": [
"ondemand"
]
},
"questions": {
"properties": {
"allOf": [
{
"$ref": "#/$defs/questions"
},
{
"assessmentDate": "#/$defs/question"
},
{
"expirationDate": "#/$defs/question"
}
]
},
"required": [
"assessmentDate"
]
}
}
}
]
},
"onDemandAssessmentExpirationDays": {
"oneOf": [
{
"properties": {
"questions": {
"properties": {
"expirationDate": "#/$defs/question"
},
"required": [
"expirationDate"
]
}
}
}
]
}
}
}
},
"type": "object",
"additionalProperties": false,
"required": [
"fields"
],
"properties": {
"fields": {
"type": "object",
"additionalProperties": false,
"required": [
"entity"
],
"properties": {
"entity": {
"type": "object",
"additionalProperties": false,
"required": [
"status"
],
"properties": {
"status": {
"$ref": "#/$defs/labeledField"
},
"assessments": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/assessmentDef"
}
}
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions src/test/resources/issues/1260/valid1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"questions": {
"assessmentDate": {
"type": "date"
}
}
}
}
}
}
}
23 changes: 23 additions & 0 deletions src/test/resources/issues/1260/valid2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"questions": {
"assessmentDate": {
"type": "date"
},
"expirationDate": {
"type": "date"
}
}
}
}
}
}
}
24 changes: 24 additions & 0 deletions src/test/resources/issues/1260/valid3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"fields": {
"entity": {
"status": {
"label": "Status"
},
"assessments": {
"entityOndemand": {
"label": "Ondemand assessment of entity",
"recurrence": "ondemand",
"onDemandAssessmentExpirationDays": 180,
"questions": {
"assessmentDate": {
"type": "date"
},
"expirationDate": {
"type": "date"
}
}
}
}
}
}
}