diff --git a/modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java b/modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java index 87604521aa..26beba92e4 100644 --- a/modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java +++ b/modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java @@ -404,8 +404,8 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) { @JsonProperty("x-example") public Object getExample() { - if (example == null) { - return null; + if (example == null || example.isEmpty()) { + return example; } try { if (BaseIntegerProperty.TYPE.equals(type)) { diff --git a/modules/swagger-models/src/test/java/io/swagger/models/parameters/AbstractSerializableParameterTest.java b/modules/swagger-models/src/test/java/io/swagger/models/parameters/AbstractSerializableParameterTest.java index 50ed6fba61..de6376c0a2 100644 --- a/modules/swagger-models/src/test/java/io/swagger/models/parameters/AbstractSerializableParameterTest.java +++ b/modules/swagger-models/src/test/java/io/swagger/models/parameters/AbstractSerializableParameterTest.java @@ -4,6 +4,7 @@ import io.swagger.models.properties.BaseIntegerProperty; import io.swagger.models.properties.BooleanProperty; import io.swagger.models.properties.DecimalProperty; +import io.swagger.models.properties.LongProperty; import io.swagger.models.properties.Property; import io.swagger.models.properties.StringProperty; import org.testng.annotations.BeforeMethod; @@ -335,6 +336,26 @@ public void testGetExampleWithDecimalProperty() { "The example value must not change when when set an array property"); } + @Test + public void testGetExampleWithEmptyString() { + // given + instance.setProperty(new LongProperty()); + example = null; + + // when + instance.setExample(example); + + // then + assertEquals(instance.getExample(), null, "The example must be null if the value is null"); + + // given + instance.setProperty(new LongProperty()); + example = ""; + + // then + assertEquals(instance.getExample(), null, "The example must be empty string if the value is an empty string"); + } + @Test public void testGetExampleWithBooleanProperty() { // given