Closed jarrodhroberson closed 8 years ago
If you use the default provided ones and don't override the docs/pages provider do you still get the same error?
This does not throw the ArrayIndexOutOfBoundsException:
bootstrap.addBundle(new SwaggerAssetsBundle(new ApiProvider()
{
@Nonnull
public SwaggerApiProvider apply(@Nullable final Environment input)
{
final BeanConfig config = new BeanConfig();
config.setTitle("Public API");
config.setVersion("1.0.0");
config.setResourcePackage("com.mycompany.resource");
config.setScan(true);
return new SwaggerApiResource(config);
}
}, new SwaggerPagesResource()));
I got it to work, I wanted these as inner classes to my Application
class and I had to add static
to the class definitions and it started working.
@Path("/docs")
@Produces(MediaType.TEXT_HTML)
public static class DocumentsPage extends SwaggerPagesResource
{ /* intentionally blank */}
@Path("/docs")
public static class DocumentsPageApi extends SwaggerApiResource
{
public DocumentsPageApi(@Nonnull final BeanConfig swaggerConfig)
{
super(swaggerConfig);
}
}
Ahh, that'll do it. Thanks!
@devshorts we should try to improve the exception experience here and make debugging easier. Lets file a follow up issue to track that.
I'm not sure how much we can do here given that the pages are resource blocks, and were nested inside of another class that did not have a resource block. I'd love to get a sample app if possible @jarrodhroberson to see what we can do to make this something that future users wont encounter though
Here is an example Application class that failed without the static
being added to the class defintions.
package com.gm.gdat.example;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.paradoxical.dropwizard.swagger.*;
import io.swagger.jaxrs.config.BeanConfig;
public class ExampleApplication extends Application<ExampleConfiguration>
{
public static void main(@Nonnull final String[] args) throws Exception
{
new ExampleApplication().run(args);
}
@Override
public void initialize(final Bootstrap<ExampleConfiguration> bootstrap)
{
bootstrap.addBundle(new SwaggerAssetsBundle(new ApiProvider()
{
@Nonnull
public SwaggerApiProvider apply(@Nullable final Environment input)
{
final BeanConfig config = new BeanConfig();
config.setTitle("Public API");
config.setVersion("1.0.0");
config.setResourcePackage("com.my.example.resource");
config.setScan(true);
return new DocumentsPageApi(config);
}
}, new DocumentsPage()));
bootstrap.addBundle(new AssetsBundle("/assets/", "/app", null, "app"));
bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
bootstrap.addBundle(new AssetsBundle("/assets/img", "/img", null, "img"));
}
@Override
public void run(final ExampleConfiguration config, final Environment environment) throws Exception
{
/* resources removed for brevity */
}
@Path("/docs")
@Produces(MediaType.TEXT_HTML)
public static class DocumentsPage extends SwaggerPagesResource
{ /* intentionally blank */}
@Path("/docs")
public static class DocumentsPageApi extends SwaggerApiResource
{
public DocumentsPageApi(@Nonnull final BeanConfig swaggerConfig)
{
super(swaggerConfig);
}
}
}
I can't seem to get this to work.
and I have these defined
I get this stacktrace:
When I comment out that first block the error goes away but does not register the swagger documentation.