Skip to content

Commit 3e7ba14

Browse files
committed
refs #2783 - avoid NumberFormatException warning with empty String in param example
1 parent da41148 commit 3e7ba14

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
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
@@ -405,7 +405,7 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) {
405405
@JsonProperty("x-example")
406406
public Object getExample() {
407407
if (example == null || example.isEmpty()) {
408-
return null;
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,20 @@ public void testGetExampleWithDecimalProperty() {
340340
public void testGetExampleWithEmptyString() {
341341
// given
342342
instance.setProperty(new LongProperty());
343-
example = "";
343+
example = null;
344344

345345
// when
346346
instance.setExample(example);
347347

348348
// then
349-
assertEquals(instance.getExample(), null, "The example must be null if the value is an empty string");
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");
350357
}
351358

352359
@Test

0 commit comments

Comments
 (0)