Class<?> toJavaType(MType type) { if(type.isSimpleType()) { return type.asSimpleType().getJavaType(); } if(type.isCollectionType()) { return Array.newInstance(toJavaType(type.asCollectionType().getElementType()), 0).getClass(); } if(type.isComplexType() || type.isDictionaryType() || type.isTypeRef()) { return Map.class; } if(type.isObjectType()) { return Object.class; } throw new IllegalStateException("Unsupported data type '" + type + "'"); }
/** * Returns the referenced type name. */ public String getRefTypeName() { return type.isCollectionType() ? type.asCollectionType().getElementType().asTypeRef().getRefTypeName() : type.asTypeRef().getRefTypeName(); }
if(null == from || from == Location.UNDEFINED) { if(p.getType().isTypeRef() || p.getType().isCollectionType()) { return MApiParameter.Location.BODY; }else{
protected boolean isBodyType(MType type) { if(type.isComplexType()) { return true; } if(type.isTypeRef()) { return true; } if(type.isDictionaryType()) { return true; } if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); return isBodyType(elementType); } return false; }
private static boolean hasUnresolvedType(MType type) { if(type instanceof MUnresolvedTypeRef) { return true; } if(type.isCollectionType()) { return hasUnresolvedType(type.asCollectionType().getElementType()); } if(type.isDictionaryType()) { return hasUnresolvedType(type.asDictionaryType().getValueType()); } return false; }
private void checkType(MetaApi api, MetaModel model, MetaProperty p, MType type) { if (type.isTypeRef()) { String name = type.asTypeRef().getRefTypeName(); if (null == api.getEntity(name) && null == api.getModel(name)) { if (Strings.containsIgnoreCase(name, "definitions/")) { throw new IllegalStateException("The ref type + '" + name + "' at '" + model.getName() + "#" + p.getName() + "' not exists, should use '#/definitions/' prefix!"); } else { throw new IllegalStateException("The ref type + '" + name + "' at '" + model.getName() + "#" + p.getName() + "' not exists!"); } } } else if (type.isCollectionType()) { checkType(api, model, p, type.asCollectionType().getElementType()); } }
private void onTypeResolved(MType mtype) { if (mtype.isComplexType()) { MComplexType ct = mtype.asComplexType(); if (!complexTypes.containsKey(ct.getJavaType())) { listener.onComplexTypeResolved(ct.getJavaType(), mtype.asComplexType()); complexTypes.put(ct.getJavaType(), ct); } for (MProperty p : ct.getProperties()) { onTypeResolved(p.getType()); } } else if (mtype.isCollectionType()) { MType elementType = mtype.asCollectionType().getElementType(); onTypeResolved(elementType); } } }
public static String toTypeName(MType type) { if(type.isSimpleType()) { SwaggerType st = swaggerWriter.convertSimpleType(type.asSimpleType()); if(null == st) { throw new IllegalStateException("Unsupported type '" + type + "'"); } return st.name().toLowerCase(); } if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); return "array<" + toTypeName(elementType) + ">"; } if(type.isComplexType()) { return type.asComplexType().getName(); } if(type.isTypeRef()) { return type.asTypeRef().getRefTypeName(); } if(type.isDictionaryType()) { return "map<string," + toTypeName(type.asDictionaryType().getValueType()) + ">"; } if(type.isObjectType()) { return "object"; } if(type.isVoidType()) { return ""; } throw new IllegalStateException("Unsupported type '" + type + "'"); }
if(type.isCollectionType()) { MType elementType = type.asCollectionType().getElementType(); if(elementType.isSimpleType()) {
if(type.isCollectionType()) { writeArrayType(context, m, w, type.asCollectionType()); return;
if(type.isCollectionType()) { writeArrayParameterType(context, m, w, p, type.asCollectionType()); return;
if(type.isCollectionType()) { return ofArray(api, name, required, type.asCollectionType(), p);
@Override public Object apply(ActionParams params) { Map<String,Object> map = params.toMap(); Object result; if(command.getMetadata().isSelect()) { //todo: page query, total count Query query = dao.createQuery(command).params(map); if(null != returnType) { if(returnType.isSimpleType()) { result = Converts.convert(query.scalarValueOrNull(), returnType.asSimpleType().getJavaType()); }else if(returnType.isCollectionType() && returnType.asCollectionType().getElementType().isSimpleType()) { result = query.scalars().list(returnType.asCollectionType().getElementType().asSimpleType().getJavaType()); }else { result = query.list(); } }else { result = query.list(); } }else{ //todo: the return type must be simple type result = dao.executeUpdate(command, map); if(null != returnType) { result = Converts.convert(result, returnType.asSimpleType().getJavaType()); } } return ApiResponse.of(result); }