Search in sources :

Example 1 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 2 with ArrayProperty

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

the class ModelImplTest method testAddProperty.

@Test
public void testAddProperty() {
    // given
    String badKey = "badKey";
    String key = "key";
    Property property = new ArrayProperty();
    instance.property(key, property);
    // when
    instance.addProperty(badKey, null);
    // then
    assertNull(instance.getProperties().get(badKey), "The bad key must not be added to the properties");
    // given
    instance.setRequired(Arrays.asList(key));
    // when
    instance.addProperty(key, property);
    assertEquals(instance.getProperties().get(key), property, "Must be able to retrieve the set value from the map");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ArrayProperty

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

the class ModelImplTest method testSetRequired.

@Test
public void testSetRequired() {
    // given
    String required = "required";
    Property property = new ArrayProperty();
    instance.property(required, property);
    // when
    instance.setRequired(Arrays.asList(required));
    // then
    assertTrue(instance.getRequired().contains(required), "The set key must be contained in the required list");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ArrayProperty

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

the class ModelImplTest method testProperty.

@Test
public void testProperty() {
    // given
    String key = "key";
    Property property = new ArrayProperty();
    // when
    instance.property(key, property);
    // then
    assertEquals(instance.getProperties().get(key), property, "Must be able to retrieve the set value from the map");
    assertTrue(instance.required(key).getRequired().contains(key), "The set key must be contained in the required list");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ArrayProperty

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

the class ArrayPropertyTest method testSetNullUniqueItems.

@Test
public void testSetNullUniqueItems() {
    final ArrayProperty prop = new ArrayProperty();
    prop.setUniqueItems(null);
    assertNull(prop.getUniqueItems());
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Test(org.testng.annotations.Test)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)81 Property (io.swagger.models.properties.Property)61 StringProperty (io.swagger.models.properties.StringProperty)41 RefProperty (io.swagger.models.properties.RefProperty)38 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 Operation (io.swagger.models.Operation)11 RefModel (io.swagger.models.RefModel)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 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