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

switch from 'redirect:' prefix to ResponseEntity for redirecting UI index #1104

Merged
Merged
Show file tree
Hide file tree
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 @@ -12,6 +12,7 @@
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

Expand Down Expand Up @@ -54,7 +55,7 @@ public SwaggerWelcomeActuator(SwaggerUiConfigProperties swaggerUiConfig, SpringD
@Operation(hidden = true)
@GetMapping(DEFAULT_PATH_SEPARATOR)
@Override
public String redirectToUi(HttpServletRequest request) {
public ResponseEntity<Void> redirectToUi(HttpServletRequest request) {
return super.redirectToUi(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springdoc.ui.AbstractSwaggerWelcome;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.util.UriComponentsBuilder;

import static org.springdoc.core.Constants.SWAGGER_UI_URL;
Expand All @@ -26,15 +27,17 @@ public SwaggerWelcomeCommon(SwaggerUiConfigProperties swaggerUiConfig, SpringDoc
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
}

protected String redirectToUi(HttpServletRequest request) {
protected ResponseEntity<Void> redirectToUi(HttpServletRequest request) {
buildConfigUrl(request.getContextPath(), ServletUriComponentsBuilder.fromCurrentContextPath());
String sbUrl = swaggerUiConfigParameters.getUiRootPath() + SWAGGER_UI_URL;
String sbUrl = request.getContextPath() + swaggerUiConfigParameters.getUiRootPath() + SWAGGER_UI_URL;
UriComponentsBuilder uriBuilder = getUriComponentsBuilder(sbUrl);

// forward all queryParams from original request
request.getParameterMap().forEach(uriBuilder::queryParam);

return UrlBasedViewResolver.REDIRECT_URL_PREFIX + uriBuilder.build().encode().toString();
return ResponseEntity.status(HttpStatus.FOUND)
.location(uriBuilder.build().encode().toUri())
.build();
}

protected Map<String, Object> openapiJson(HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
Expand Down Expand Up @@ -76,7 +77,7 @@ public SwaggerWelcomeWebMvc(SwaggerUiConfigProperties swaggerUiConfig, SpringDoc
@Operation(hidden = true)
@GetMapping(SWAGGER_UI_PATH)
@Override
public String redirectToUi(HttpServletRequest request) {
public ResponseEntity<Void> redirectToUi(HttpServletRequest request) {
return super.redirectToUi(request);
}

Expand Down