Search in sources :

Example 6 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ApiDeclarationParser method readProperties.

List<ModelProperty> readProperties(Map<String, Object> properties, MessageBuilder messages) {
    List<ModelProperty> output = new ArrayList<ModelProperty>();
    for (String key : properties.keySet()) {
        Map<String, Object> value = (Map<String, Object>) properties.get(key);
        ModelProperty prop = new ModelProperty();
        String type = readString(value.get("type"));
        prop.setType(type);
        String qualifiedType = readString(value.get("qualifiedType"));
        output.add(prop);
    }
    return output;
}
Also used : ModelProperty(io.swagger.models.apideclaration.ModelProperty) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class SwaggerCompatConverter method convertProperty.

public Property convertProperty(ModelProperty property) {
    Property output = null;
    output = propertyFromTypedObject(property);
    output.setDescription(property.getDescription());
    return output;
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelProperty(io.swagger.models.apideclaration.ModelProperty) RefProperty(io.swagger.models.properties.RefProperty) UntypedProperty(io.swagger.models.properties.UntypedProperty)

Example 8 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelConverterTest method convertModelWithPrimitives.

@Test
public void convertModelWithPrimitives() throws Exception {
    io.swagger.models.apideclaration.Model model = new io.swagger.models.apideclaration.Model();
    model.setDescription("the model");
    Map<String, ModelProperty> properties = new LinkedHashMap<String, ModelProperty>();
    ModelProperty id = new ModelProperty();
    id.setType("integer");
    id.setFormat(Format.INT64);
    id.setDescription("the id property");
    properties.put("id", id);
    ModelProperty name = new ModelProperty();
    name.setType("string");
    name.setDescription("the name property");
    properties.put("name", name);
    model.setProperties(properties);
    ModelProperty age = new ModelProperty();
    age.setType("integer");
    age.setFormat(Format.INT32);
    age.setDescription("the age property");
    properties.put("age", age);
    model.setProperties(properties);
    List<String> required = new ArrayList<String>();
    required.add("id");
    required.add("name");
    model.setRequired(required);
    Model converted = converter.convertModel(model);
    assertEquals(model.getDescription(), converted.getDescription());
    Map<String, Property> convertedProperties = converted.getProperties();
    assertTrue(convertedProperties.size() == 3);
    assertTrue(convertedProperties.keySet().iterator().next().equals("id"));
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Model(io.swagger.models.Model) ModelProperty(io.swagger.models.apideclaration.ModelProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 9 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelConverterTest method convertModelWithSubtypes.

@Test
public void convertModelWithSubtypes() throws Exception {
    io.swagger.models.apideclaration.Model model = new io.swagger.models.apideclaration.Model();
    model.setDescription("the model");
    model.setDiscriminator("type");
    List<String> subtypes = new ArrayList<String>();
    subtypes.add("Cat");
    subtypes.add("Dog");
    Map<String, ModelProperty> properties = new LinkedHashMap<String, ModelProperty>();
    ModelProperty id = new ModelProperty();
    id.setType("integer");
    id.setFormat(Format.INT64);
    id.setDescription("the id property");
    properties.put("id", id);
    ModelProperty type = new ModelProperty();
    type.setType("string");
    type.setDescription("the type property, which is the discriminator");
    properties.put("type", type);
    model.setProperties(properties);
    Model converted = converter.convertModel(model);
// TODO: subtypes are not translated 1:1
}
Also used : Model(io.swagger.models.Model) ArrayList(java.util.ArrayList) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 10 with ModelProperty

use of io.swagger.models.apideclaration.ModelProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertRefArrayModelProperty.

@Test
public void convertRefArrayModelProperty() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("array");
    Items items = new Items();
    items.setRef("Pet");
    property.setItems(items);
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), ArrayProperty.class);
    ArrayProperty prop = (ArrayProperty) converted;
    Property innerType = prop.getItems();
    RefProperty ref = (RefProperty) innerType;
    assertEquals(ref.getSimpleRef(), "Pet");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) Items(io.swagger.models.apideclaration.Items) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Aggregations

ModelProperty (io.swagger.models.apideclaration.ModelProperty)14 Property (io.swagger.models.properties.Property)12 Test (org.testng.annotations.Test)12 ArrayProperty (io.swagger.models.properties.ArrayProperty)11 RefProperty (io.swagger.models.properties.RefProperty)11 StringProperty (io.swagger.models.properties.StringProperty)11 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)10 DoubleProperty (io.swagger.models.properties.DoubleProperty)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 LongProperty (io.swagger.models.properties.LongProperty)10 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 Model (io.swagger.models.Model)2 Items (io.swagger.models.apideclaration.Items)2 LinkedHashMap (java.util.LinkedHashMap)2 UntypedProperty (io.swagger.models.properties.UntypedProperty)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1