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?

Était-ce utile?

La solution

Try setting a relative path like this:

config.setBasePath(".." + environment.getApplicationContext().getContextPath());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top