Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect configured generator URL in swagger config #11714

Merged
merged 1 commit into from
Feb 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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