From 45debbda7668da102cf7680a6bb4e0549ad142cb Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 19 Sep 2013 21:38:09 -0700 Subject: [PATCH] Fixed #14 --- pom.xml | 14 +++++ release-notes/VERSION | 2 + .../jackson/module/jsonSchema/JsonSchema.java | 5 +- .../factories/SchemaFactoryWrapper.java | 42 +++++++------- .../jsonSchema/factories/WrapperFactory.java | 1 - .../module/jsonSchema/types/AnySchema.java | 9 +-- .../module/jsonSchema/types/ArraySchema.java | 7 +-- .../jsonSchema/types/BooleanSchema.java | 7 +-- .../jsonSchema/types/IntegerSchema.java | 58 +++++++++---------- .../module/jsonSchema/types/NullSchema.java | 17 ++---- .../module/jsonSchema/types/NumberSchema.java | 21 +++---- .../module/jsonSchema/types/ObjectSchema.java | 12 ++-- .../module/jsonSchema/types/StringSchema.java | 8 +-- .../module/jsonSchema/SchemaTestBase.java | 4 ++ .../jsonSchema/TestGenerateJsonSchema.java | 18 +++--- .../module/jsonSchema/TestTypeGeneration.java | 34 +++++++++++ .../jsonSchema/failing/TestUnwrapping.java | 49 ++++++++++++++++ 17 files changed, 187 insertions(+), 121 deletions(-) create mode 100644 src/test/java/com/fasterxml/jackson/module/jsonSchema/TestTypeGeneration.java create mode 100644 src/test/java/com/fasterxml/jackson/module/jsonSchema/failing/TestUnwrapping.java diff --git a/pom.xml b/pom.xml index 7b214994..7fc0ee3f 100644 --- a/pom.xml +++ b/pom.xml @@ -81,4 +81,18 @@ JSON Schema (http://tools.ietf.org/html/draft-zyp-json-schema-03) version 3 gene test + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + com/fasterxml/jackson/module/jsonSchema/failing/*.java + + + + + diff --git a/release-notes/VERSION b/release-notes/VERSION index 0f214cfb..017cc156 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,6 +1,8 @@ Project: jackson-module-jsonSchema Version: 2.3.0 (xx-xxx-2013) +#14: Generated schema contains multiple 'type' values + (reported by Arul D; aruld@github) #18: Add mechanism to customize schema for property (suggested by rpdai) diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java index f224b120..6a04fd4a 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java @@ -71,8 +71,8 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type") @JsonTypeIdResolver(JsonSchemaIdResolver.class) -public abstract class JsonSchema { - +public abstract class JsonSchema +{ /** * This attribute defines a URI of a schema that contains the full * representation of this schema. When a validator encounters this @@ -294,7 +294,6 @@ public Boolean getRequired() { @JsonIgnore public abstract JsonFormatTypes getType(); - /** * determine if this JsonSchema is an {@link AnySchema}. * diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/SchemaFactoryWrapper.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/SchemaFactoryWrapper.java index 1521e8e8..7ebba0e5 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/SchemaFactoryWrapper.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/SchemaFactoryWrapper.java @@ -47,30 +47,30 @@ public void setProvider(SerializerProvider p) { @Override public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType) { - AnySchema anySchema = schemaProvider.anySchema(); - schema = anySchema; - return visitorFactory.anyFormatVisitor(anySchema); + AnySchema s = schemaProvider.anySchema(); + this.schema = s; + return visitorFactory.anyFormatVisitor(s); } @Override public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType) { - ArraySchema arraySchema = schemaProvider.arraySchema(); - schema = arraySchema; - return visitorFactory.arrayFormatVisitor(provider, arraySchema); + ArraySchema s = schemaProvider.arraySchema(); + this.schema = s; + return visitorFactory.arrayFormatVisitor(provider, s); } @Override public JsonBooleanFormatVisitor expectBooleanFormat(JavaType convertedType) { - BooleanSchema booleanSchema = schemaProvider.booleanSchema(); - schema = booleanSchema; - return visitorFactory.booleanFormatVisitor(booleanSchema); + BooleanSchema s = schemaProvider.booleanSchema(); + this.schema = s; + return visitorFactory.booleanFormatVisitor(s); } @Override public JsonIntegerFormatVisitor expectIntegerFormat(JavaType convertedType) { - IntegerSchema integerSchema = schemaProvider.integerSchema(); - schema = integerSchema; - return visitorFactory.integerFormatVisitor(integerSchema); + IntegerSchema s = schemaProvider.integerSchema(); + this.schema = s; + return visitorFactory.integerFormatVisitor(s); } @Override @@ -89,16 +89,16 @@ public JsonNumberFormatVisitor expectNumberFormat(JavaType convertedType) { @Override public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) { - ObjectSchema objectSchema = schemaProvider.objectSchema(); - schema = objectSchema; - return visitorFactory.objectFormatVisitor(provider, objectSchema); + ObjectSchema s = schemaProvider.objectSchema(); + schema = s; + return visitorFactory.objectFormatVisitor(provider, s); } @Override public JsonStringFormatVisitor expectStringFormat(JavaType convertedType) { - StringSchema stringSchema = schemaProvider.stringSchema(); - schema = stringSchema; - return visitorFactory.stringFormatVisitor(stringSchema); + StringSchema s = schemaProvider.stringSchema(); + schema = s; + return visitorFactory.stringFormatVisitor(s); } @Override @@ -109,9 +109,9 @@ public JsonMapFormatVisitor expectMapFormat(JavaType type) * concept of Map (distinct from Record or Object); so best * we can do is to consider it a vague kind-a Object... */ - ObjectSchema objectSchema = schemaProvider.objectSchema(); - schema = objectSchema; - return visitorFactory.mapFormatVisitor(provider, objectSchema); + ObjectSchema s = schemaProvider.objectSchema(); + schema = s; + return visitorFactory.mapFormatVisitor(provider, s); } /* diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/WrapperFactory.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/WrapperFactory.java index 1a2656ff..685ae059 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/WrapperFactory.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/WrapperFactory.java @@ -6,7 +6,6 @@ * Exists to supply {@link SchemaFactoryWrapper} or its subclasses * to nested schema factories. * @author jphelan - * */ public class WrapperFactory { diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AnySchema.java index 6aebc5a4..74cdb316 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AnySchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AnySchema.java @@ -3,7 +3,6 @@ import java.util.HashSet; import java.util.Set; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; @@ -27,11 +26,7 @@ of enum values uses the same algorithm as defined in "uniqueItems" @JsonProperty(value = "enum") private Set enums; - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.ANY; - - //instance initializer block - { + public AnySchema() { enums = new HashSet(); } @@ -66,7 +61,7 @@ public boolean equals(Object obj) { */ @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.ANY; } public void setEnums(Set enums) { diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ArraySchema.java index f8b4af79..10f82bdd 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ArraySchema.java @@ -15,8 +15,6 @@ empty jsonSchema which allows any value for items in the instance array. */ public class ArraySchema extends ContainerTypeSchema { - - /** * see {@link AdditionalItems} */ @@ -37,9 +35,6 @@ public class ArraySchema extends ContainerTypeSchema { @JsonProperty private Integer minItems; - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.ARRAY; - /** * This attribute indicates that all items in an array instance MUST be unique (contains no two identical values). @@ -110,7 +105,7 @@ public Integer getMinItems() { */ @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.ARRAY; } public Boolean getUniqueItems() { diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/BooleanSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/BooleanSchema.java index 5096bea6..fa9afeca 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/BooleanSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/BooleanSchema.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.module.jsonSchema.types; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; @@ -10,10 +9,6 @@ * */ public class BooleanSchema extends ValueTypeSchema { - - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.BOOLEAN; - /* (non-Javadoc) * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#isBooleanSchema() */ @@ -25,7 +20,7 @@ public class BooleanSchema extends ValueTypeSchema { */ @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.BOOLEAN; } /* (non-Javadoc) diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/IntegerSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/IntegerSchema.java index 7efc64f6..06540186 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/IntegerSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/IntegerSchema.java @@ -9,45 +9,45 @@ * @author jphelan * */ -public class IntegerSchema extends NumberSchema { - +public class IntegerSchema extends NumberSchema +{ /** * This attribute defines what value the number instance must be divisible by with no remainder (the result of the division must be an integer.) The value of this attribute SHOULD NOT be 0. */ - @JsonProperty private Integer divisibleBy; - @JsonProperty(required = true) - public final JsonFormatTypes type = JsonFormatTypes.INTEGER; - - @Override - public IntegerSchema asIntegerSchema() { return this; } - - /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonSchema.types.NumberSchema#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof IntegerSchema) { + @Override + public boolean isIntegerSchema() { return true; } + + @Override + public JsonFormatTypes getType() { + return JsonFormatTypes.INTEGER; + } + + @Override + public IntegerSchema asIntegerSchema() { return this; } + + @JsonProperty + public Integer getDivisibleBy() { + return divisibleBy; + } + + public void setDivisibleBy(Integer divisibleBy) { + this.divisibleBy = divisibleBy; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) return true; + if (obj instanceof IntegerSchema) { IntegerSchema that = (IntegerSchema)obj; return getDivisibleBy() == null ? that.getDivisibleBy() == null : getDivisibleBy().equals(that.getDivisibleBy()) && super.equals(obj); - } else { - return false; - } + } + return false; } - - public Integer getDivisibleBy() { - return divisibleBy; - } - - @Override - public boolean isIntegerSchema() { return true; } - - public void setDivisibleBy(Integer divisibleBy) { - this.divisibleBy = divisibleBy; - } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NullSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NullSchema.java index 98cd7667..d0ea960c 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NullSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NullSchema.java @@ -1,35 +1,26 @@ package com.fasterxml.jackson.module.jsonSchema.types; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; + import com.fasterxml.jackson.module.jsonSchema.JsonSchema; /** * This class represents a {@link JsonSchema} as a null type * @author jphelan */ -public class NullSchema extends SimpleTypeSchema { - - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.NULL; - +public class NullSchema extends SimpleTypeSchema +{ @Override public NullSchema asNullSchema() { return this; } - /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { return (obj instanceof NullSchema && super.equals(obj)); } - /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#getType() - */ @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.NULL; } @Override diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NumberSchema.java index ce216a62..a1db6fa3 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NumberSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NumberSchema.java @@ -1,17 +1,17 @@ package com.fasterxml.jackson.module.jsonSchema.types; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; + import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; + import com.fasterxml.jackson.module.jsonSchema.JsonSchema; /** * This class represents a {@link JsonSchema} as a number type * @author jphelan - * */ -public class NumberSchema extends ValueTypeSchema { - +public class NumberSchema extends ValueTypeSchema +{ /** * This attribute indicates if the value of the instance (if the instance is a number) can not equal the number defined by the @@ -35,10 +35,7 @@ public class NumberSchema extends ValueTypeSchema { /**This attribute defines the minimum value of the instance property*/ @JsonProperty private Double minimum = null; - - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.NUMBER; - + @Override public NumberSchema asNumberSchema() { return this; } @@ -58,9 +55,8 @@ public boolean equals(Object obj) { getMinimum() == null ? that.getMinimum() == null : getMinimum().equals(that.getMinimum()) && super.equals(obj); - } else { - return false; } + return false; } public Boolean getExclusiveMaximum() { @@ -83,8 +79,9 @@ public Double getMinimum() { * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#getType() */ @Override - public JsonFormatTypes getType() { - return type; + public JsonFormatTypes getType() + { + return JsonFormatTypes.NUMBER; } @Override diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java index f16fccc5..a9c2baec 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java @@ -6,19 +6,20 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; + import com.fasterxml.jackson.databind.BeanProperty; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; + import com.fasterxml.jackson.module.jsonSchema.JsonSchema; /** * This type represents a {@link JsonSchema} as an object type * @author jphelan */ -public class ObjectSchema extends ContainerTypeSchema { - +public class ObjectSchema extends ContainerTypeSchema +{ /** * This attribute defines a jsonSchema for all properties that are not * explicitly defined in an object type definition. If specified, the value @@ -65,9 +66,6 @@ public class ObjectSchema extends ContainerTypeSchema { @JsonProperty private Map properties; - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.OBJECT; - public ObjectSchema() { dependencies = new ArrayList(); @@ -133,7 +131,7 @@ public Map getProperties() { @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.OBJECT; } @Override diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/StringSchema.java index 50341d01..3c4ed9a3 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/StringSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/StringSchema.java @@ -1,8 +1,9 @@ package com.fasterxml.jackson.module.jsonSchema.types; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; + import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; + import com.fasterxml.jackson.module.jsonSchema.JsonSchema; /** @@ -26,9 +27,6 @@ public class StringSchema extends ValueTypeSchema { */ @JsonProperty private String pattern; - - @JsonIgnore - private final JsonFormatTypes type = JsonFormatTypes.STRING; /* (non-Javadoc) * @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#asStringSchema() @@ -71,7 +69,7 @@ public String getPattern() { @Override public JsonFormatTypes getType() { - return type; + return JsonFormatTypes.STRING; } @Override diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/SchemaTestBase.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/SchemaTestBase.java index 27785f45..434c89c2 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/SchemaTestBase.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/SchemaTestBase.java @@ -122,6 +122,10 @@ protected enum EnumWithSubClass { private final static ObjectMapper SHARED_MAPPER = new ObjectMapper(); + protected ObjectMapper objectMapper() { + return SHARED_MAPPER; + } + protected ObjectWriter objectWriter() { return SHARED_MAPPER.writer(); } diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java index 547abb01..47cb90fb 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java @@ -4,18 +4,18 @@ import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonProperty; + import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; + import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema; import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema.Items; -/** - * @author Ryan Heaton - */ +@SuppressWarnings("serial") public class TestGenerateJsonSchema extends SchemaTestBase { @@ -94,7 +94,6 @@ public static class BeanWithId { public String value; } - @JsonFilter("filteredBean") protected static class FilteredBean { @JsonProperty @@ -121,7 +120,6 @@ public static class LetterBean { public Enumerated letter; } - @SuppressWarnings("serial") static class StringMap extends HashMap { } /* @@ -133,10 +131,9 @@ static class StringMap extends HashMap { } private final ObjectMapper MAPPER = new ObjectMapper(); /** - * tests generating json-schema stuff. + * Test simple generation */ - public void testGeneratingJsonSchema() - throws Exception + public void testGeneratingJsonSchema() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(SimpleBean.class); @@ -237,7 +234,7 @@ public void testThatObjectsHaveNoItems() throws Exception assertFalse(result.containsKey("items")); } - @SuppressWarnings({ "unchecked", "rawtypes", "serial" }) + @SuppressWarnings({ "unchecked", "rawtypes" }) public void testSchemaId() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); @@ -255,7 +252,6 @@ public void testSchemaId() throws Exception }}, result); } - @SuppressWarnings("serial") public void testWithEnum() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); @@ -288,7 +284,7 @@ public void testSimpleMap() throws Exception // Maps are treated like ... "empty" Object. Not good, should be improved if possible assertEquals("{\"type\":\"object\"}", MAPPER.writeValueAsString(jsonSchema)); } - + /* /********************************************************** /* Tests cases, error detection/handling diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestTypeGeneration.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestTypeGeneration.java new file mode 100644 index 00000000..fce9c826 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestTypeGeneration.java @@ -0,0 +1,34 @@ +package com.fasterxml.jackson.module.jsonSchema; + +import java.util.Date; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; +import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; + +public class TestTypeGeneration extends SchemaTestBase +{ + static class Issue14Bean + { + public Date date; + } + + /* + /********************************************************** + /* Unit tests + /********************************************************** + */ + + final ObjectMapper MAPPER = objectMapper(); + + // [Issue#14]: multiple type attributes + public void testCorrectType() throws Exception + { + JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); + JsonSchema jsonSchema = generator.generateSchema(Issue14Bean.class); + String json = MAPPER.writeValueAsString(jsonSchema).replace('"', '\''); + final String EXP = "{'type':'object','properties':{'date':{'type':'integer','format':'UTC_MILLISEC'}}}"; + assertEquals(EXP, json); + } + +} diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/failing/TestUnwrapping.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/failing/TestUnwrapping.java new file mode 100644 index 00000000..3deb4510 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/failing/TestUnwrapping.java @@ -0,0 +1,49 @@ +package com.fasterxml.jackson.module.jsonSchema.failing; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; +import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; +import com.fasterxml.jackson.module.jsonSchema.SchemaTestBase; + +public class TestUnwrapping extends SchemaTestBase +{ + static class UnwrappingRoot + { + public int age; + + @JsonUnwrapped + public Name name; + } + + static class Name { + @JsonUnwrapped(prefix="name.") + public String first, last; + } + + /* + /********************************************************** + /* Unit tests, success + /********************************************************** + */ + + private final ObjectMapper MAPPER = new ObjectMapper(); + + public void testUnwrapping() throws Exception + { + JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); + JsonSchema schema = generator.generateSchema(UnwrappingRoot.class); + + String json = MAPPER.writeValueAsString(schema).replace('"', '\''); + +//System.err.println("JSON -> "+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(schema)); + String EXP = "{'type':'object','properties':{" + +"'name.last':{'type':'string'},'name.first':{'type':'string'}," + +"'age':{'type':'number','type':'integer'}}}"; + +System.err.println("EXP: "+EXP); +System.err.println("ACT: "+json); + + assertEquals(EXP, json); + } +}