Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.PropertyBuilder;
import io.swagger.models.properties.RefProperty;
import io.swagger.util.Json;

import java.math.BigDecimal;
Expand Down Expand Up @@ -904,26 +903,7 @@ public Model definition(ObjectNode node, String location, ParseResult result) {
ExternalDocs docs = externalDocs(externalDocs, location, result);
impl.setExternalDocs(docs);

ObjectNode properties = getObject("properties", node, false, location, result);
if(properties != null) {
Set<String> propertyNames = getKeys(properties);
for(String propertyName : propertyNames) {
JsonNode propertyNode = properties.get(propertyName);
if(propertyNode.getNodeType().equals(JsonNodeType.OBJECT)) {
ObjectNode on = (ObjectNode) propertyNode;
Property property = property(on, location, result);
if(property != null) {
if ("array".equals(property.getType()) && !(property instanceof ArrayProperty && ((ArrayProperty) property).getItems() != null)) {
result.missing(location, "items");
}
}
impl.property(propertyName, property);
}
else {
result.invalidType(location, "properties", "object", propertyNode);
}
}
}
addProperties(location,node,result,impl);

// need to set properties first
ArrayNode required = getArray("required", node, false, location, result);
Expand Down Expand Up @@ -1045,11 +1025,36 @@ else if(!SCHEMA_KEYS.contains(key)) {
}
}

addProperties(location,node,result,model);

return model;
}
return null;
}

private void addProperties(String location, ObjectNode node, ParseResult result, AbstractModel model) {
ObjectNode properties = getObject("properties", node, false, location, result);
if(properties != null) {
Set<String> propertyNames = getKeys(properties);
for(String propertyName : propertyNames) {
JsonNode propertyNode = properties.get(propertyName);
if(propertyNode.getNodeType().equals(JsonNodeType.OBJECT)) {
ObjectNode on = (ObjectNode) propertyNode;
Property property = property(on, location, result);
if(property != null) {
if ("array".equals(property.getType()) && !(property instanceof ArrayProperty && ((ArrayProperty) property).getItems() != null)) {
result.missing(location, "items");
}
}
model.addProperty(propertyName, property);
}
else {
result.invalidType(location, "properties", "object", propertyNode);
}
}
}
}

public Map<String, Property> properties(ObjectNode node, String location, ParseResult result) {
if(node == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.util.TestUtils;
import io.swagger.parser.util.SwaggerDeserializationResult;
import io.swagger.parser.util.TestUtils;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import org.testng.Assert;
Expand All @@ -57,6 +56,13 @@

public class SwaggerParserTest {

@Test
public void testIssue1143(){
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("issue1143.json", null, true);
assertNotNull(result.getSwagger().getDefinitions().get("RedisResource"));
assertNotNull(result.getSwagger().getDefinitions().get("identificacion_usuario_aplicacion"));
}

@Test
public void testIssue1204() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("issue1204.yaml", null, true);
Expand Down
Loading