Last active
August 29, 2015 14:07
-
-
Save pofallon/79e84ba53e8eec5a5e98 to your computer and use it in GitHub Desktop.
Sample JAX-RS 2.0 filter to remove AsyncResponse parameters from Swagger docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Provider | |
public class SwaggerAsyncResponseFilter implements ContainerResponseFilter { | |
SwaggerSpecFilter removeAsyncFilter = new SwaggerSpecFilter() { | |
public boolean isOperationAllowed(Operation operation, ApiDescription api, Map<String, List<String>> params, Map<String, String> cookies, | |
Map<String, List<String>> headers) { | |
return true; | |
} | |
public boolean isParamAllowed(Parameter parameter, Operation operation, ApiDescription api, Map<String,List<String>> params, | |
Map<String,String> cookies, Map<String,List<String>> headers) { | |
if (parameter.dataType().equals("AsyncResponse")) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
}; | |
SpecFilter specFilter = new SpecFilter(); | |
public void filter(ContainerRequestContext requestContext, | |
ContainerResponseContext responseContext) { | |
if (responseContext.getEntityClass().toString().contains("com.wordnik.swagger.model.ApiListing")) { | |
try { | |
ApiListing listing = (ApiListing)responseContext.getEntity(); | |
ApiListing filtered = specFilter.filter(listing, removeAsyncFilter, new scala.collection.immutable.HashMap<String, scala.collection.immutable.List<String>>(), new scala.collection.immutable.HashMap<String, String>(), new scala.collection.immutable.HashMap<String, scala.collection.immutable.List<String>>()); | |
responseContext.setEntity(filtered); | |
} catch (Exception e) { | |
System.out.println("Error: " + e.getMessage() + "(" + e.getClass() + ")"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment