Skip to content

Commit

Permalink
fix: respect configured generator URL in swagger config
Browse files Browse the repository at this point in the history
  • Loading branch information
fgreinacher authored Feb 18, 2022
1 parent 06d8ae7 commit 5d827ae
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,41 @@

package io.swagger.generator;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

public class Bootstrap extends HttpServlet {
private static final long serialVersionUID = 1400930071893332856L;

@Override
public void init(ServletConfig config) throws ServletException {
DynamicSwaggerConfig bc = new DynamicSwaggerConfig();
bc.setBasePath("/api");
String hostString = System.getenv("GENERATOR_HOST");
if (!StringUtils.isBlank(hostString)) {
try {
URI hostURI = new URI(hostString);
String scheme = hostURI.getScheme();
if (scheme != null) {
bc.setSchemes(new String[] { scheme });
}
String host = hostURI.getHost();
if (host != null) {
bc.setHost(host);
}
bc.setBasePath(hostURI.getPath() + "/api");
} catch(URISyntaxException e) {
System.out.println("Could not parse configured GENERATOR_HOST as URL: " + e.getMessage());
}
} else {
bc.setBasePath("/api");
}
bc.setTitle("Swagger Generator");
bc.setDescription("This is an online swagger codegen server. You can find out more "
+ "at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
Expand Down

0 comments on commit 5d827ae

Please sign in to comment.