Skip to content

Commit

Permalink
swagger-api#1424 Processing a self-referencing subResource leads to …
Browse files Browse the repository at this point in the history
…a series of recursive scans
  • Loading branch information
elakito committed Sep 3, 2015
1 parent 132616d commit c3a5561
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ public class Reader {
private final ReaderConfig config;
private Swagger swagger;

private Set<Class<?>> scannedResources;

public Reader(Swagger swagger) {
this(swagger, null);
}

public Reader(Swagger swagger, ReaderConfig config) {
this.swagger = swagger == null ? new Swagger() : swagger;
this.config = new DefaultReaderConfig(config);
this.scannedResources = new HashSet<Class<?>>();
}

/**
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c3a5561

Please sign in to comment.