JAVA-21459 Upgrade spring-rest-http-2 to use SpringDoc in place of SpringFox (#14131)

* JAVA-21459 Upgrade spring-rest-http-2 to use SpringDoc in place of SpringFox

* JAVA-21459 Code Review changes

* JAVA-21459 Formatting pom changes

* JAVA-21459 Formatting pom changes
This commit is contained in:
anuragkumawat 2023-06-06 10:54:12 +05:30 committed by GitHub
parent 3f9bddc9ab
commit 0e4baeda6a
6 changed files with 51 additions and 53 deletions

View File

@ -24,16 +24,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -47,11 +37,23 @@
<artifactId>resilience4j-timelimiter</artifactId>
<version>${resilience4j.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<swagger2.version>2.9.2</swagger2.version>
<resilience4j.version>1.6.1</resilience4j.version>
<springdoc.version>1.7.0</springdoc.version>
<guava.version>31.0.1-jre</guava.version>
</properties>
</project>

View File

@ -0,0 +1,17 @@
package com.baeldung.endpoint.swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
@Configuration
public class SpringDocConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI().info(new Info().title("SpringDoc example")
.description("SpringDoc application")
.version("v0.0.1"));
}
}

View File

@ -1,21 +0,0 @@
package com.baeldung.endpoint.swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.swaggerui.disable;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SwaggerUIDisableApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerUIDisableApplication.class, args);
}
}

View File

@ -6,33 +6,21 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
@Profile("!prod && swagger")
//@Profile("!prod")
// @Profile("swagger")
// @ConditionalOnExpression(value = "${useSwagger:false}")
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.baeldung"))
.paths(PathSelectors.regex("/.*"))
.build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
public OpenAPI openAPI() {
return new OpenAPI().info(new Info().title("SpringDoc Disable SwaggerUI example")
.description("SpringDoc Disable SwaggerUI application")
.version("v0.0.1"));
}
}

View File

@ -1,6 +1,6 @@
package com.baeldung.swaggerui.disable.controllers;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@ -14,7 +14,7 @@ public class VersionController {
this.environment = environment;
}
@ApiOperation(value = "Get the currently deployed API version and active Spring profiles")
@Operation(summary = "Get the currently deployed API version and active Spring profiles")
@GetMapping("/api/version")
public Version getVersion() {
return new Version("1.0", environment.getActiveProfiles());