Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -21,6 +21,8 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

public class PropertyDeserializer extends JsonDeserializer<Property> {
Logger LOGGER = LoggerFactory.getLogger(PropertyDeserializer.class);
Expand Down Expand Up @@ -71,6 +73,17 @@ public Property deserialize(JsonParser jp, DeserializationContext ctxt)
return propertyFromNode(node);
}

private boolean isReserved(String propertyName){
PropertyBuilder.PropertyId[] reserved = PropertyBuilder.PropertyId.values();
boolean isReserved = false;
for(int i = 0; i < reserved.length; i++){
if(reserved[i].getPropertyName().equals(propertyName)){
isReserved = true;
}
}
return isReserved;
}

Property propertyFromNode(JsonNode node) {
final String type = getString(node, PropertyBuilder.PropertyId.TYPE);
final String format = getString(node, PropertyBuilder.PropertyId.FORMAT);
Expand All @@ -88,6 +101,19 @@ Property propertyFromNode(JsonNode node) {
if (items != null) {
return new MapProperty(items).description(description);
}
} else {
detailNode = node.get("properties");
Map<String, Property> properties = new HashMap<String, Property>();
if(detailNode != null){
for(Iterator<Map.Entry<String,JsonNode>> iter = detailNode.fields(); iter.hasNext();){
Map.Entry<String,JsonNode> field = iter.next();
if(!isReserved(field.getKey())){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it is necessary to check for the reserved property names here, some input would be welcome

Property property = propertyFromNode(field.getValue());
properties.put(field.getKey(), property);
}
}
}
return new ObjectProperty(properties);
}
}
if (ArrayProperty.isType(type)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package io.swagger.models.properties;

import io.swagger.models.Xml;
import java.util.Map;

public class ObjectProperty extends AbstractProperty implements Property {
public static final String TYPE = "object";

Map<String, Property> properties;

public ObjectProperty() {
super.type = TYPE;
}

public ObjectProperty(Map<String, Property> properties) {
super.type = TYPE;
this.properties = properties;
}

public static boolean isType(String type) {
return TYPE.equals(type);
}
Expand All @@ -18,6 +26,14 @@ public static boolean isType(String type, String format) {
return isType(type);
}

public Map<String, Property> getProperties(){
return this.properties;
}

public void setProperties(Map<String, Property> properties){
this.properties = properties;
}

public ObjectProperty xml(Xml xml) {
this.setXml(xml);
return this;
Expand Down