Skip to content

Commit da41148

Browse files
committed
checking empty string in examples for #2783
1 parent 6d6d46e commit da41148

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) {
404404

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

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

Lines changed: 14 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,19 @@ 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 = "";
344+
345+
// when
346+
instance.setExample(example);
347+
348+
// then
349+
assertEquals(instance.getExample(), null, "The example must be null if the value is an empty string");
350+
}
351+
338352
@Test
339353
public void testGetExampleWithBooleanProperty() {
340354
// given

0 commit comments

Comments
 (0)