Skip to content

Commit

Permalink
Merge pull request #4109 from swagger-api/items1636Support
Browse files Browse the repository at this point in the history
add item support in ModelImpl
  • Loading branch information
gracekarina authored Feb 2, 2022
2 parents 8144616 + 13ffcc9 commit 156c31c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public Model deserialize(JsonParser jp, DeserializationContext ctxt)
return model;
} else {
sub = node.get("type");
JsonNode items = node.get("items");
Model model = null;
if (sub != null && "array".equals(((TextNode) sub).textValue())) {
if ((sub != null && "array".equals(((TextNode) sub).textValue())) || (items != null)){
model = Json.mapper().convertValue(node, ArrayModel.class);
} else {
model = Json.mapper().convertValue(node, ModelImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNotNull;

import io.swagger.models.ArrayModel;
import io.swagger.models.Model;
import io.swagger.models.Swagger;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.MapProperty;
Expand All @@ -12,6 +15,7 @@
import io.swagger.util.ResourceUtils;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.util.Yaml;
import org.testng.annotations.Test;

import java.io.IOException;
Expand Down Expand Up @@ -117,4 +121,19 @@ public void testNestedUntypedProperty() throws IOException {
assertTrue(additionalProperties instanceof UntypedProperty);
assertEquals(additionalProperties.getDescription(), "map value");
}

@Test(description = "it should deserialize an array untyped")
public void testArrayUntypedModel() throws IOException {
final String json = "{\n" +
" \"description\":\"top level object\",\n" +
" \"items\":{}" +
"}";
final Model result = m.readValue(json, Model.class);
assertTrue(result instanceof ArrayModel);

final ArrayModel array = (ArrayModel) result;
assertEquals(array.getType(),"array");
assertEquals(array.getDescription(), "top level object");
assertNotNull(array.getItems());
}
}

0 comments on commit 156c31c

Please sign in to comment.