Skip to content

Commit ab0793b

Browse files
authored
Merge pull request #11738 from fgreinacher/fix/use-generator-host
fix: use information in generator host for generating spec
2 parents 0989603 + 8b96546 commit ab0793b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ public void init(ServletConfig config) throws ServletException {
3838
if (scheme != null) {
3939
bc.setSchemes(new String[] { scheme });
4040
}
41-
String host = hostURI.getHost();
42-
if (host != null) {
43-
bc.setHost(host);
41+
String authority = hostURI.getAuthority();
42+
if (authority != null) {
43+
// In Swagger host refers to host _and_ port, a.k.a. the URI authority
44+
bc.setHost(authority);
4445
}
4546
bc.setBasePath(hostURI.getPath() + "/api");
4647
} catch(URISyntaxException e) {

modules/swagger-generator/src/main/java/io/swagger/generator/DynamicSwaggerConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import io.swagger.models.Operation;
88
import io.swagger.models.Path;
99
import io.swagger.models.Swagger;
10+
import io.swagger.models.Scheme;
1011
import io.swagger.models.parameters.Parameter;
1112
import io.swagger.models.parameters.PathParameter;
1213

1314
import java.util.ArrayList;
15+
import java.util.Arrays;
1416
import java.util.Collections;
1517
import java.util.List;
18+
import java.util.stream.Collectors;
1619

1720
public class DynamicSwaggerConfig extends BeanConfig {
1821
static List<String> clients = new ArrayList<String>();
@@ -73,6 +76,15 @@ public Swagger configure(Swagger swagger) {
7376
}
7477
}
7578

76-
return swagger.info(getInfo()).host(getHost()).basePath("/api");
79+
Swagger result = swagger
80+
.info(getInfo())
81+
.host(getHost())
82+
.basePath(getBasePath());
83+
84+
if (getSchemes() != null) {
85+
result = result.schemes(Arrays.stream(getSchemes()).map(s -> Scheme.forValue(s)).collect(Collectors.toList()));
86+
}
87+
88+
return result;
7789
}
7890
}

0 commit comments

Comments
 (0)