|
17 | 17 |
|
18 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; |
19 | 19 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
20 | 21 |
|
21 | 22 | import java.util.Collections; |
22 | 23 | import java.util.List; |
@@ -134,4 +135,95 @@ void classPathNoSlash() { |
134 | 135 | + "}"; |
135 | 136 | assertFalse(schema.validate(inputData, InputFormat.JSON, OutputFormat.BOOLEAN)); |
136 | 137 | } |
| 138 | + |
| 139 | + @Test |
| 140 | + void refSiblingId07AndBelow() { |
| 141 | + String schemaData = "{\r\n" |
| 142 | + + " \"$id\": \"http://localhost:1234/sibling_id/base/\",\r\n" |
| 143 | + + " \"definitions\": {\r\n" |
| 144 | + + " \"foo\": {\r\n" |
| 145 | + + " \"$id\": \"http://localhost:1234/sibling_id/foo.json\",\r\n" |
| 146 | + + " \"type\": \"string\"\r\n" |
| 147 | + + " },\r\n" |
| 148 | + + " \"base_foo\": {\r\n" |
| 149 | + + " \"$comment\": \"this canonical uri is http://localhost:1234/sibling_id/base/foo.json\",\r\n" |
| 150 | + + " \"$id\": \"foo.json\",\r\n" |
| 151 | + + " \"type\": \"number\"\r\n" |
| 152 | + + " }\r\n" |
| 153 | + + " },\r\n" |
| 154 | + + " \"allOf\": [\r\n" |
| 155 | + + " {\r\n" |
| 156 | + + " \"$comment\": \"$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json\",\r\n" |
| 157 | + + " \"$id\": \"http://localhost:1234/sibling_id/\",\r\n" |
| 158 | + + " \"$ref\": \"foo.json\"\r\n" |
| 159 | + + " }\r\n" |
| 160 | + + " ]\r\n" |
| 161 | + + "}"; |
| 162 | + SchemaRegistry factory = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7); |
| 163 | + Schema schema = factory.getSchema(schemaData); |
| 164 | + String inputData = "1"; |
| 165 | + assertTrue(schema.validate(inputData, InputFormat.JSON, OutputFormat.BOOLEAN)); |
| 166 | + } |
| 167 | + |
| 168 | + @Test |
| 169 | + void refSiblingId201909AndAbove() { |
| 170 | + String schemaData = "{\r\n" |
| 171 | + + " \"$id\": \"http://localhost:1234/sibling_id/base/\",\r\n" |
| 172 | + + " \"definitions\": {\r\n" |
| 173 | + + " \"foo\": {\r\n" |
| 174 | + + " \"$id\": \"http://localhost:1234/sibling_id/foo.json\",\r\n" |
| 175 | + + " \"type\": \"string\"\r\n" |
| 176 | + + " },\r\n" |
| 177 | + + " \"base_foo\": {\r\n" |
| 178 | + + " \"$comment\": \"this canonical uri is http://localhost:1234/sibling_id/base/foo.json\",\r\n" |
| 179 | + + " \"$id\": \"foo.json\",\r\n" |
| 180 | + + " \"type\": \"number\"\r\n" |
| 181 | + + " }\r\n" |
| 182 | + + " },\r\n" |
| 183 | + + " \"allOf\": [\r\n" |
| 184 | + + " {\r\n" |
| 185 | + + " \"$comment\": \"$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json\",\r\n" |
| 186 | + + " \"$id\": \"http://localhost:1234/sibling_id/\",\r\n" |
| 187 | + + " \"$ref\": \"foo.json\"\r\n" |
| 188 | + + " }\r\n" |
| 189 | + + " ]\r\n" |
| 190 | + + "}"; |
| 191 | + SchemaRegistry factory = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2019_09); |
| 192 | + Schema schema = factory.getSchema(schemaData); |
| 193 | + String inputData = "\"a\""; |
| 194 | + assertTrue(schema.validate(inputData, InputFormat.JSON, OutputFormat.BOOLEAN)); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + void refSiblingIdInner201909AndAbove() { |
| 199 | + String schemaData = "{\r\n" |
| 200 | + + " \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\r\n" |
| 201 | + + " \"$id\": \"http://example.com/schema-relative-uri-defs1.json\",\r\n" |
| 202 | + + " \"properties\": {\r\n" |
| 203 | + + " \"foo\": {\r\n" |
| 204 | + + " \"$id\": \"schema-relative-uri-defs2.json\",\r\n" |
| 205 | + + " \"$defs\": {\r\n" |
| 206 | + + " \"inner\": {\r\n" |
| 207 | + + " \"properties\": {\r\n" |
| 208 | + + " \"bar\": {\r\n" |
| 209 | + + " \"type\": \"string\"\r\n" |
| 210 | + + " }\r\n" |
| 211 | + + " }\r\n" |
| 212 | + + " }\r\n" |
| 213 | + + " },\r\n" |
| 214 | + + " \"$ref\": \"#/$defs/inner\"\r\n" |
| 215 | + + " }\r\n" |
| 216 | + + " },\r\n" |
| 217 | + + " \"$ref\": \"schema-relative-uri-defs2.json\"\r\n" |
| 218 | + + "}"; |
| 219 | + SchemaRegistry factory = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2019_09); |
| 220 | + Schema schema = factory.getSchema(schemaData); |
| 221 | + String inputData = "{\r\n" |
| 222 | + + " \"foo\": {\r\n" |
| 223 | + + " \"bar\": \"a\"\r\n" |
| 224 | + + " },\r\n" |
| 225 | + + " \"bar\": \"a\"\r\n" |
| 226 | + + "}"; |
| 227 | + assertTrue(schema.validate(inputData, InputFormat.JSON, OutputFormat.BOOLEAN)); |
| 228 | + } |
137 | 229 | } |
0 commit comments