package com.mangofactory.swagger.models;

import com.fasterxml.classmate.ResolvedType;

import java.util.Collection;
import java.util.List;
import java.util.Set;

public class Collections {
    public static <T extends Collection> ResolvedType elementType(ResolvedType container, Class<T> collectionType) {
        return container.typeParametersFor(collectionType).get(0);
    }

    public static ResolvedType collectionElementType(ResolvedType type) {
        if (List.class.isAssignableFrom(type.getErasedType())) {
            return Collections.elementType(type, List.class);
        } else if (Set.class.isAssignableFrom(type.getErasedType())) {
            return Collections.elementType(type, Set.class);
        } else if (type.isArray()) {
            return type.getArrayElementType();
        } else {
            return null;
        }
    }

    public static boolean isContainerType(ResolvedType type) {
        if (List.class.isAssignableFrom(type.getErasedType()) ||
                Set.class.isAssignableFrom(type.getErasedType()) ||
                type.isArray()) {
            return true;
        }
        return false;
    }

    public static String containerType(ResolvedType type) {
        if (List.class.isAssignableFrom(type.getErasedType())) {
            return "List";
        } else if (Set.class.isAssignableFrom(type.getErasedType())) {
            return "Set";
        } else if (type.isArray()) {
            return "Array";
        } else {
            throw new UnsupportedOperationException(String.format("Type is not collection type %s", type));
        }
    }
}

@@ -79,16 +79,61 @@
 vedType;
+%0Aimport com.fasterxml.classmate.TypeResolver;
 %0A%0Aimport
@@ -351,24 +351,50 @@
 %7B%0A      
-  return
+List%3CResolvedType%3E resolvedTypes =
  contain
@@ -433,14 +433,146 @@
 ype)
-.get(0
+;%0A      if (resolvedTypes.size() == 1) %7B%0A        return resolvedTypes.get(0);%0A      %7D%0A      return new TypeResolver().resolve(Object.class
 );%0A 

Fix for controller methods returning non-generic List type causes initialization error