Skip to content
Merged
Changes from 1 commit
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 @@ -28,15 +28,22 @@
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import java.util.Set;


@Configuration
@EnableSwagger2
public class OpenAPIDocumentationConfig {
private final Logger LOGGER = LoggerFactory.getLogger(OpenAPIDocumentationConfig.class);

ApiInfo apiInfo() {
final Properties properties = new Properties();
Expand All @@ -63,7 +70,7 @@ ApiInfo apiInfo() {

@Bean
public Docket customImplementation(){
return new Docket(DocumentationType.SWAGGER_2)
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
.build()
Expand All @@ -74,6 +81,27 @@ public Docket customImplementation(){
.ignoredParameterTypes(Resource.class)
.ignoredParameterTypes(InputStream.class)
.apiInfo(apiInfo());

String hostString = System.getenv("GENERATOR_HOST");
if (!StringUtils.isBlank(hostString)) {
try {
URI hostURI = new URI(hostString);
String scheme = hostURI.getScheme();
if (scheme != null) {
docket.protocols(Set.of(new String[] { scheme }));
}
String authority = hostURI.getAuthority();
if (authority != null) {
// In Swagger host refers to host _and_ port, a.k.a. the URI authority
docket.host(authority);
}
docket.pathMapping(hostURI.getPath());
} catch(URISyntaxException e) {
LOGGER.warn("Could not parse configured GENERATOR_HOST '" + hostString + "': " + e.getMessage());
}
}

return docket;
}

}