Skip to content

Commit

Permalink
Fix exclusiveMinimum and exclusiveMaximum for OpenAPI 3.0 (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay authored Sep 11, 2024
1 parent 3dcb69b commit 8fbca5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/networknt/schema/oas/OpenApi30.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ private static class Holder {
ValidatorTypeCode.ENUM,
ValidatorTypeCode.MINIMUM,
ValidatorTypeCode.MAXIMUM,
ValidatorTypeCode.EXCLUSIVE_MINIMUM,
ValidatorTypeCode.EXCLUSIVE_MAXIMUM,
ValidatorTypeCode.MULTIPLE_OF,
ValidatorTypeCode.MIN_LENGTH,
ValidatorTypeCode.MAX_LENGTH,
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/networknt/schema/oas/OpenApi30Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.networknt.schema.oas;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;
Expand All @@ -28,6 +29,7 @@
import com.networknt.schema.InputFormat;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.OutputFormat;
import com.networknt.schema.PathType;
import com.networknt.schema.SchemaLocation;
import com.networknt.schema.SchemaValidatorsConfig;
Expand Down Expand Up @@ -82,4 +84,40 @@ void jsonPointerWithNumberInFragment() {
assertEquals("$.paths['/pet'].post.responses['200'].content['application/json'].schema",
schema.getEvaluationPath().toString());
}

/**
* Exclusive maximum true.
*/
@Test
void exclusiveMaximum() {
String schemaData = "{\r\n"
+ " \"type\": \"number\",\r\n"
+ " \"minimum\": 0,\r\n"
+ " \"maximum\": 100,\r\n"
+ " \"exclusiveMaximum\": true\r\n"
+ "}\r\n"
+ "";
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
JsonSchema schema = factory.getSchema(schemaData);
assertFalse(schema.validate("100", InputFormat.JSON, OutputFormat.BOOLEAN));
}

/**
* Exclusive minimum true.
*/
@Test
void exclusiveMinimum() {
String schemaData = "{\r\n"
+ " \"type\": \"number\",\r\n"
+ " \"minimum\": 0,\r\n"
+ " \"maximum\": 100,\r\n"
+ " \"exclusiveMinimum\": true\r\n"
+ "}\r\n"
+ "";
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
JsonSchema schema = factory.getSchema(schemaData);
assertFalse(schema.validate("0", InputFormat.JSON, OutputFormat.BOOLEAN));
}
}

0 comments on commit 8fbca5a

Please sign in to comment.