Search in sources :

Example 16 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.

the class ModelPropertyTest method extractProperties.

@Test
public void extractProperties() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(Family.class);
    assertEquals(models.size(), 3);
    final Model person = models.get("Person");
    final Property employer = person.getProperties().get("employer");
    assertTrue(employer instanceof ArrayProperty);
    final ArrayProperty employerProperty = (ArrayProperty) employer;
    final Property items = employerProperty.getItems();
    assertTrue(items instanceof RefProperty);
    assertEquals(((RefProperty) items).getSimpleRef(), "Employer");
    final Property awards = person.getProperties().get("awards");
    assertTrue(awards instanceof ArrayProperty);
    assertTrue(((ArrayProperty) awards).getItems() instanceof StringProperty);
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) ModelWithBooleanProperty(io.swagger.models.ModelWithBooleanProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) 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)

Example 17 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.

the class ModelPropertyTest method extractPrimitiveArray.

@Test
public void extractPrimitiveArray() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithPrimitiveArray.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithPrimitiveArray");
    final ArrayProperty longArray = (ArrayProperty) model.getProperties().get("longArray");
    final Property longArrayItems = longArray.getItems();
    assertTrue(longArrayItems instanceof LongProperty);
    final ArrayProperty intArray = (ArrayProperty) model.getProperties().get("intArray");
    assertTrue(intArray.getItems() instanceof IntegerProperty);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) ModelWithBooleanProperty(io.swagger.models.ModelWithBooleanProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 18 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.

the class ContainerTest method testArray.

@Test
public void testArray() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Model model = context.resolve(ArrayBean.class);
    final Map<String, Property> props = model.getProperties();
    assertEquals(1, props.size());
    final Property prop = props.get("a");
    assertNotNull(prop);
    assertEquals(prop.getType(), "array");
    final Property items = ((ArrayProperty) prop).getItems();
    assertNotNull(items);
    assertEquals(items.getType(), "integer");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 19 with ArrayProperty

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

the class AnnotationUtils method generateResponseProperty.

public static Property generateResponseProperty(Swagger swagger, ResponseConfigBase config) throws Error {
    Class<?> responseClass = config.getResponseClass();
    if (responseClass == null || ReflectionUtils.isVoid(responseClass)) {
        return null;
    }
    if (!ClassUtils.isPrimitiveOrWrapper(responseClass)) {
        Map<String, Model> newDefinitions = ModelConverters.getInstance().readAll(responseClass);
        appendDefinition(swagger, newDefinitions);
    }
    Property property = ModelConverters.getInstance().readAsProperty(responseClass);
    // 根据swagger定义这里是区分大小写的, 虽然不明白为何这样做,不过还是不要改标准了
    switch(config.getResponseContainer()) {
        case "List":
            property = new ArrayProperty(property);
            break;
        case "Set":
            property = new ArrayProperty(property);
            ((ArrayProperty) property).setUniqueItems(true);
            break;
        case "Map":
            property = new MapProperty(property);
            break;
        case "":
            // 不必处理
            break;
        default:
            throw new Error("not support responseContainer " + config.getResponseContainer());
    }
    return property;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) Model(io.swagger.models.Model) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty)

Example 20 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project camel by apache.

the class RestSwaggerReader method modelTypeAsProperty.

private Property modelTypeAsProperty(String typeName, Swagger swagger) {
    boolean array = typeName.endsWith("[]");
    if (array) {
        typeName = typeName.substring(0, typeName.length() - 2);
    }
    String ref = modelTypeAsRef(typeName, swagger);
    Property prop = ref != null ? new RefProperty(ref) : new StringProperty(typeName);
    if (array) {
        return new ArrayProperty(prop);
    } else {
        return prop;
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) RefProperty(io.swagger.models.properties.RefProperty)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)43 Property (io.swagger.models.properties.Property)30 Test (org.testng.annotations.Test)30 StringProperty (io.swagger.models.properties.StringProperty)23 Model (io.swagger.models.Model)14 MapProperty (io.swagger.models.properties.MapProperty)14 IntegerProperty (io.swagger.models.properties.IntegerProperty)12 RefProperty (io.swagger.models.properties.RefProperty)12 ModelImpl (io.swagger.models.ModelImpl)8 DoubleProperty (io.swagger.models.properties.DoubleProperty)7 LongProperty (io.swagger.models.properties.LongProperty)7 Operation (io.swagger.models.Operation)6 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)6 FloatProperty (io.swagger.models.properties.FloatProperty)5 ApiModelProperty (io.swagger.annotations.ApiModelProperty)4 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)4 BaseIntegerProperty (io.swagger.models.properties.BaseIntegerProperty)4 BooleanProperty (io.swagger.models.properties.BooleanProperty)4 DecimalProperty (io.swagger.models.properties.DecimalProperty)4 Annotation (java.lang.annotation.Annotation)4