Skip to content

Commit

Permalink
Updated the naive host/port resolution strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipkrish committed Apr 11, 2015
1 parent 13f663d commit 164b174
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ext {
groovy = "2.4.3"
spock = "1.0-groovy-2.4"
guava = "18.0"
springHateoas = "0.10.0.RELEASE"
springHateoas = "0.17.0.RELEASE"
slf4j = "1.7.12"
mockito = "1.10.19"
servlet = "3.0.1"
Expand Down Expand Up @@ -32,7 +32,8 @@ ext {
],
spring : [
"org.springframework.plugin:spring-plugin-core:${springPluginVersion}",
"org.springframework.plugin:spring-plugin-metadata:${springPluginVersion}"
"org.springframework.plugin:spring-plugin-metadata:${springPluginVersion}",
"org.springframework.hateoas:spring-hateoas:${springHateoas}"
],
springProvided: [
"org.springframework:spring-core:$spring",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import springfox.documentation.spring.web.DocumentationCache;
import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;

import javax.servlet.ServletRequest;
import java.net.URI;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;

@Controller
@ApiIgnore
Expand All @@ -52,16 +54,16 @@ public class Swagger2Controller {
public
@ResponseBody
ResponseEntity<Swagger> getDocumentation(
@RequestParam(value = "group", required = false) String swaggerGroup, ServletRequest request) {
@RequestParam(value = "group", required = false) String swaggerGroup) {

String groupName = Optional.fromNullable(swaggerGroup).or("default");
Documentation documentation = documentationCache.documentationByGroup(groupName);
if (documentation == null) {
return new ResponseEntity<Swagger>(HttpStatus.NOT_FOUND);
}
Swagger swagger = mapper.mapDocumentation(documentation);
//TODO - this will be problematic when behind a proxy
swagger.host(String.format("%s:%s", request.getServerName(), request.getServerPort()));
URI uri = linkTo(Swagger2Controller.class).toUri();
swagger.host(String.format("%s:%s", uri.getHost(), uri.getPort()));
return new ResponseEntity<Swagger>(swagger, HttpStatus.OK);
}

Expand Down

0 comments on commit 164b174

Please sign in to comment.