Skip to content

Commit 13ffcc9

Browse files
committed
addressed comments in PR
1 parent 8a460ba commit 13ffcc9

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
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
}

modules/swagger-models/src/main/java/io/swagger/models/ModelImpl.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,13 @@ public class ModelImpl extends AbstractModel {
2323
private String description;
2424
private Object example;
2525
private Property additionalProperties;
26-
private Property items;
2726
private String discriminator;
2827
@JsonProperty("default")
2928
private String defaultValue;
3029
private List<String> _enum;
3130
private BigDecimal minimum;
3231
private BigDecimal maximum;
3332

34-
public ModelImpl items(Property items) {
35-
this.setItems(items);
36-
return this;
37-
}
38-
39-
public Property getItems() {
40-
return items;
41-
}
42-
43-
public void setItems(Property items) {
44-
this.items = items;
45-
}
46-
4733
public ModelImpl _enum(List<String> value) {
4834
this._enum = value;
4935
return this;
@@ -311,9 +297,6 @@ public boolean equals(Object o) {
311297
if (additionalProperties != null ? !additionalProperties.equals(model.additionalProperties) : model.additionalProperties != null) {
312298
return false;
313299
}
314-
if (items != null ? !items.equals(model.items) : model.items != null) {
315-
return false;
316-
}
317300
if (discriminator != null ? !discriminator.equals(model.discriminator) : model.discriminator != null) {
318301
return false;
319302
}
@@ -347,7 +330,6 @@ public int hashCode() {
347330
result = 31 * result + (_enum != null ? _enum.hashCode() : 0);
348331
result = 31 * result + (minimum != null ? minimum.hashCode() : 0);
349332
result = 31 * result + (maximum != null ? maximum.hashCode() : 0);
350-
result = 31 * result + (items != null ? items.hashCode() : 0);
351333
return result;
352334
}
353335

@@ -369,7 +351,6 @@ public Object clone() {
369351
cloned.defaultValue = this.defaultValue;
370352
cloned.minimum = this.minimum;
371353
cloned.maximum = this.maximum;
372-
cloned.items = this.items;
373354

374355
return cloned;
375356
}

0 commit comments

Comments
 (0)