Skip to content

Commit 480f09d

Browse files
authored
Merge pull request #2874 from swagger-api/issue-2783
refs #2783 - avoid NumberFormatException warning with empty String in param example
2 parents 6d6d46e + 3e7ba14 commit 480f09d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) {
404404

405405
@JsonProperty("x-example")
406406
public Object getExample() {
407-
if (example == null) {
408-
return null;
407+
if (example == null || example.isEmpty()) {
408+
return example;
409409
}
410410
try {
411411
if (BaseIntegerProperty.TYPE.equals(type)) {

modules/swagger-models/src/test/java/io/swagger/models/parameters/AbstractSerializableParameterTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.swagger.models.properties.BaseIntegerProperty;
55
import io.swagger.models.properties.BooleanProperty;
66
import io.swagger.models.properties.DecimalProperty;
7+
import io.swagger.models.properties.LongProperty;
78
import io.swagger.models.properties.Property;
89
import io.swagger.models.properties.StringProperty;
910
import org.testng.annotations.BeforeMethod;
@@ -335,6 +336,26 @@ public void testGetExampleWithDecimalProperty() {
335336
"The example value must not change when when set an array property");
336337
}
337338

339+
@Test
340+
public void testGetExampleWithEmptyString() {
341+
// given
342+
instance.setProperty(new LongProperty());
343+
example = null;
344+
345+
// when
346+
instance.setExample(example);
347+
348+
// then
349+
assertEquals(instance.getExample(), null, "The example must be null if the value is null");
350+
351+
// given
352+
instance.setProperty(new LongProperty());
353+
example = "";
354+
355+
// then
356+
assertEquals(instance.getExample(), null, "The example must be empty string if the value is an empty string");
357+
}
358+
338359
@Test
339360
public void testGetExampleWithBooleanProperty() {
340361
// given

0 commit comments

Comments
 (0)