Skip to content

Commit 45debbd

Browse files
committed
Fixed #14
1 parent 8230242 commit 45debbd

File tree

17 files changed

+187
-121
lines changed

17 files changed

+187
-121
lines changed

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,18 @@ JSON Schema (http://tools.ietf.org/html/draft-zyp-json-schema-03) version 3 gene
8181
<scope>test</scope>
8282
</dependency>
8383
</dependencies>
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>${surefire.version}</version>
90+
<configuration>
91+
<excludes>
92+
<exclude>com/fasterxml/jackson/module/jsonSchema/failing/*.java</exclude>
93+
</excludes>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
8498
</project>

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Project: jackson-module-jsonSchema
22
Version: 2.3.0 (xx-xxx-2013)
33

4+
#14: Generated schema contains multiple 'type' values
5+
(reported by Arul D; aruld@github)
46
#18: Add mechanism to customize schema for property
57
(suggested by rpdai)
68

src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
@JsonInclude(JsonInclude.Include.NON_EMPTY)
7272
@JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type")
7373
@JsonTypeIdResolver(JsonSchemaIdResolver.class)
74-
public abstract class JsonSchema {
75-
74+
public abstract class JsonSchema
75+
{
7676
/**
7777
* This attribute defines a URI of a schema that contains the full
7878
* representation of this schema. When a validator encounters this
@@ -294,7 +294,6 @@ public Boolean getRequired() {
294294
@JsonIgnore
295295
public abstract JsonFormatTypes getType();
296296

297-
298297
/**
299298
* determine if this JsonSchema is an {@link AnySchema}.
300299
*

src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/SchemaFactoryWrapper.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,30 @@ public void setProvider(SerializerProvider p) {
4747

4848
@Override
4949
public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType) {
50-
AnySchema anySchema = schemaProvider.anySchema();
51-
schema = anySchema;
52-
return visitorFactory.anyFormatVisitor(anySchema);
50+
AnySchema s = schemaProvider.anySchema();
51+
this.schema = s;
52+
return visitorFactory.anyFormatVisitor(s);
5353
}
5454

5555
@Override
5656
public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType) {
57-
ArraySchema arraySchema = schemaProvider.arraySchema();
58-
schema = arraySchema;
59-
return visitorFactory.arrayFormatVisitor(provider, arraySchema);
57+
ArraySchema s = schemaProvider.arraySchema();
58+
this.schema = s;
59+
return visitorFactory.arrayFormatVisitor(provider, s);
6060
}
6161

6262
@Override
6363
public JsonBooleanFormatVisitor expectBooleanFormat(JavaType convertedType) {
64-
BooleanSchema booleanSchema = schemaProvider.booleanSchema();
65-
schema = booleanSchema;
66-
return visitorFactory.booleanFormatVisitor(booleanSchema);
64+
BooleanSchema s = schemaProvider.booleanSchema();
65+
this.schema = s;
66+
return visitorFactory.booleanFormatVisitor(s);
6767
}
6868

6969
@Override
7070
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType convertedType) {
71-
IntegerSchema integerSchema = schemaProvider.integerSchema();
72-
schema = integerSchema;
73-
return visitorFactory.integerFormatVisitor(integerSchema);
71+
IntegerSchema s = schemaProvider.integerSchema();
72+
this.schema = s;
73+
return visitorFactory.integerFormatVisitor(s);
7474
}
7575

7676
@Override
@@ -89,16 +89,16 @@ public JsonNumberFormatVisitor expectNumberFormat(JavaType convertedType) {
8989

9090
@Override
9191
public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) {
92-
ObjectSchema objectSchema = schemaProvider.objectSchema();
93-
schema = objectSchema;
94-
return visitorFactory.objectFormatVisitor(provider, objectSchema);
92+
ObjectSchema s = schemaProvider.objectSchema();
93+
schema = s;
94+
return visitorFactory.objectFormatVisitor(provider, s);
9595
}
9696

9797
@Override
9898
public JsonStringFormatVisitor expectStringFormat(JavaType convertedType) {
99-
StringSchema stringSchema = schemaProvider.stringSchema();
100-
schema = stringSchema;
101-
return visitorFactory.stringFormatVisitor(stringSchema);
99+
StringSchema s = schemaProvider.stringSchema();
100+
schema = s;
101+
return visitorFactory.stringFormatVisitor(s);
102102
}
103103

104104
@Override
@@ -109,9 +109,9 @@ public JsonMapFormatVisitor expectMapFormat(JavaType type)
109109
* concept of Map (distinct from Record or Object); so best
110110
* we can do is to consider it a vague kind-a Object...
111111
*/
112-
ObjectSchema objectSchema = schemaProvider.objectSchema();
113-
schema = objectSchema;
114-
return visitorFactory.mapFormatVisitor(provider, objectSchema);
112+
ObjectSchema s = schemaProvider.objectSchema();
113+
schema = s;
114+
return visitorFactory.mapFormatVisitor(provider, s);
115115
}
116116

