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