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
859 stars 325 forks source link

OpenAPI Spec 3.0 validation should not require exclusiveMinimum to be a number #1114

Closed jkosternl closed 2 months ago

jkosternl commented 2 months ago

As specified in https://spec.openapis.org/oas/3.0/schema/latest.html the field exclusiveMinimum is a boolean. But while using the example code in doc/openapi.md and changing it to the 3.0 instances, the validation fails with an JsonSchemaException: exclusiveMinimum value is not a number at ExclusiveMinimumValidator.java:45

I used it like this:

  JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4,
    builder -> builder.metaSchema(OpenApi30.getInstance())
      .defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));

   jsonSchema =
    factory.getSchema(
      SchemaLocation.of("classpath:" + filePath + "#/components/schemas/" + schemaName));

and also tried VersionFlag.V7 and other variants.

Expected behavior:

 "value": {
    "minimum": 0,
    "exclusiveMinimum": true,

should validate just fine, with OpenAPI 3.0 and draft 4.

Note: in OpenAPI 3.1 this is changed to a number.

justin-tay commented 2 months ago

Thanks for the bug report. You are correct that in OpenAPI 3.0 it should be a boolean.

jkosternl commented 2 months ago

Thanks very much @justin-tay and @stevehu for responding and fixing this issue that fast! 👍🏻 Really appreciated.