Skip to content

Commit

Permalink
Merge pull request #1577 from elakito/work-1574
Browse files Browse the repository at this point in the history
fix #1574 allow visit the same sub resources along different paths
  • Loading branch information
fehguy committed Dec 23, 2015
2 parents 260cf9b + 8921f2f commit 05475b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ private Swagger read(Class<?> cls, String parentPath, String parentMethod, boole
if (subResource != null && !scannedResources.contains(subResource)) {
scannedResources.add(subResource);
read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags, operation.getParameters(), scannedResources);
// remove the sub resource so that it can visit it later in another path
// but we have a room for optimization in the future to reuse the scanned result
// by caching the scanned resources in the reader instance to avoid actual scanning
// the the resources again
scannedResources.remove(subResource);
}

// can't continue without a valid http method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,24 @@ public void scanSimpleSelfReferencingSubResource() {
config.setScanAllResources(true);
Swagger swagger = new Reader(new Swagger(), config).read(SimpleSelfReferencingSubResource.class);

assertEquals(swagger.getPaths().size(), 2);
assertEquals(swagger.getPaths().size(), 4);

// these two paths are directly reachable without passing thru a recursive reference
Operation retrieve = getGet(swagger, "/sub");
assertNotNull(retrieve);
assertEquals(retrieve.getParameters().size(), 0);

retrieve = getGet(swagger, "/sub/leaf");
assertNotNull(retrieve);
assertEquals(retrieve.getParameters().size(), 0);

retrieve = getGet(swagger, "/sub/recurse2");
assertNotNull(retrieve);
assertEquals(retrieve.getParameters().size(), 0);

retrieve = getGet(swagger, "/sub/recurse2/leaf");
assertNotNull(retrieve);
assertEquals(retrieve.getParameters().size(), 0);
}

@Test(description = "scan resource with ApiOperation.code() value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public SubResource retrieveSelf() {
public SubResource2 retrieveSelf2() {
return new SubResource2();
}
@Path("/leaf")
public SubResource3 retrieveLeaf() {
return new SubResource3();
}
}

public static class SubResource2 {
Expand All @@ -47,5 +51,17 @@ public SubResource2 retrieveSelf() {
public SubResource retrieveSelf1() {
return new SubResource();
}
@Path("/leaf")
public SubResource3 retrieveLeaf() {
return new SubResource3();
}
}

public static class SubResource3 {
@GET
@Produces("application/json")
public SubResource3 retrieve() {
return this;
}
}
}

0 comments on commit 05475b8

Please sign in to comment.