Skip to content

Commit 6a20242

Browse files
committed
added typed default values
1 parent 2413642 commit 6a20242

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.wordnik.swagger.models.Xml;
44

55
public class BooleanProperty extends AbstractProperty implements Property {
6+
protected Boolean _default;
67
public BooleanProperty() {
78
super.type = "boolean";
89
}
@@ -15,10 +16,33 @@ public BooleanProperty example(Boolean example) {
1516
this.setExample(String.valueOf(example));
1617
return this;
1718
}
19+
public BooleanProperty _default(String _default) {
20+
try {
21+
this.setDefault(Boolean.parseBoolean(_default));
22+
}
23+
catch (Exception e) {
24+
//cotinue
25+
}
26+
return this;
27+
}
28+
public BooleanProperty _default(boolean _default) {
29+
this.setDefault(_default);
30+
return this;
31+
}
1832

1933
public static boolean isType(String type, String format) {
2034
if("boolean".equals(type))
2135
return true;
2236
else return false;
2337
}
38+
39+
public Boolean getDefault() {
40+
return _default;
41+
}
42+
public void setDefault(Boolean _default) {
43+
this._default = _default;
44+
}
45+
public void setDefault(String _default) {
46+
this._default(_default);
47+
}
2448
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4-
import com.fasterxml.jackson.annotation.JsonIgnore;
54

65
public class DoubleProperty extends AbstractNumericProperty implements Property {
76
protected Double _default;
@@ -31,7 +30,10 @@ public DoubleProperty _default(String _default) {
3130
}
3231
return this;
3332
}
34-
33+
public DoubleProperty _default(Double _default) {
34+
this.setDefault(_default);
35+
return this;
36+
}
3537
public static boolean isType(String type, String format) {
3638
if("number".equals(type) && "double".equals(format))
3739
return true;
@@ -44,7 +46,6 @@ public Double getDefault() {
4446
public void setDefault(Double _default) {
4547
this._default = _default;
4648
}
47-
@JsonIgnore
4849
public void setDefault(String _default) {
4950
this._default(_default);
5051
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4-
import com.fasterxml.jackson.annotation.JsonIgnore;
54

65
public class FloatProperty extends AbstractNumericProperty implements Property {
76
protected Float _default;
@@ -31,6 +30,10 @@ public FloatProperty _default(String _default) {
3130
}
3231
return this;
3332
}
33+
public FloatProperty _default(Float _default) {
34+
this.setDefault(_default);
35+
return this;
36+
}
3437

3538
public static boolean isType(String type, String format) {
3639
if("number".equals(type) && "float".equals(format))
@@ -44,7 +47,6 @@ public Float getDefault() {
4447
public void setDefault(Float _default) {
4548
this._default = _default;
4649
}
47-
@JsonIgnore
4850
public void setDefault(String _default) {
4951
this._default(_default);
5052
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.wordnik.swagger.models.properties;
22

33
import com.wordnik.swagger.models.Xml;
4-
import com.fasterxml.jackson.annotation.JsonIgnore;
54

65
public class IntegerProperty extends AbstractNumericProperty implements Property {
76
protected Integer _default;
@@ -31,6 +30,10 @@ public IntegerProperty _default(String _default) {
3130
}
3231
return this;
3332
}
33+
public IntegerProperty _default(Integer _default) {
34+
this.setDefault(_default);
35+
return this;
36+
}
3437

3538
public static boolean isType(String type, String format) {
3639
if("integer".equals(type) && "int32".equals(format))
@@ -44,7 +47,6 @@ public Integer getDefault() {
4447
public void setDefault(Integer _default) {
4548
this._default = _default;
4649
}
47-
@JsonIgnore
4850
public void setDefault(String _default) {
4951
this._default(_default);
5052
}

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

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

33
import com.wordnik.swagger.models.Xml;
4-
import com.fasterxml.jackson.annotation.JsonIgnore;
54

65
public class LongProperty extends AbstractNumericProperty implements Property {
76
protected Long _default;
@@ -44,7 +43,6 @@ public Long getDefault() {
4443
public void setDefault(Long _default) {
4544
this._default = _default;
4645
}
47-
@JsonIgnore
4846
public void setDefault(String _default) {
4947
this._default(_default);
5048
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public static Property build(String type, String format, Map<String, Object> arg
3232
Boolean uniqueItems = (Boolean)args.get("uniqueItems");
3333

3434
AbstractProperty property = null;
35-
if(BooleanProperty.isType(type, format))
36-
property = new BooleanProperty();
35+
if(BooleanProperty.isType(type, format)) {
36+
property = new BooleanProperty()
37+
._default(_default);
38+
}
3739
if(DateProperty.isType(type, format))
3840
property = new DateProperty();
3941
if(DateTimeProperty.isType(type, format))

0 commit comments

Comments
 (0)