diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ContainerTypeSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ContainerTypeSchema.java index ba5c9330..665c6b9f 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ContainerTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ContainerTypeSchema.java @@ -24,15 +24,32 @@ of enum values uses the same algorithm as defined in "uniqueItems" */ @JsonProperty(value = "enum", required = true) private Set enums; - - //instance initializer block + + //instance initializer block { enums = new HashSet(); } - - /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#asContainerSchema() + /** + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). */ + @JsonProperty(value = "oneOf", required = true) + private Set oneOf; + //instance initializer block + { + oneOf = new HashSet(); + } + + + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#asContainerSchema() + */ @Override public ContainerTypeSchema asContainerSchema() { return this; } @@ -60,4 +77,12 @@ public Set getEnums() { public void setEnums(Set enums) { this.enums = enums; } + + public Set getOneOf() { + return oneOf; + } + + public void setOneOf(Set oneOf) { + this.oneOf = oneOf; + } } \ No newline at end of file diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java index ff9a5fd7..849aae38 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema; import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema; +import junit.framework.Assert; /** * Trivial test to ensure {@link JsonSchema} can be also deserialized @@ -126,7 +127,7 @@ public void _testSimple(String name, JsonSchema jsonSchema) throws Exception String json2 = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(finalNode); // assertEquals(node, finalNode); - assertEquals("Schemas for "+name+" differ", + assertEquals("Schemas for " + name + " differ", json1, json2); } @@ -155,4 +156,49 @@ public void testDeserializeTrueAdditionalProperties() throws Exception ObjectSchema schema = MAPPER.readValue(schemaStr, ObjectSchema.class); assertNull(schema.getAdditionalProperties()); } + + /** + * Verifies that a true-valued additional property is deserialized properly + */ + public void testOneOf() throws Exception + { + String schemaStr = "{\n" + + " \"id\": \"http://some.site.somewhere/entry-schema#\",\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"description\": \"schema for an fstab entry\",\n" + + " \"type\": \"object\",\n" + + //" \"required\": [ \"storage\" ],\n" + + " \"properties\": {\n" + + " \"storage\": {\n" + + " \"type\": \"object\",\n" + + " \"oneOf\": [\n" + + " { \"$ref\": \"#/definitions/diskDevice\" },\n" + + " { \"$ref\": \"#/definitions/diskUUID\" },\n" + + " { \"$ref\": \"#/definitions/nfs\" },\n" + + " { \"$ref\": \"#/definitions/tmpfs\" }\n" + + " ]\n" + + " },\n" + + " \"fstype\": {\n" + + " \"type\": \"object\",\n" + + " \"enum\": [ \"ext3\", \"ext4\", \"btrfs\" ]\n" + + " },\n" + + " \"options\": {\n" + + " \"type\": \"array\",\n" + + " \"minItems\": 1,\n" + + " \"items\": { \"type\": \"string\" },\n" + + " \"uniqueItems\": true\n" + + " },\n" + + " \"readonly\": { \"type\": \"boolean\" }\n" + + " }\n" + +// " \"definitions\": {\n" + +// " \"diskDevice\": {},\n" + +// " \"diskUUID\": {},\n" + +// " \"nfs\": {},\n" + +// " \"tmpfs\": {}\n" + +// " }\n" + + "}"; + ObjectSchema schema = MAPPER.readValue(schemaStr, ObjectSchema.class); + assertNotNull(schema.getProperties().get("storage").asObjectSchema().getOneOf()); + assertEquals(4,schema.getProperties().get("storage").asObjectSchema().getOneOf().size()); + } }