Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,16 @@ protected String _subTypeName(NamedType type) {
}

protected boolean _isSetType(Class<?> cls) {
if (cls != null) {

if (java.util.Set.class.equals(cls)) {
if (cls == null) {
return false;
}
if (java.util.Set.class.isAssignableFrom(cls)) {
return true;
}
// check for scala Set as well - to avoid bringing in scala runtime
for (Class<?> a : cls.getInterfaces()) {
if ("interface scala.collection.Set".equals(a.toString())) {
return true;
} else {
for (Class<?> a : cls.getInterfaces()) {
// this is dirty and ugly and needs to be extended into a scala model converter. But to avoid bringing in scala runtime...
if (java.util.Set.class.equals(a) || "interface scala.collection.Set".equals(a.toString())) {
return true;
}
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.swagger.v3.core.converting;

import io.swagger.v3.core.jackson.AbstractModelConverter;
import io.swagger.v3.core.util.Json;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class IsSetTypeTest {

private static class TestModelConverter extends AbstractModelConverter {
protected TestModelConverter() {
super(Json.mapper());
}

public boolean isSetType(Class<?> cls) {
return _isSetType(cls);
}
}

private final TestModelConverter converter = new TestModelConverter();

@Test
public void testIsSetTypeWithNull() {
assertFalse(converter.isSetType(null));
}

@Test
public void testIsSetTypeWithSetInterface() {
assertTrue(converter.isSetType(Set.class));
}

@Test
public void testIsSetTypeWithHashSet() {
assertTrue(converter.isSetType(HashSet.class));
}

@Test
public void testIsSetTypeWithLinkedHashSet() {
assertTrue(converter.isSetType(LinkedHashSet.class));
}

@Test
public void testIsSetTypeWithTreeSet() {
assertTrue(converter.isSetType(TreeSet.class));
}

@Test
public void testIsSetTypeWithNonSetCollection() {
assertFalse(converter.isSetType(List.class));
assertFalse(converter.isSetType(ArrayList.class));
}

@Test
public void testIsSetTypeWithNonCollection() {
assertFalse(converter.isSetType(String.class));
assertFalse(converter.isSetType(Integer.class));
assertFalse(converter.isSetType(Map.class));
}
}
Loading