Closed KOFKOY closed 6 months ago
version 1.3.3
Your schema is not valid and there is insufficient information to reproduce. As you are using the format
keyword it is possible you are using a dialect where format assertions aren't enabled and therefore the data matches both as the type is string.
Your schema is not valid and there is insufficient information to reproduce. As you are using the
format
keyword it is possible you are using a dialect where format assertions aren't enabled and therefore the data matches both as the type is string.
This is a jsonschema file downloaded from Amazon. I can't change its format. I'll try another version or look at the source code.
After testing, I found that version 1.1.0 does not have this problem with time verification.
Closing as this cannot be reproduced.
package com.networknt.schema;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import com.networknt.schema.SpecVersion.VersionFlag;
public class Issue969Test {
@Test
void test() {
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.setFormatAssertionsEnabled(true);
String schemaData = "{\r\n"
+ " \"oneOf\": [\r\n"
+ " {\r\n"
+ " \"format\": \"date\"\r\n"
+ " },\r\n"
+ " {\r\n"
+ " \"format\": \"date-time\"\r\n"
+ " }\r\n"
+ " ]\r\n"
+ "}";
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V202012).getSchema(schemaData, config);
assertTrue(schema.validate("\"2024-02-23\"", InputFormat.JSON).isEmpty());
assertFalse(schema.validate("\"2024-02-30\"", InputFormat.JSON).isEmpty());
assertTrue(schema.validate("\"2021-12-31T23:59:59Z\"", InputFormat.JSON).isEmpty());
assertFalse(schema.validate("\"2021-12-31T23:59:59\"", InputFormat.JSON).isEmpty());
}
}
example: my jsonschema: "restock_date" : { "title" : "Restock Date", "description" : "Date that product will be restocked", "editable" : true, "hidden" : false, "examples" : [ "2020-05-05" ], "type" : "string", "oneOf" : [ { "type" : "string", "format" : "date" }, { "type" : "string", "format" : "date-time" } ] }
Data that needs to be verified: "restock_date" : "2024-02-23"
===============================
This verification will report an error with error code 1022. It should satisfy all the conditions in oneOf at the same time