All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.models.properties.ObjectProperty Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc2
Show newest version
package io.swagger.models.properties;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
import io.swagger.models.Xml;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

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

    Map properties;

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

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

    public ObjectProperty vendorExtension(String key, Object obj) {
        this.setVendorExtension(key, obj);
        return this;
    }

    public static boolean isType(String type) {
        return TYPE.equals(type);
    }

    //TODO: implement additional formats
    public static boolean isType(String type, String format) {
        return isType(type);
    }

    public ObjectProperty properties(Map properties) {
        this.setProperties(properties);
        return this;
    }

    public ObjectProperty property(String name, Property property) {
        if(this.properties == null) {
            this.properties = new TreeMap();
        }
        this.properties.put(name, property);
        return this;
    }

    public ObjectProperty access(String access) {
        this.setAccess(access);
        return this;
    }

    public ObjectProperty description(String description) {
        this.setDescription(description);
        return this;
    }

    public ObjectProperty name(String name) {
        this.setName(name);
        return this;
    }

    public ObjectProperty title(String title) {
        this.setTitle(title);
        return this;
    }

    public ObjectProperty _default(String _default) {
        this.setDefault(_default);
        return this;
    }

    public ObjectProperty readOnly(boolean readOnly) {
        this.setReadOnly(readOnly);
        return this;
    }

    public ObjectProperty required(boolean required) {
        this.setRequired(required);
        return this;
    }

    public ObjectProperty readOnly() {
        this.setReadOnly(Boolean.TRUE);
        return this;
    }

    public Map getProperties(){
      return this.properties;
    }

    @JsonGetter("required")
    public List getRequiredProperties() {
        List output = new ArrayList();
        if (properties != null) {
            for (String key : properties.keySet()) {
                Property prop = properties.get(key);
                if (prop != null && prop.getRequired()) {
                    output.add(key);
                }
            }
        }
        Collections.sort(output);
        if (output.size() > 0) {
            return output;
        } else {
            return null;
        }
    }

    @JsonSetter("required")
    public void setRequiredProperties(List required) {
        if (properties != null) {
            for (String s : required) {
                Property p = properties.get(s);
                if (p != null) {
                    p.setRequired(true);
                }
            }
        }
    }

    public void setProperties(Map properties){
      this.properties = properties;
    }

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

    public ObjectProperty example(Object example) {
        this.setExample(example);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof ObjectProperty)) {
            return false;
        }

        ObjectProperty that = (ObjectProperty) o;

        if (properties != null ? !properties.equals(that.properties) : that.properties != null) {
            return false;
        }
        return super.equals(o);
    }

    @Override
    public int hashCode() {
        int result =  super.hashCode();
        result = 31 * result + (properties != null ? properties.hashCode() : 0);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy