Created
May 16, 2015 15:26
-
-
Save natros/370c0093fa60379c3901 to your computer and use it in GitHub Desktop.
This file contains 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
import com.google.inject.AbstractModule; | |
import com.wordnik.swagger.annotations.Api; | |
import com.wordnik.swagger.config.ScannerFactory; | |
import com.wordnik.swagger.jaxrs.config.ReflectiveJaxrsScanner; | |
import com.wordnik.swagger.jaxrs.listing.ApiListingResource; | |
import com.wordnik.swagger.jaxrs.listing.SwaggerSerializers; | |
import com.wordnik.swagger.models.*; | |
import org.reflections.Reflections; | |
import java.util.Set; | |
public class SwaggerModule extends AbstractModule { | |
private final Reflections reflections; | |
public SwaggerModule(Reflections reflections) { | |
this.reflections = reflections; | |
} | |
@Override | |
protected void configure() { | |
bind(ApiListingResource.class); | |
bind(SwaggerSerializers.class); | |
Info info = new Info(); | |
info.setTitle("Swagger example"); | |
info.setVersion("1.0.0"); | |
MyReflectiveJaxrsScanner scanner = new MyReflectiveJaxrsScanner(); | |
scanner.setReflections(reflections); | |
scanner.setInfo(info); | |
ScannerFactory.setScanner(scanner); | |
} | |
private static class MyReflectiveJaxrsScanner extends ReflectiveJaxrsScanner { | |
private Info info; | |
@Override | |
public Set<Class<?>> classes() { | |
return reflections.getTypesAnnotatedWith(Api.class); | |
} | |
@Override | |
public Swagger configure(Swagger swagger) { | |
swagger.setInfo(info); | |
swagger.setBasePath("/api"); | |
swagger.scheme(Scheme.HTTP); | |
return swagger; | |
} | |
public void setInfo(Info info) { | |
this.info = info; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use this with guice.