Search in sources :

Example 11 with ObjectProperty

use of io.swagger.models.properties.ObjectProperty in project teiid by teiid.

the class SwaggerMetadataProcessor method walkProperties.

private void walkProperties(final Swagger swagger, Set<Property> parents, final Map<String, Property> properties, final String namePrefix, final String nisPrefix, final PropertyAction pa) {
    if (properties == null) {
        return;
    }
    final PropertyVisitor visitor = new PropertyVisitor() {

        @Override
        public void visit(String name, Property property) {
            pa.execute(fqn(namePrefix, name), nis(nisPrefix, name, false), property, false);
        }

        @Override
        public void visit(String name, ArrayProperty property) {
            if (isSimple(property)) {
                // the array type defined in the type of the property
                pa.execute(fqn(namePrefix, name), nis(nisPrefix, name, false), property.getItems(), true);
            } else {
                // if Object or Ref, array does not matter as return is already a resultset.
                Property items = property.getItems();
                parents.add(property);
                if (items instanceof ObjectProperty) {
                    String modelName = ((ObjectProperty) items).getName();
                    walkProperties(swagger, parents, ((ObjectProperty) items).getProperties(), fqn(fqn(namePrefix, name), modelName), nis(nis(nisPrefix, name, true), modelName, false), pa);
                } else if (items instanceof RefProperty) {
                    String modelName = ((RefProperty) items).getSimpleRef();
                    Model model = swagger.getDefinitions().get(modelName);
                    walkProperties(swagger, parents, model.getProperties(), fqn(fqn(namePrefix, name), modelName), nis(nis(nisPrefix, name, true), modelName, false), pa);
                } else {
                    walkProperties(swagger, parents, properties, fqn(namePrefix, name), nis(nisPrefix, name, true), pa);
                }
                parents.remove(property);
            }
        }

        @Override
        public void visit(String name, FileProperty property) {
        // TODO:
        }

        @Override
        public void visit(String name, MapProperty property) {
        // TODO:
        }

        @Override
        public void visit(String name, ObjectProperty property) {
            parents.add(property);
            walkProperties(swagger, parents, property.getProperties(), fqn(namePrefix, name), nis(nisPrefix, name, false), pa);
            parents.remove(property);
        }

        @Override
        public void visit(String name, RefProperty property) {
            parents.add(property);
            Model model = swagger.getDefinitions().get(property.getSimpleRef());
            walkProperties(swagger, parents, model.getProperties(), fqn(namePrefix, name), nis(nisPrefix, name, false), pa);
            parents.remove(property);
        }
    };
    for (Entry<String, Property> p : properties.entrySet()) {
        if (parents.contains(p.getValue())) {
            // TODO: could be an error condition
            continue;
        }
        visitor.accept(p.getKey(), p.getValue());
    }
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) FileProperty(io.swagger.models.properties.FileProperty) MapProperty(io.swagger.models.properties.MapProperty) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) TranslatorProperty(org.teiid.translator.TranslatorProperty) ExtensionMetadataProperty(org.teiid.metadata.ExtensionMetadataProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) FileProperty(io.swagger.models.properties.FileProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 12 with ObjectProperty

use of io.swagger.models.properties.ObjectProperty in project java-chassis by ServiceComb.

the class TestSwaggerUtils method isComplexProperty.

@Test
public void isComplexProperty() {
    Property property = new RefProperty("ref");
    Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
    property = new ObjectProperty();
    Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
    property = new MapProperty();
    Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
    property = new ArrayProperty(new ObjectProperty());
    Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
    property = new ArrayProperty(new StringProperty());
    Assert.assertFalse(SwaggerUtils.isComplexProperty(property));
    property = new StringProperty();
    Assert.assertFalse(SwaggerUtils.isComplexProperty(property));
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.junit.Test)

Example 13 with ObjectProperty

use of io.swagger.models.properties.ObjectProperty in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method addAttributesToModel.

private void addAttributesToModel(ModelImpl model, NamedNodeMap namedNodeMap) {
    if (namedNodeMap == null || namedNodeMap.getNamedItem(NAME_ATTRIBUTE) == null) {
        return;
    }
    String name = namedNodeMap.getNamedItem(NAME_ATTRIBUTE).getNodeValue();
    Map<String, Property> properties = new HashMap<>();
    if (model.getProperties() == null || !model.getProperties().containsKey(ATTR_CONTENT_KEYWORD)) {
        ObjectProperty objectProperty = new ObjectProperty();
        objectProperty.setProperties(properties);
        model.addProperty(ATTR_CONTENT_KEYWORD, objectProperty);
    }
    ObjectProperty objectProperty = (ObjectProperty) model.getProperties().get(ATTR_CONTENT_KEYWORD);
    objectProperty.getProperties().put(name, new StringProperty());
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) HashMap(java.util.HashMap) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty)

Example 14 with ObjectProperty

use of io.swagger.models.properties.ObjectProperty in project swagger-parser by swagger-api.

the class SwaggerInventory method process.

public void process(Property property) {
    this.properties.add(property);
    if (property instanceof ArrayProperty) {
        ArrayProperty p = (ArrayProperty) property;
        Property ap = p.getItems();
        this.process(ap);
    } else if (property instanceof MapProperty) {
        MapProperty p1 = (MapProperty) property;
    } else if (property instanceof ObjectProperty) {
        ObjectProperty p2 = (ObjectProperty) property;
        if (p2.getProperties() != null) {
            Iterator ap1 = p2.getProperties().keySet().iterator();
            while (ap1.hasNext()) {
                String name = (String) ap1.next();
                Property ip = (Property) p2.getProperties().get(name);
                this.process(ip);
            }
        }
    }
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) Iterator(java.util.Iterator) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) Property(io.swagger.models.properties.Property)

Aggregations

ObjectProperty (io.swagger.models.properties.ObjectProperty)14 Property (io.swagger.models.properties.Property)12 ArrayProperty (io.swagger.models.properties.ArrayProperty)8 RefProperty (io.swagger.models.properties.RefProperty)7 StringProperty (io.swagger.models.properties.StringProperty)7 MapProperty (io.swagger.models.properties.MapProperty)5 Test (org.testng.annotations.Test)5 BooleanProperty (io.swagger.models.properties.BooleanProperty)3 DateProperty (io.swagger.models.properties.DateProperty)3 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)3 DecimalProperty (io.swagger.models.properties.DecimalProperty)3 DoubleProperty (io.swagger.models.properties.DoubleProperty)3 FloatProperty (io.swagger.models.properties.FloatProperty)3 IntegerProperty (io.swagger.models.properties.IntegerProperty)3 LongProperty (io.swagger.models.properties.LongProperty)3 HashMap (java.util.HashMap)3 Model (io.swagger.models.Model)2 RefModel (io.swagger.models.RefModel)2 FileProperty (io.swagger.models.properties.FileProperty)2 LinkedHashMap (java.util.LinkedHashMap)2