Search in sources :

Example 1 with MapProperty

use of io.swagger.models.properties.MapProperty 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 MapProperty

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

the class MapPropertyConverter method doConvert.

@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object property) {
    MapProperty mapProperty = (MapProperty) property;
    Property valueProperty = mapProperty.getAdditionalProperties();
    JavaType valueJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, valueProperty);
    return TypeFactory.defaultInstance().constructMapType(Map.class, TypeFactory.defaultInstance().constructType(String.class), valueJavaType);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) MapProperty(io.swagger.models.properties.MapProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property)

Example 3 with MapProperty

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

the class MapPropertyTest method testEquals.

@Test
public void testEquals() {
    final MapProperty prop1 = new MapProperty();
    prop1.setName(PROP_1);
    prop1.setRequired(true);
    final MapProperty prop2 = new MapProperty();
    prop2.setName(PROP_2);
    assertNotEquals(prop1, prop2);
    prop2.setName(PROP_1);
    prop2.setRequired(true);
    assertEquals(prop1, prop2);
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) Test(org.testng.annotations.Test)

Example 4 with MapProperty

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

the class MapPropertyDeserializerTest method testMapDeserialization.

@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property responseSchema = response.getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof MapProperty);
    MapProperty mp = (MapProperty) responseSchema;
    assertTrue(mp.getAdditionalProperties() instanceof IntegerProperty);
}
Also used : Response(io.swagger.models.Response) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 5 with MapProperty

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

the class PropertySerializationTest method deserializeStringMapProperty.

@Test(description = "it should deserialize a string MapProperty")
public void deserializeStringMapProperty() throws IOException {
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "object");
    assertEquals(p.getClass(), MapProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

MapProperty (io.swagger.models.properties.MapProperty)32 Property (io.swagger.models.properties.Property)26 ArrayProperty (io.swagger.models.properties.ArrayProperty)22 RefProperty (io.swagger.models.properties.RefProperty)16 Test (org.testng.annotations.Test)15 StringProperty (io.swagger.models.properties.StringProperty)13 Model (io.swagger.models.Model)12 IntegerProperty (io.swagger.models.properties.IntegerProperty)12 ObjectProperty (io.swagger.models.properties.ObjectProperty)8 RefModel (io.swagger.models.RefModel)7 ModelImpl (io.swagger.models.ModelImpl)6 JavaType (com.fasterxml.jackson.databind.JavaType)5 ApiModelProperty (io.swagger.annotations.ApiModelProperty)5 FileProperty (io.swagger.models.properties.FileProperty)5 LongProperty (io.swagger.models.properties.LongProperty)5 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)4 ComposedModel (io.swagger.models.ComposedModel)4 Operation (io.swagger.models.Operation)4 Response (io.swagger.models.Response)4 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)4