Skip to content

Commit

Permalink
Merge pull request swagger-api#8220 from swagger-api/issue-8214
Browse files Browse the repository at this point in the history
fixed index out of bound exception for inline empty example field.
  • Loading branch information
HugoMario authored May 22, 2018
2 parents 4788eec + 5c5d979 commit e3f69c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void flatten(Swagger swagger) {
private void fixStringModel(ModelImpl m) {
if (m.getType() != null && m.getType().equals("string") && m.getExample() != null) {
String example = m.getExample().toString();
if (example.substring(0, 1).equals("\"") &&
if (!example.isEmpty() && example.substring(0, 1).equals("\"") &&
example.substring(example.length() - 1).equals("\"")) {
m.setExample(example.substring(1, example.length() - 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.*;
import io.swagger.util.Json;
import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

import static org.testng.AssertJUnit.*;
Expand Down Expand Up @@ -988,5 +990,24 @@ public void testArbitraryObjectModelWithArrayInlineWithTitle() {
assertTrue(inlineProp instanceof ObjectProperty);
ObjectProperty op = (ObjectProperty) inlineProp;
assertNull(op.getProperties());
}
}

@Test
public void testEmptyExampleOnStrinngTypeModels() {
Swagger swagger = new Swagger();

RefProperty refProperty = new RefProperty();
refProperty.set$ref("#/definitions/Test");

swagger.path("/hello", new Path()
.get(new Operation()
.response(200, new Response()
.schema(new ArrayProperty()
.items(refProperty)))));

swagger.addDefinition("Test", new ModelImpl()
.example(StringUtils.EMPTY)
.type("string"));
new InlineModelResolver().flatten(swagger);
}
}

0 comments on commit e3f69c0

Please sign in to comment.