use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.
the class ModelPropertyTest method extractProperties.
@Test
public void extractProperties() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(Family.class);
assertEquals(models.size(), 3);
final Model person = models.get("Person");
final Property employer = person.getProperties().get("employer");
assertTrue(employer instanceof ArrayProperty);
final ArrayProperty employerProperty = (ArrayProperty) employer;
final Property items = employerProperty.getItems();
assertTrue(items instanceof RefProperty);
assertEquals(((RefProperty) items).getSimpleRef(), "Employer");
final Property awards = person.getProperties().get("awards");
assertTrue(awards instanceof ArrayProperty);
assertTrue(((ArrayProperty) awards).getItems() instanceof StringProperty);
}
use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.
the class ModelPropertyTest method extractPrimitiveArray.
@Test
public void extractPrimitiveArray() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithPrimitiveArray.class);
assertEquals(models.size(), 1);
final Model model = models.get("ModelWithPrimitiveArray");
final ArrayProperty longArray = (ArrayProperty) model.getProperties().get("longArray");
final Property longArrayItems = longArray.getItems();
assertTrue(longArrayItems instanceof LongProperty);
final ArrayProperty intArray = (ArrayProperty) model.getProperties().get("intArray");
assertTrue(intArray.getItems() instanceof IntegerProperty);
}
use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.
the class ContainerTest method testArray.
@Test
public void testArray() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
final Model model = context.resolve(ArrayBean.class);
final Map<String, Property> props = model.getProperties();
assertEquals(1, props.size());
final Property prop = props.get("a");
assertNotNull(prop);
assertEquals(prop.getType(), "array");
final Property items = ((ArrayProperty) prop).getItems();
assertNotNull(items);
assertEquals(items.getType(), "integer");
}
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 camel by apache.
the class RestSwaggerReader method modelTypeAsProperty.
private Property modelTypeAsProperty(String typeName, Swagger swagger) {
boolean array = typeName.endsWith("[]");
if (array) {
typeName = typeName.substring(0, typeName.length() - 2);
}
String ref = modelTypeAsRef(typeName, swagger);
Property prop = ref != null ? new RefProperty(ref) : new StringProperty(typeName);
if (array) {
return new ArrayProperty(prop);
} else {
return prop;
}
}
Aggregations