Skip to content

Commit e3f69c0

Browse files
authored
Merge pull request #8220 from swagger-api/issue-8214
fixed index out of bound exception for inline empty example field.
2 parents 4788eec + 5c5d979 commit e3f69c0

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void flatten(Swagger swagger) {
219219
private void fixStringModel(ModelImpl m) {
220220
if (m.getType() != null && m.getType().equals("string") && m.getExample() != null) {
221221
String example = m.getExample().toString();
222-
if (example.substring(0, 1).equals("\"") &&
222+
if (!example.isEmpty() && example.substring(0, 1).equals("\"") &&
223223
example.substring(example.length() - 1).equals("\"")) {
224224
m.setExample(example.substring(1, example.length() - 1));
225225
}

modules/swagger-codegen/src/test/java/io/swagger/codegen/InlineModelResolverTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import io.swagger.models.parameters.Parameter;
66
import io.swagger.models.properties.*;
77
import io.swagger.util.Json;
8+
import org.apache.commons.lang3.StringUtils;
89
import org.testng.annotations.Test;
910

11+
import java.util.HashMap;
1012
import java.util.Map;
1113

1214
import static org.testng.AssertJUnit.*;
@@ -988,5 +990,24 @@ public void testArbitraryObjectModelWithArrayInlineWithTitle() {
988990
assertTrue(inlineProp instanceof ObjectProperty);
989991
ObjectProperty op = (ObjectProperty) inlineProp;
990992
assertNull(op.getProperties());
991-
}
993+
}
994+
995+
@Test
996+
public void testEmptyExampleOnStrinngTypeModels() {
997+
Swagger swagger = new Swagger();
998+
999+
RefProperty refProperty = new RefProperty();
1000+
refProperty.set$ref("#/definitions/Test");
1001+
1002+
swagger.path("/hello", new Path()
1003+
.get(new Operation()
1004+
.response(200, new Response()
1005+
.schema(new ArrayProperty()
1006+
.items(refProperty)))));
1007+
1008+
swagger.addDefinition("Test", new ModelImpl()
1009+
.example(StringUtils.EMPTY)
1010+
.type("string"));
1011+
new InlineModelResolver().flatten(swagger);
1012+
}
9921013
}

0 commit comments

Comments
 (0)