Question

I am trying to use dropwizard + swagger to have a rest api...and it's documentation.

Problem I found is that swagger requires to set a "basePath" property when initialising the resource that will serve the documentation:

@Override
public void run(MyServiceConfiguration configuration, Environment environment) throws Exception {
    ...
    ...
    // Set the swagger config options
    SwaggerConfig config = ConfigFactory.config();
    config.setApiVersion("1.0.0");
    config.setBasePath("http://localhost:9090/api");

I can get the port and the rootpath from the configuration parameter. But is there any way to actually get the protocol + hostname while I am at the service run method?

Was it helpful?

Solution

Try setting a relative path like this:

config.setBasePath(".." + environment.getApplicationContext().getContextPath());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top