Skip to content

Commit 156c31c

Browse files
authored
Merge pull request #4109 from swagger-api/items1636Support
add item support in ModelImpl
2 parents 8144616 + 13ffcc9 commit 156c31c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

modules/swagger-core/src/main/java/io/swagger/util/ModelDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public Model deserialize(JsonParser jp, DeserializationContext ctxt)
5151
return model;
5252
} else {
5353
sub = node.get("type");
54+
JsonNode items = node.get("items");
5455
Model model = null;
55-
if (sub != null && "array".equals(((TextNode) sub).textValue())) {
56+
if ((sub != null && "array".equals(((TextNode) sub).textValue())) || (items != null)){
5657
model = Json.mapper().convertValue(node, ArrayModel.class);
5758
} else {
5859
model = Json.mapper().convertValue(node, ModelImpl.class);

modules/swagger-core/src/test/java/io/swagger/deserialization/JsonDeserializationTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import static org.testng.Assert.assertEquals;
44
import static org.testng.Assert.assertTrue;
5+
import static org.testng.AssertJUnit.assertNotNull;
56

7+
import io.swagger.models.ArrayModel;
8+
import io.swagger.models.Model;
69
import io.swagger.models.Swagger;
710
import io.swagger.models.properties.ObjectProperty;
811
import io.swagger.models.properties.MapProperty;
@@ -12,6 +15,7 @@
1215
import io.swagger.util.ResourceUtils;
1316

1417
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import io.swagger.util.Yaml;
1519
import org.testng.annotations.Test;
1620

1721
import java.io.IOException;
@@ -117,4 +121,19 @@ public void testNestedUntypedProperty() throws IOException {
117121
assertTrue(additionalProperties instanceof UntypedProperty);
118122
assertEquals(additionalProperties.getDescription(), "map value");
119123
}
124+
125+
@Test(description = "it should deserialize an array untyped")
126+
public void testArrayUntypedModel() throws IOException {
127+
final String json = "{\n" +
128+
" \"description\":\"top level object\",\n" +
129+
" \"items\":{}" +
130+
"}";
131+
final Model result = m.readValue(json, Model.class);
132+
assertTrue(result instanceof ArrayModel);
133+
134+
final ArrayModel array = (ArrayModel) result;
135+
assertEquals(array.getType(),"array");
136+
assertEquals(array.getDescription(), "top level object");
137+
assertNotNull(array.getItems());
138+
}
120139
}

0 commit comments

Comments
 (0)