Domanda

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?

È stato utile?

Soluzione

Try setting a relative path like this:

config.setBasePath(".." + environment.getApplicationContext().getContextPath());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top