Skip to content

Commit 8fbca5a

Browse files
authored
Fix exclusiveMinimum and exclusiveMaximum for OpenAPI 3.0 (#1115)
1 parent 3dcb69b commit 8fbca5a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/main/java/com/networknt/schema/oas/OpenApi30.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ private static class Holder {
3131
ValidatorTypeCode.ENUM,
3232
ValidatorTypeCode.MINIMUM,
3333
ValidatorTypeCode.MAXIMUM,
34-
ValidatorTypeCode.EXCLUSIVE_MINIMUM,
35-
ValidatorTypeCode.EXCLUSIVE_MAXIMUM,
3634
ValidatorTypeCode.MULTIPLE_OF,
3735
ValidatorTypeCode.MIN_LENGTH,
3836
ValidatorTypeCode.MAX_LENGTH,

src/test/java/com/networknt/schema/oas/OpenApi30Test.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.networknt.schema.oas;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021

2122
import java.util.List;
@@ -28,6 +29,7 @@
2829
import com.networknt.schema.InputFormat;
2930
import com.networknt.schema.JsonSchema;
3031
import com.networknt.schema.JsonSchemaFactory;
32+
import com.networknt.schema.OutputFormat;
3133
import com.networknt.schema.PathType;
3234
import com.networknt.schema.SchemaLocation;
3335
import com.networknt.schema.SchemaValidatorsConfig;
@@ -82,4 +84,40 @@ void jsonPointerWithNumberInFragment() {
8284
assertEquals("$.paths['/pet'].post.responses['200'].content['application/json'].schema",
8385
schema.getEvaluationPath().toString());
8486
}
87+
88+
/**
89+
* Exclusive maximum true.
90+
*/
91+
@Test
92+
void exclusiveMaximum() {
93+
String schemaData = "{\r\n"
94+
+ " \"type\": \"number\",\r\n"
95+
+ " \"minimum\": 0,\r\n"
96+
+ " \"maximum\": 100,\r\n"
97+
+ " \"exclusiveMaximum\": true\r\n"
98+
+ "}\r\n"
99+
+ "";
100+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
101+
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
102+
JsonSchema schema = factory.getSchema(schemaData);
103+
assertFalse(schema.validate("100", InputFormat.JSON, OutputFormat.BOOLEAN));
104+
}
105+
106+
/**
107+
* Exclusive minimum true.
108+
*/
109+
@Test
110+
void exclusiveMinimum() {
111+
String schemaData = "{\r\n"
112+
+ " \"type\": \"number\",\r\n"
113+
+ " \"minimum\": 0,\r\n"
114+
+ " \"maximum\": 100,\r\n"
115+
+ " \"exclusiveMinimum\": true\r\n"
116+
+ "}\r\n"
117+
+ "";
118+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
119+
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
120+
JsonSchema schema = factory.getSchema(schemaData);
121+
assertFalse(schema.validate("0", InputFormat.JSON, OutputFormat.BOOLEAN));
122+
}
85123
}

0 commit comments

Comments
 (0)