Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date and date-time #979

Closed
KOFKOY opened this issue Feb 29, 2024 · 5 comments
Closed

date and date-time #979

KOFKOY opened this issue Feb 29, 2024 · 5 comments

Comments

@KOFKOY
Copy link

KOFKOY commented Feb 29, 2024

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

@KOFKOY
Copy link
Author

KOFKOY commented Feb 29, 2024

version 1.3.3

@justin-tay
Copy link
Contributor

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.

@KOFKOY
Copy link
Author

KOFKOY commented Mar 1, 2024

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.

@KOFKOY
Copy link
Author

KOFKOY commented Mar 1, 2024

After testing, I found that version 1.1.0 does not have this problem with time verification.

@justin-tay
Copy link
Contributor

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());
    }
}

@justin-tay justin-tay closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants