Skip to content

Commit

Permalink
Fixed #14
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 20, 2013
1 parent 8230242 commit 45debbd
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 121 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ JSON Schema (http://tools.ietf.org/html/draft-zyp-json-schema-03) version 3 gene
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<excludes>
<exclude>com/fasterxml/jackson/module/jsonSchema/failing/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,7 +294,6 @@ public Boolean getRequired() {
@JsonIgnore
public abstract JsonFormatTypes getType();


/**
* determine if this JsonSchema is an {@link AnySchema}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Exists to supply {@link SchemaFactoryWrapper} or its subclasses
* to nested schema factories.
* @author jphelan
*
*/
public class WrapperFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,11 +26,7 @@ of enum values uses the same algorithm as defined in "uniqueItems"
@JsonProperty(value = "enum")
private Set<String> enums;

@JsonIgnore
private final JsonFormatTypes type = JsonFormatTypes.ANY;

//instance initializer block
{
public AnySchema() {
enums = new HashSet<String>();
}

Expand Down Expand Up @@ -66,7 +61,7 @@ public boolean equals(Object obj) {
*/
@Override
public JsonFormatTypes getType() {
return type;
return JsonFormatTypes.ANY;
}

public void setEnums(Set<String> enums) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
empty jsonSchema which allows any value for items in the instance array.
*/
public class ArraySchema extends ContainerTypeSchema {


/**
* see {@link AdditionalItems}
*/
Expand All @@ -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).
Expand Down Expand Up @@ -110,7 +105,7 @@ public Integer getMinItems() {
*/
@Override
public JsonFormatTypes getType() {
return type;
return JsonFormatTypes.ARRAY;
}

public Boolean getUniqueItems() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
*/
Expand All @@ -25,7 +20,7 @@ public class BooleanSchema extends ValueTypeSchema {
*/
@Override
public JsonFormatTypes getType() {
return type;
return JsonFormatTypes.BOOLEAN;
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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; }

Expand All @@ -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() {
Expand All @@ -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
Expand Down
Loading

0 comments on commit 45debbd

Please sign in to comment.