|
16 | 16 | package com.networknt.schema.oas;
|
17 | 17 |
|
18 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
20 | 21 |
|
21 | 22 | import java.util.List;
|
|
28 | 29 | import com.networknt.schema.InputFormat;
|
29 | 30 | import com.networknt.schema.JsonSchema;
|
30 | 31 | import com.networknt.schema.JsonSchemaFactory;
|
| 32 | +import com.networknt.schema.OutputFormat; |
31 | 33 | import com.networknt.schema.PathType;
|
32 | 34 | import com.networknt.schema.SchemaLocation;
|
33 | 35 | import com.networknt.schema.SchemaValidatorsConfig;
|
@@ -82,4 +84,40 @@ void jsonPointerWithNumberInFragment() {
|
82 | 84 | assertEquals("$.paths['/pet'].post.responses['200'].content['application/json'].schema",
|
83 | 85 | schema.getEvaluationPath().toString());
|
84 | 86 | }
|
| 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 | + } |
85 | 123 | }
|
0 commit comments