Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ignore static methods while detecting the referenced classes in build…

…ing the models.
  • Loading branch information...
commit 14ec58b1075bef2b7788e37c223169ba626d7548 1 parent 1618323
@rpidikiti rpidikiti authored
View
4 modules/swagger-core/src/main/scala/com/wordnik/swagger/core/util/TypeUtil.scala
@@ -151,7 +151,7 @@ object TypeUtil {
}
if (clazz != null) {
for (field <- clazz.getFields) {
- if (Modifier.isPublic(field.getModifiers)) {
+ if (Modifier.isPublic(field.getModifiers) && !Modifier.isStatic(field.getModifiers)) {
var fieldClass: String = field.getType.getName
var fieldGenericType = field.getGenericType
field.getType.isArray match {
@@ -170,7 +170,7 @@ object TypeUtil {
}
}
for (method <- clazz.getMethods) {
- if (Modifier.isPublic(method.getModifiers)) {
+ if (Modifier.isPublic(method.getModifiers) && !Modifier.isStatic(method.getModifiers)) {
var methodReturnClass: String = method.getReturnType.getName
var methodGenericType = method.getGenericReturnType
View
26 modules/swagger-core/src/test/scala/com/wordnik/test/swagger/core/SpecReaderTest.scala
@@ -181,6 +181,20 @@ class SpecReaderTest extends FlatSpec with ShouldMatchers {
val types = TypeUtil.getReferencedClasses(classes)
assert(types.size() === 2)
}
+
+ it should "not read methods from companion object " in {
+ var docObj = ApiPropertiesReader.read(classOf[TestCompanionObject])
+ expect(3) {
+ docObj.getFields.size()
+ }
+ }
+
+ it should "not read reference objects form companion object methods" in {
+ var classes:java.util.List[String] = new java.util.ArrayList[String]()
+ classes.add(classOf[TestCompanionObject].getName);
+ val types = TypeUtil.getReferencedClasses(classes)
+ assert(types.size() === 1)
+ }
}
@RunWith(classOf[JUnitRunner])
@@ -464,3 +478,15 @@ case class ScalaCaseClassWithScalaSupportedType(
class ClassToTestModelClassesFromBaseClass extends ObjectWithChildObjectsInMap {
}
+
+case class TestCompanionObject(
+ @BeanProperty var label:String,
+ @BeanProperty var width:Int,
+ @BeanProperty var height:Int) {
+}
+
+object TestCompanionObject {
+ def getDescription():ObjectWithRootElementName = {
+ null
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.