Skip to content

Commit 0116979

Browse files
committed
Refs #1636, applies Option 4 scanning model
1 parent 9ea4057 commit 0116979

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,15 @@ private Swagger read(Class<?> cls, String parentPath, String parentMethod, boole
186186
boolean hasApiAnnotation = (api != null);
187187
boolean isApiHidden = hasApiAnnotation && api.hidden();
188188

189-
// class readable only if annotated with @Path or isSubresource, or and @Api not hidden
190-
boolean classReadable = (hasPathAnnotation || isSubresource) && !isApiHidden;
189+
// class readable only if annotated with ((@Path and @Api) or isSubresource ) - and @Api not hidden
190+
boolean classReadable = ((hasPathAnnotation && hasApiAnnotation)|| isSubresource) && !isApiHidden;
191+
192+
// with scanAllResources true in config and @Api not hidden scan only if it has also @Path annotation or is subresource
193+
boolean scanAll = !isApiHidden && config.isScanAllResources() && (hasPathAnnotation || isSubresource);
194+
195+
// readable if classReadable or scanAll
196+
boolean readable = classReadable || scanAll;
191197

192-
// readable if classReadable or (scanAllResources true in config and @Api not hidden)
193-
boolean readable = classReadable || (!isApiHidden && config.isScanAllResources());
194198

195199
if (!readable) {
196200
return swagger;

modules/swagger-jaxrs/src/test/java/io/swagger/SimpleReaderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.swagger.resources.ClassWithExamplePost;
3131
import io.swagger.resources.HiddenResource;
3232
import io.swagger.resources.NicknamedOperation;
33+
import io.swagger.resources.NotValidRootResource;
3334
import io.swagger.resources.Resource1041;
3435
import io.swagger.resources.Resource1073;
3536
import io.swagger.resources.Resource1085;
@@ -309,6 +310,11 @@ public void notScanHiddenResource() {
309310
assertNull(getSwagger(HiddenResource.class).getPaths());
310311
}
311312

313+
@Test(description = "not scan a resource without @Api annotation")
314+
public void notScanNotValidRootResourcee() {
315+
assertNull(getSwagger(NotValidRootResource.class).getPaths());
316+
}
317+
312318
@Test(description = "correctly model an empty model per 499")
313319
public void scanResourceWithEmptyModel() {
314320
Map<String, Model> definitions = getSwagger(ResourceWithEmptyModel.class).getDefinitions();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.swagger.resources;
2+
3+
import io.swagger.annotations.ApiOperation;
4+
import io.swagger.annotations.ApiParam;
5+
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.Path;
8+
import javax.ws.rs.core.Response;
9+
import java.util.ArrayList;
10+
11+
@Path("fun")
12+
public class NotValidRootResource {
13+
@GET
14+
@ApiOperation(value = "this", tags = "tag1")
15+
@Path("/this")
16+
public Response getThis(@ApiParam(value = "test") ArrayList<String> tenantId) {
17+
return Response.ok().build();
18+
}
19+
}

0 commit comments

Comments
 (0)