swagger-samples icon indicating copy to clipboard operation
swagger-samples copied to clipboard

java-dropwizard performs initialization of Swagger object twice, potentially dropping configuration

Open btiernay opened this issue 9 years ago • 0 comments

If a the Swagger object on BeanConfig is modified in a method such as https://github.com/swagger-api/swagger-samples/blob/master/java/java-dropwizard/src/main/java/io/swagger/sample/SwaggerSampleApplication.java#L33-L37 then it will go missing when the ApiListingResource is first initialized. This is because the BaseApiListingResource#process method looks in the ServletContext for the Swagger object (https://github.com/swagger-api/swagger-core/blob/0d72a72c33021e03a9876dc45d2656d11604037e/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java#L46). It should be possible to communicate this value from Dropwizard to the servlet context.

I attempted to do this via:

    BeanConfig config = new BeanConfig();
    config.setServletConfig(environment.getJerseyServletContainer().getServletContext());

But this does not work since environment.getJerseyServletContainer().getServletContext() returns null at this point in the execution.

btiernay avatar May 15 '16 16:05 btiernay