Skip to content

Commit

Permalink
GH-5 NotFoundException: null
Browse files Browse the repository at this point in the history
Adding support for direct swagger document link
  • Loading branch information
lex-em committed Mar 22, 2019
1 parent 5d2e900 commit e5ef0a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ServiceInfo {

private String swaggerUri;

private String directSwaggerDocUrl;

private String protocol = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public Optional<String> getServicePath(String route) {
.map(ServiceInfo::getPath)
.map(path -> path.replaceAll("^/", "").replaceAll("/\\*\\*", ""));
}

public Optional<String> getDirectSwaggerDocUrl(String route) {
return Optional.ofNullable(routes.get(route))
.map(ServiceInfo::getDirectSwaggerDocUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ public ObjectNode getSwaggerDoc(String route) {
@Override
public ObjectNode getOriginalSwaggerDoc(String route) {
Optional<String> serviceUrlOpt = servicesSwaggerInfo.getServiceUrl(route);
String serviceUrl = serviceUrlOpt.orElseGet(() -> servicesSwaggerInfo.getDefaultProtocol() + route);
RestTemplate restTemplate = serviceUrlOpt.map(x -> pureRestTemplate).orElse(loadBalancedRestTemplate);
String url = String.format("%s/%s",
serviceUrl,
servicesSwaggerInfo.getSwaggerUrl(route));
RestTemplate restTemplate = serviceUrlOpt
.map(x -> pureRestTemplate)
.orElse(loadBalancedRestTemplate);
String url = servicesSwaggerInfo.getDirectSwaggerDocUrl(route)
.orElseGet(() -> {
String serviceUrl = serviceUrlOpt
.orElseGet(() -> servicesSwaggerInfo.getDefaultProtocol() + route);
return String.format("%s/%s",
serviceUrl,
servicesSwaggerInfo.getSwaggerUrl(route));
});
try {
return restTemplate.getForObject(url, ObjectNode.class);
} catch (IllegalStateException e) {
Expand Down

0 comments on commit e5ef0a2

Please sign in to comment.