networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
860 stars 325 forks source link

"Unknown keyword exclusiveMinimun" when validating an OpenAPI 3.0 document #1119

Closed sonallux closed 2 weeks ago

sonallux commented 1 month ago

I am currently trying to validate an OpenAPI 3.0 document using the json-schema-validator library and I am getting the following warning when creating the JsonSchema object:

[main] WARN com.networknt.schema.UnknownKeywordFactory - Unknown keyword exclusiveMinimum - you should define your own Meta Schema. If the keyword is irrelevant for validation, just use a NonValidationKeyword or if it should generate annotations AnnotationKeyword

I am using this code to create the JsonSchema object:

return JsonSchemaFactory
    .getInstance(SpecVersion.VersionFlag.V4)
    .getSchema(SchemaLocation.of("https://spec.openapis.org/oas/3.0/schema/latest"));

What is wrong with this and why am I getting the message printed to the console?

jkosternl commented 1 month ago

Which version of the library did you use @sonallux? Please always specify that in a question. In v.1.5.2 that keyword was changed a bit in OpenAPI 3.0, see #1114 Make sure you are using it in the right way. You can also check src/test/java/com/networknt/schema/oas/OpenApi30Test.java as an example.

sonallux commented 3 weeks ago

@jkosternl I am using the v1.5.2. But the Issue is also present in the recently released v1.5.3.

The examples in src/test/java/com/networknt/schema/oas/OpenApi30Test.java are different to the use case I have. I want to validate a complete OpenAPI 3.0 definition file against the official OpenAPI 3.0 schema.

Here is a more complete example:

@Test
void testOpenApiValidation() throws Exception {
    var schema = JsonSchemaFactory
        .getInstance(VersionFlag.V4)
        .getSchema(SchemaLocation.of("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/schemas/v3.0/schema.yaml"));

    var result = schema.validate(Files.readString(Path.of("petstore.yaml")), InputFormat.YAML);

    assertEquals(0, result.size());
}
stevehu commented 3 weeks ago

You cannot use v4 for OpenAPI 3.0. Try the latest version and let us know if it works.

sonallux commented 3 weeks ago

You cannot use v4 for OpenAPI 3.0. Try the latest version and let us know if it works.

@stevehu thanks for your reply. But I do not understand it.

The OpenAPI 3.0 Schema file is explicitly mentioning it is using JsonSchema v4 here. Also the SpecVersionDetector is is reporting v4 for the OpenAPI 3.0 Schema.