Skip to content

Commit 2413642

Browse files
committed
update default values
1 parent 2214293 commit 2413642

File tree

10 files changed

+155
-22
lines changed

10 files changed

+155
-22
lines changed

modules/swagger-core/src/main/java/com/wordnik/swagger/util/PropertyDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Property propertyFromNode(JsonNode node) {
7272
description = (String) ((TextNode) detailNode).asText();
7373
detailNode = node.get("default");
7474
if(detailNode != null)
75-
_default = (String) ((TextNode) detailNode).asText();
75+
_default = detailNode.toString();
7676
detailNode = node.get("pattern");
7777
if(detailNode != null)
7878
pattern = (String) ((TextNode) detailNode).asText();

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/AbstractProperty.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public abstract class AbstractProperty implements Property {
77
String type;
88
String format;
99
String example;
10-
String _default;
1110
Xml xml;
1211
boolean required;
1312
Integer position;
@@ -23,10 +22,6 @@ public Property description(String description) {
2322
this.setDescription(description);
2423
return this;
2524
}
26-
public Property _default(String _default) {
27-
this.setDefault(_default);
28-
return this;
29-
}
3025
public Property readOnly() {
3126
this.setReadOnly(Boolean.TRUE);
3227
return this;
@@ -95,13 +90,6 @@ public void setDescription(String description) {
9590
this.description = description;
9691
}
9792

98-
public String getDefault() {
99-
return _default;
100-
}
101-
public void setDefault(String _default) {
102-
this._default = _default;
103-
}
104-
10593
public Boolean getReadOnly() {
10694
return readOnly;
10795
}
@@ -111,4 +99,8 @@ public void setReadOnly(Boolean readOnly) {
11199
else
112100
this.readOnly = readOnly;
113101
}
102+
103+
public void setDefault(String _default) {
104+
// do nothing
105+
}
114106
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/DoubleProperty.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45

56
public class DoubleProperty extends AbstractNumericProperty implements Property {
7+
protected Double _default;
8+
69
public DoubleProperty() {
710
super.type = "number";
811
super.format = "double";
@@ -17,9 +20,32 @@ public DoubleProperty example(Double example) {
1720
return this;
1821
}
1922

23+
public DoubleProperty _default(String _default) {
24+
if(_default != null) {
25+
try {
26+
this._default = Double.parseDouble(_default);
27+
}
28+
catch (NumberFormatException e) {
29+
// continue;
30+
}
31+
}
32+
return this;
33+
}
34+
2035
public static boolean isType(String type, String format) {
2136
if("number".equals(type) && "double".equals(format))
2237
return true;
2338
else return false;
2439
}
40+
41+
public Double getDefault() {
42+
return _default;
43+
}
44+
public void setDefault(Double _default) {
45+
this._default = _default;
46+
}
47+
@JsonIgnore
48+
public void setDefault(String _default) {
49+
this._default(_default);
50+
}
2551
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/FloatProperty.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45

56
public class FloatProperty extends AbstractNumericProperty implements Property {
7+
protected Float _default;
8+
69
public FloatProperty() {
710
super.type = "number";
811
super.format = "float";
@@ -17,9 +20,32 @@ public FloatProperty example(Float example) {
1720
return this;
1821
}
1922

23+
public FloatProperty _default(String _default) {
24+
if(_default != null) {
25+
try {
26+
this._default = Float.parseFloat(_default);
27+
}
28+
catch (NumberFormatException e) {
29+
// continue;
30+
}
31+
}
32+
return this;
33+
}
34+
2035
public static boolean isType(String type, String format) {
2136
if("number".equals(type) && "float".equals(format))
2237
return true;
2338
else return false;
2439
}
40+
41+
public Float getDefault() {
42+
return _default;
43+
}
44+
public void setDefault(Float _default) {
45+
this._default = _default;
46+
}
47+
@JsonIgnore
48+
public void setDefault(String _default) {
49+
this._default(_default);
50+
}
2551
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/IntegerProperty.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45

56
public class IntegerProperty extends AbstractNumericProperty implements Property {
7+
protected Integer _default;
8+
69
public IntegerProperty() {
710
super.type = "integer";
811
super.format = "int32";
@@ -17,9 +20,32 @@ public IntegerProperty example(Integer example) {
1720
return this;
1821
}
1922

23+
public IntegerProperty _default(String _default) {
24+
if(_default != null) {
25+
try {
26+
this._default = Integer.parseInt(_default);
27+
}
28+
catch (NumberFormatException e) {
29+
// continue;
30+
}
31+
}
32+
return this;
33+
}
34+
2035
public static boolean isType(String type, String format) {
2136
if("integer".equals(type) && "int32".equals(format))
2237
return true;
2338
else return false;
2439
}
40+
41+
public Integer getDefault() {
42+
return _default;
43+
}
44+
public void setDefault(Integer _default) {
45+
this._default = _default;
46+
}
47+
@JsonIgnore
48+
public void setDefault(String _default) {
49+
this._default(_default);
50+
}
2551
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/LongProperty.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45

56
public class LongProperty extends AbstractNumericProperty implements Property {
7+
protected Long _default;
8+
69
public LongProperty() {
710
super.type = "integer";
811
super.format = "int64";
@@ -17,9 +20,32 @@ public LongProperty example (Long example) {
1720
return this;
1821
}
1922

23+
public LongProperty _default(String _default) {
24+
if(_default != null) {
25+
try {
26+
this._default = Long.parseLong(_default);
27+
}
28+
catch (NumberFormatException e) {
29+
// continue;
30+
}
31+
}
32+
return this;
33+
}
34+
2035
public static boolean isType(String type, String format) {
2136
if("integer".equals(type) && "int64".equals(format))
2237
return true;
2338
else return false;
2439
}
40+
41+
public Long getDefault() {
42+
return _default;
43+
}
44+
public void setDefault(Long _default) {
45+
this._default = _default;
46+
}
47+
@JsonIgnore
48+
public void setDefault(String _default) {
49+
this._default(_default);
50+
}
2551
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/Property.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public interface Property {
2525
boolean getRequired();
2626
void setRequired(boolean required);
2727

28-
String getDefault();
29-
void setDefault(String _default);
30-
3128
String getExample();
3229
void setExample(String example);
3330

@@ -39,4 +36,6 @@ public interface Property {
3936

4037
Xml getXml();
4138
void setXml(Xml xml);
39+
40+
void setDefault(String _default);
4241
}

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/PropertyBuilder.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@ public static Property build(String type, String format, Map<String, Object> arg
3838
property = new DateProperty();
3939
if(DateTimeProperty.isType(type, format))
4040
property = new DateTimeProperty();
41-
if(DoubleProperty.isType(type, format))
41+
if(DoubleProperty.isType(type, format)) {
4242
property = new DoubleProperty()
43+
._default(_default)
4344
.minimum(minimum)
4445
.maximum(maximum)
4546
.exclusiveMinimum(exclusiveMinimum)
4647
.exclusiveMaximum(exclusiveMinimum);
47-
if(FloatProperty.isType(type, format))
48+
}
49+
if(FloatProperty.isType(type, format)) {
4850
property = new FloatProperty()
51+
._default(_default)
4952
.minimum(minimum)
5053
.maximum(maximum)
5154
.exclusiveMinimum(exclusiveMinimum)
5255
.exclusiveMaximum(exclusiveMinimum);
56+
}
5357
if(FileProperty.isType(type, format)) {
5458
property = new FileProperty();
5559
}
@@ -59,18 +63,22 @@ public static Property build(String type, String format, Map<String, Object> arg
5963
.maximum(maximum)
6064
.exclusiveMinimum(exclusiveMinimum)
6165
.exclusiveMaximum(exclusiveMinimum);
62-
if(IntegerProperty.isType(type, format))
66+
if(IntegerProperty.isType(type, format)) {
6367
property = new IntegerProperty()
68+
._default(_default)
6469
.minimum(minimum)
6570
.maximum(maximum)
6671
.exclusiveMinimum(exclusiveMinimum)
6772
.exclusiveMaximum(exclusiveMinimum);
68-
if(LongProperty.isType(type, format))
73+
}
74+
if(LongProperty.isType(type, format)) {
6975
property = new LongProperty()
76+
._default(_default)
7077
.minimum(minimum)
7178
.maximum(maximum)
7279
.exclusiveMinimum(exclusiveMinimum)
7380
.exclusiveMaximum(exclusiveMinimum);
81+
}
7482
if(RefProperty.isType(type, format))
7583
property = new RefProperty();
7684
if(EmailProperty.isType(type, format))
@@ -79,17 +87,21 @@ public static Property build(String type, String format, Map<String, Object> arg
7987
.maxLength(maxLength)
8088
.pattern(pattern)
8189
._enum(_enum);
82-
if(StringProperty.isType(type, format))
90+
if(StringProperty.isType(type, format)) {
8391
property = new StringProperty()
92+
._default(_default)
8493
.minLength(minLength)
8594
.maxLength(maxLength)
8695
.pattern(pattern)
8796
._enum(_enum);
88-
if(UUIDProperty.isType(type, format))
97+
}
98+
if(UUIDProperty.isType(type, format)) {
8999
property = new UUIDProperty()
100+
._default(_default)
90101
.minLength(minLength)
91102
.maxLength(maxLength)
92103
.pattern(pattern);
104+
}
93105
// general properties
94106
if(property != null) {
95107
property
@@ -105,6 +117,7 @@ public static Property build(String type, String format, Map<String, Object> arg
105117
// fall back to Integer if type is integer and format is missing
106118
LOGGER.debug("no format specified for integer type, falling back to int32");
107119
property = new IntegerProperty()
120+
._default(_default)
108121
.minimum(minimum)
109122
.maximum(maximum)
110123
.exclusiveMinimum(exclusiveMinimum)

modules/swagger-models/src/main/java/com/wordnik/swagger/models/properties/StringProperty.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45

56
import java.util.*;
67

78
public class StringProperty extends AbstractProperty implements Property {
89
protected List<String> _enum;
910
protected Integer minLength = null, maxLength = null;
1011
protected String pattern = null;
12+
protected String _default;
1113

1214
public StringProperty() {
1315
super.type = "string";
@@ -43,6 +45,10 @@ public StringProperty _enum(List<String> value) {
4345
this._enum = value;
4446
return this;
4547
}
48+
public StringProperty _default(String _default) {
49+
this._default = _default;
50+
return this;
51+
}
4652

4753
public List<String> getEnum() {
4854
return _enum;
@@ -72,6 +78,13 @@ public void setPattern(String pattern) {
7278
this.pattern = pattern;
7379
}
7480

81+
public String getDefault() {
82+
return _default;
83+
}
84+
public void setDefault(String _default) {
85+
this._default = _default;
86+
}
87+
7588
//TODO: implement additional formats
7689
public static boolean isType(String type, String format) {
7790
if("string".equals(type) && (format == null || "uri".equals(format) || "byte".equals(format)))

0 commit comments

Comments
 (0)