|
9 | 9 | import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
|
10 | 10 | import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema;
|
11 | 11 | import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema;
|
| 12 | +import junit.framework.Assert; |
12 | 13 |
|
13 | 14 | /**
|
14 | 15 | * Trivial test to ensure {@link JsonSchema} can be also deserialized
|
@@ -126,7 +127,7 @@ public void _testSimple(String name, JsonSchema jsonSchema) throws Exception
|
126 | 127 | String json2 = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(finalNode);
|
127 | 128 |
|
128 | 129 | // assertEquals(node, finalNode);
|
129 |
| - assertEquals("Schemas for "+name+" differ", |
| 130 | + assertEquals("Schemas for " + name + " differ", |
130 | 131 | json1, json2);
|
131 | 132 | }
|
132 | 133 |
|
@@ -155,4 +156,49 @@ public void testDeserializeTrueAdditionalProperties() throws Exception
|
155 | 156 | ObjectSchema schema = MAPPER.readValue(schemaStr, ObjectSchema.class);
|
156 | 157 | assertNull(schema.getAdditionalProperties());
|
157 | 158 | }
|
| 159 | + |
| 160 | + /** |
| 161 | + * Verifies that a true-valued additional property is deserialized properly |
| 162 | + */ |
| 163 | + public void testOneOf() throws Exception |
| 164 | + { |
| 165 | + String schemaStr = "{\n" + |
| 166 | + " \"id\": \"http://some.site.somewhere/entry-schema#\",\n" + |
| 167 | + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + |
| 168 | + " \"description\": \"schema for an fstab entry\",\n" + |
| 169 | + " \"type\": \"object\",\n" + |
| 170 | + //" \"required\": [ \"storage\" ],\n" + |
| 171 | + " \"properties\": {\n" + |
| 172 | + " \"storage\": {\n" + |
| 173 | + " \"type\": \"object\",\n" + |
| 174 | + " \"oneOf\": [\n" + |
| 175 | + " { \"$ref\": \"#/definitions/diskDevice\" },\n" + |
| 176 | + " { \"$ref\": \"#/definitions/diskUUID\" },\n" + |
| 177 | + " { \"$ref\": \"#/definitions/nfs\" },\n" + |
| 178 | + " { \"$ref\": \"#/definitions/tmpfs\" }\n" + |
| 179 | + " ]\n" + |
| 180 | + " },\n" + |
| 181 | + " \"fstype\": {\n" + |
| 182 | + " \"type\": \"object\",\n" + |
| 183 | + " \"enum\": [ \"ext3\", \"ext4\", \"btrfs\" ]\n" + |
| 184 | + " },\n" + |
| 185 | + " \"options\": {\n" + |
| 186 | + " \"type\": \"array\",\n" + |
| 187 | + " \"minItems\": 1,\n" + |
| 188 | + " \"items\": { \"type\": \"string\" },\n" + |
| 189 | + " \"uniqueItems\": true\n" + |
| 190 | + " },\n" + |
| 191 | + " \"readonly\": { \"type\": \"boolean\" }\n" + |
| 192 | + " }\n" + |
| 193 | +// " \"definitions\": {\n" + |
| 194 | +// " \"diskDevice\": {},\n" + |
| 195 | +// " \"diskUUID\": {},\n" + |
| 196 | +// " \"nfs\": {},\n" + |
| 197 | +// " \"tmpfs\": {}\n" + |
| 198 | +// " }\n" + |
| 199 | + "}"; |
| 200 | + ObjectSchema schema = MAPPER.readValue(schemaStr, ObjectSchema.class); |
| 201 | + assertNotNull(schema.getProperties().get("storage").asObjectSchema().getOneOf()); |
| 202 | + assertEquals(4,schema.getProperties().get("storage").asObjectSchema().getOneOf().size()); |
| 203 | + } |
158 | 204 | }
|
0 commit comments