117117
/*

src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/WrapperFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Exists to supply {@link SchemaFactoryWrapper} or its subclasses
77
* to nested schema factories.
88
* @author jphelan
9-
*
109
*/
1110
public class WrapperFactory {
1211

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AnySchema.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6-
import com.fasterxml.jackson.annotation.JsonIgnore;
76
import com.fasterxml.jackson.annotation.JsonProperty;
87
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
98
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
@@ -27,11 +26,7 @@ of enum values uses the same algorithm as defined in "uniqueItems"
2726
@JsonProperty(value = "enum")
2827
private Set<String> enums;
2928

30-
@JsonIgnore
31-
private final JsonFormatTypes type = JsonFormatTypes.ANY;
32-
33-
//instance initializer block
34-
{
29+
public AnySchema() {
3530
enums = new HashSet<String>();
3631
}
3732

@@ -66,7 +61,7 @@ public boolean equals(Object obj) {
6661
*/
6762
@Override
6863
public JsonFormatTypes getType() {
69-
return type;
64+
return JsonFormatTypes.ANY;
7065
}
7166

7267
public void setEnums(Set<String> enums) {

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ArraySchema.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
empty jsonSchema which allows any value for items in the instance array.
1616
*/
1717
public class ArraySchema extends ContainerTypeSchema {
18-
19-
2018
/**
2119
* see {@link AdditionalItems}
2220
*/
@@ -37,9 +35,6 @@ public class ArraySchema extends ContainerTypeSchema {
3735
@JsonProperty
3836
private Integer minItems;
3937

40-
@JsonIgnore
41-
private final JsonFormatTypes type = JsonFormatTypes.ARRAY;
42-
4338
/**
4439
* This attribute indicates that all items in an array instance MUST be
4540
unique (contains no two identical values).
@@ -110,7 +105,7 @@ public Integer getMinItems() {
110105
*/
111106
@Override
112107
public JsonFormatTypes getType() {
113-
return type;
108+
return JsonFormatTypes.ARRAY;
114109
}
115110

116111
public Boolean getUniqueItems() {

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/BooleanSchema.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.module.jsonSchema.types;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
43
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
54
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
65

@@ -10,10 +9,6 @@
109
*
1110
*/
1211
public class BooleanSchema extends ValueTypeSchema {
13-
14-
@JsonIgnore
15-
private final JsonFormatTypes type = JsonFormatTypes.BOOLEAN;
16-
1712
/* (non-Javadoc)
1813
* @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#isBooleanSchema()
1914
*/
@@ -25,7 +20,7 @@ public class BooleanSchema extends ValueTypeSchema {
2520
*/
2621
@Override
2722
public JsonFormatTypes getType() {
28-
return type;
23+
return JsonFormatTypes.BOOLEAN;
2924
}
3025

3126
/* (non-Javadoc)

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/IntegerSchema.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,45 @@
99
* @author jphelan
1010
*
1111
*/
12-
public class IntegerSchema extends NumberSchema {
13-
12+
public class IntegerSchema extends NumberSchema
13+
{
1414
/**
1515
* This attribute defines what value the number instance must be
1616
divisible by with no remainder (the result of the division must be an
1717
integer.) The value of this attribute SHOULD NOT be 0.
1818
*/
19-
@JsonProperty
2019
private Integer divisibleBy;
2120

22-
@JsonProperty(required = true)
23-
public final JsonFormatTypes type = JsonFormatTypes.INTEGER;
24-
25-
@Override
26-
public IntegerSchema asIntegerSchema() { return this; }
27-
28-
/* (non-Javadoc)
29-
* @see com.fasterxml.jackson.databind.jsonSchema.types.NumberSchema#equals(java.lang.Object)
30-
*/
31-
@Override
32-
public boolean equals(Object obj) {
33-
if (obj instanceof IntegerSchema) {
21+
@Override
22+
public boolean isIntegerSchema() { return true; }
23+
24+
@Override
25+
public JsonFormatTypes getType() {
26+
return JsonFormatTypes.INTEGER;
27+
}
28+
29+
@Override
30+
public IntegerSchema asIntegerSchema() { return this; }
31+
32+
@JsonProperty
33+
public Integer getDivisibleBy() {
34+
return divisibleBy;
35+
}
36+
37+
public void setDivisibleBy(Integer divisibleBy) {
38+
this.divisibleBy = divisibleBy;
39+
}
40+
41+
@Override
42+
public boolean equals(Object obj)
43+
{
44+
if (obj == this) return true;
45+
if (obj instanceof IntegerSchema) {
3446
IntegerSchema that = (IntegerSchema)obj;
3547
return getDivisibleBy() == null ? that.getDivisibleBy() == null :
3648
getDivisibleBy().equals(that.getDivisibleBy()) &&
3749
super.equals(obj);
38-
} else {
39-
return false;
40-
}
50+
}
51+
return false;
4152
}
42-
43-
public Integer getDivisibleBy() {
44-
return divisibleBy;
45-
}
46-
47-
@Override
48-
public boolean isIntegerSchema() { return true; }
49-
50-
public void setDivisibleBy(Integer divisibleBy) {
51-
this.divisibleBy = divisibleBy;
52-
}
5353
}

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/NullSchema.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
package com.fasterxml.jackson.module.jsonSchema.types;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
43
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
4+
55
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
66

77
/**
88
* This class represents a {@link JsonSchema} as a null type
99
* @author jphelan
1010
*/
11-
public class NullSchema extends SimpleTypeSchema {
12-
13-
@JsonIgnore
14-
private final JsonFormatTypes type = JsonFormatTypes.NULL;
15-
11+
public class NullSchema extends SimpleTypeSchema
12+
{
1613
@Override
1714
public NullSchema asNullSchema() { return this; }
1815

19-
/* (non-Javadoc)
20-
* @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#equals(java.lang.Object)
21-
*/
2216
@Override
2317
public boolean equals(Object obj) {
2418
return (obj instanceof NullSchema && super.equals(obj));
2519
}
2620

27-
/* (non-Javadoc)
28-
* @see com.fasterxml.jackson.databind.jsonSchema.types.JsonSchema#getType()
29-
*/
3021
@Override
3122
public JsonFormatTypes getType() {
32-
return type;
23+
return JsonFormatTypes.NULL;
3324
}
3425

3526
@Override

0 commit comments

Comments
 (0)