Search in sources :

Example 81 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project incubator-servicecomb-java-chassis by apache.

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) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ExampleProperty(io.swagger.annotations.ExampleProperty) Property(io.swagger.models.properties.Property)

Example 82 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project incubator-servicecomb-java-chassis by apache.

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)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)82 Property (io.swagger.models.properties.Property)62 StringProperty (io.swagger.models.properties.StringProperty)42 RefProperty (io.swagger.models.properties.RefProperty)39 Test (org.testng.annotations.Test)36 MapProperty (io.swagger.models.properties.MapProperty)25 Model (io.swagger.models.Model)23 IntegerProperty (io.swagger.models.properties.IntegerProperty)23 LongProperty (io.swagger.models.properties.LongProperty)14 ModelImpl (io.swagger.models.ModelImpl)13 BooleanProperty (io.swagger.models.properties.BooleanProperty)12 DoubleProperty (io.swagger.models.properties.DoubleProperty)12 RefModel (io.swagger.models.RefModel)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 Operation (io.swagger.models.Operation)9 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)9 DecimalProperty (io.swagger.models.properties.DecimalProperty)9 HashMap (java.util.HashMap)9 Response (io.swagger.models.Response)7 Swagger (io.swagger.models.Swagger)7