Reputation: 1643
I found swagger and swagger-ui and I like the approach. I already managed to get it working at least on Spring boot. Now I would like to integrate swagger in a Java EE application running on wildfly 9. Unfortunately this doesn't work at all. Swagger is really poor documented.
What is necessary to get it working? I follwed the instructions from the official swagger documentation at https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X.
This is my swagger dependency in build.gradle:
compile 'io.swagger:swagger-jaxrs:1.5.4'
This is my JAX-RS application class:
public class SmamblRestApiApplication extends Application {
private Set<Class<?>> classes = new HashSet<>();
public SmamblRestApiApplication() {
initClasses();
}
private void initSwagger() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setTitle("SmamblV1");
beanConfig.setVersion("1.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/rest/v1");
beanConfig.setResourcePackage("com.myapp.api.v1.rest");
beanConfig.setScan(true);
}
private void initClasses() {
//--- Api Endpoints --------------------------------------
classes.add(RegistrationApi.class);
classes.add(MigrationApi.class);
classes.add(PhoneNumberApi.class);
classes.add(UserResourceApi.class);
classes.add(MonitoringApi.class);
classes.add(PingApi.class);
classes.add(PublicUserResource.class);
//--- Filters --------------------------------------------
classes.add(ApiExceptionMapper.class);
classes.add(SecurityRolesFilter.class);
//--- Swagger --------------------------------------------
classes.add(ApiListingResource.class);
classes.add(SwaggerSerializers.class);
}
@Override
public Set<Class<?>> getClasses() {
return classes;
}
}
And I even annotated one method with a swagger annotation:
@Path("private/user")
@RolesAllowed({UserRole.USER})
@NoCache
@Api
public class UserResourceApi {
@Inject
UserFacade userFacade;
@RolesAllowed(UserRole.ADMIN)
@Produces(MediaType.APPLICATION_JSON)
@GET
@ApiOperation("test")
public List<UserResource> getAllUsers() {
return userFacade.findAllUsers();
}
// ...
When trying to reach the swagger.json as desribed in the documentation above, an empty file is returned (no 404 or s.th., so I believe something is working but doesn't output anything). What can I do?
Btw. can anyone explain me the difference between the com.wordnik and io.swagger packages?
Upvotes: 2
Views: 1946
Reputation: 8200
I think your code should be ok (I have a similar configuration working with WildFly). But, I don't see the initSwagger
method called in your code. Maybe the problem is only that the method is not being called.
Upvotes: 1