Skip to content

Commit

Permalink
Refs #1636, applies Option 4 scanning model
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed May 12, 2016
1 parent 9ea4057 commit 0116979
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java
Expand Up @@ -186,11 +186,15 @@ private Swagger read(Class<?> cls, String parentPath, String parentMethod, boole
boolean hasApiAnnotation = (api != null);
boolean isApiHidden = hasApiAnnotation && api.hidden();

// class readable only if annotated with @Path or isSubresource, or and @Api not hidden
boolean classReadable = (hasPathAnnotation || isSubresource) && !isApiHidden;
// class readable only if annotated with ((@Path and @Api) or isSubresource ) - and @Api not hidden
boolean classReadable = ((hasPathAnnotation && hasApiAnnotation)|| isSubresource) && !isApiHidden;

// with scanAllResources true in config and @Api not hidden scan only if it has also @Path annotation or is subresource
boolean scanAll = !isApiHidden && config.isScanAllResources() && (hasPathAnnotation || isSubresource);

// readable if classReadable or scanAll
boolean readable = classReadable || scanAll;

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

if (!readable) {
return swagger;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import io.swagger.resources.ClassWithExamplePost;
import io.swagger.resources.HiddenResource;
import io.swagger.resources.NicknamedOperation;
import io.swagger.resources.NotValidRootResource;
import io.swagger.resources.Resource1041;
import io.swagger.resources.Resource1073;
import io.swagger.resources.Resource1085;
Expand Down Expand Up @@ -309,6 +310,11 @@ public void notScanHiddenResource() {
assertNull(getSwagger(HiddenResource.class).getPaths());
}

@Test(description = "not scan a resource without @Api annotation")
public void notScanNotValidRootResourcee() {
assertNull(getSwagger(NotValidRootResource.class).getPaths());
}

@Test(description = "correctly model an empty model per 499")
public void scanResourceWithEmptyModel() {
Map<String, Model> definitions = getSwagger(ResourceWithEmptyModel.class).getDefinitions();
Expand Down
@@ -0,0 +1,19 @@
package io.swagger.resources;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import java.util.ArrayList;

@Path("fun")
public class NotValidRootResource {
@GET
@ApiOperation(value = "this", tags = "tag1")
@Path("/this")
public Response getThis(@ApiParam(value = "test") ArrayList<String> tenantId) {
return Response.ok().build();
}
}

0 comments on commit 0116979

Please sign in to comment.