
org.springdoc.webflux.ui.SwaggerWelcomeWebFlux Maven / Gradle / Ivy
/*
*
* *
* * * Copyright 2019-2020 the original author or authors.
* * *
* * * Licensed under the Apache License, Version 2.0 (the "License");
* * * you may not use this file except in compliance with the License.
* * * You may obtain a copy of the License at
* * *
* * * https://www.apache.org/licenses/LICENSE-2.0
* * *
* * * Unless required by applicable law or agreed to in writing, software
* * * distributed under the License is distributed on an "AS IS" BASIS,
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * See the License for the specific language governing permissions and
* * * limitations under the License.
* *
*
*/
package org.springdoc.webflux.ui;
import java.util.Map;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.core.SpringDocConfigProperties;
import org.springdoc.core.SwaggerUiConfigParameters;
import org.springdoc.core.SwaggerUiConfigProperties;
import reactor.core.publisher.Mono;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.UriComponentsBuilder;
import static org.springdoc.core.Constants.SWAGGER_CONFIG_URL;
import static org.springdoc.core.Constants.SWAGGER_UI_PATH;
/**
* The type Swagger welcome.
* @author bnasslahsen
*/
@Controller
public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
/**
* The Webflux base path.
*/
private String webfluxBasePath;
/**
* Instantiates a new Swagger welcome.
*
* @param swaggerUiConfig the swagger ui config
* @param springDocConfigProperties the spring doc config properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param webFluxProperties the web flux properties
*/
public SwaggerWelcomeWebFlux(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebFluxProperties webFluxProperties) {
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
webfluxBasePath = webFluxProperties.getBasePath();
}
/**
* Redirect to ui mono.
*
* @param request the request
* @param response the response
* @return the mono
*/
@Operation(hidden = true)
@GetMapping(SWAGGER_UI_PATH)
@Override
public Mono redirectToUi(ServerHttpRequest request, ServerHttpResponse response) {
return super.redirectToUi(request, response);
}
/**
* Gets swagger ui config.
*
* @param request the request
* @return the swagger ui config
*/
@Operation(hidden = true)
@GetMapping(value = SWAGGER_CONFIG_URL, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Override
public Map getSwaggerUiConfig(ServerHttpRequest request) {
return super.getSwaggerUiConfig(request);
}
@Override
protected void calculateUiRootPath(StringBuilder... sbUrls) {
StringBuilder sbUrl = new StringBuilder();
calculateUiRootCommon(sbUrl, sbUrls);
}
@Override
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
if (oauthPrefix == null && !swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl())) {
this.oauthPrefix = uriComponentsBuilder.path(webfluxBasePath).path(swaggerUiConfigParameters.getUiRootPath()).path(webJarsPrefixUrl);
swaggerUiConfigParameters.setOauth2RedirectUrl(this.oauthPrefix.path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy