diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java index 94bf08982d..b62bc0cacb 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java @@ -92,6 +92,8 @@ public class Reader { private final ReaderConfig config; private Swagger swagger; + private Set> scannedResources; + public Reader(Swagger swagger) { this(swagger, null); } @@ -99,6 +101,7 @@ public Reader(Swagger swagger) { public Reader(Swagger swagger, ReaderConfig config) { this.swagger = swagger == null ? new Swagger() : swagger; this.config = new DefaultReaderConfig(config); + this.scannedResources = new HashSet>(); } /** @@ -309,7 +312,8 @@ protected Swagger read(Class cls, String parentPath, String parentMethod, boo apiProduces = both.toArray(new String[both.size()]); } final Class subResource = getSubResource(method); - if (subResource != null) { + if (subResource != null && !scannedResources.contains(subResource)) { + scannedResources.add(subResource); read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags, operation.getParameters()); } diff --git a/modules/swagger-jaxrs/src/test/java/io/swagger/SimpleScannerTest.java b/modules/swagger-jaxrs/src/test/java/io/swagger/SimpleScannerTest.java index 0b8ca5fcd1..3dde187de3 100644 --- a/modules/swagger-jaxrs/src/test/java/io/swagger/SimpleScannerTest.java +++ b/modules/swagger-jaxrs/src/test/java/io/swagger/SimpleScannerTest.java @@ -4,6 +4,7 @@ import com.google.common.base.Functions; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableMap; + import io.swagger.jaxrs.Reader; import io.swagger.jaxrs.config.DefaultReaderConfig; import io.swagger.models.ArrayModel; @@ -49,7 +50,9 @@ import io.swagger.resources.ResourceWithVoidReturns; import io.swagger.resources.SimpleResource; import io.swagger.resources.SimpleResourceWithoutAnnotations; +import io.swagger.resources.SimpleSelfReferencingSubResource; import io.swagger.resources.TaggedResource; + import org.testng.annotations.Test; import java.util.ArrayList; @@ -318,6 +321,19 @@ public void scanSimpleResourceWithoutAnnotations() { assertNull(param2.getDescription()); } + @Test(description = "scan a simple self-referencing subresource") + public void scanSimpleSelfReferencingSubResource() { + DefaultReaderConfig config = new DefaultReaderConfig(); + config.setScanAllResources(true); + Swagger swagger = new Reader(new Swagger(), config).read(SimpleSelfReferencingSubResource.class); + + assertEquals(swagger.getPaths().size(), 1); + + Operation get = getGet(swagger, "/sub"); + assertNotNull(get); + assertEquals(get.getParameters().size(), 0); + } + @Test(description = "scan resource with ApiOperation.code() value") public void scanResourceWithApiOperationCodeValue() { Swagger swagger = getSwagger(ResourceWithApiOperationCode.class);