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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations