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:
parent
3f9bddc9ab
commit
0e4baeda6a
|
@ -24,16 +24,6 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
@ -47,11 +37,23 @@
|
||||||
<artifactId>resilience4j-timelimiter</artifactId>
|
<artifactId>resilience4j-timelimiter</artifactId>
|
||||||
<version>${resilience4j.version}</version>
|
<version>${resilience4j.version}</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<swagger2.version>2.9.2</swagger2.version>
|
<swagger2.version>2.9.2</swagger2.version>
|
||||||
<resilience4j.version>1.6.1</resilience4j.version>
|
<resilience4j.version>1.6.1</resilience4j.version>
|
||||||
|
<springdoc.version>1.7.0</springdoc.version>
|
||||||
|
<guava.version>31.0.1-jre</guava.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,33 +6,21 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
@Profile("!prod && swagger")
|
@Profile("!prod && swagger")
|
||||||
//@Profile("!prod")
|
//@Profile("!prod")
|
||||||
// @Profile("swagger")
|
// @Profile("swagger")
|
||||||
// @ConditionalOnExpression(value = "${useSwagger:false}")
|
// @ConditionalOnExpression(value = "${useSwagger:false}")
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableSwagger2
|
public class SwaggerConfig {
|
||||||
public class SwaggerConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket api() {
|
public OpenAPI openAPI() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2).select()
|
return new OpenAPI().info(new Info().title("SpringDoc Disable SwaggerUI example")
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.baeldung"))
|
.description("SpringDoc Disable SwaggerUI application")
|
||||||
.paths(PathSelectors.regex("/.*"))
|
.version("v0.0.1"));
|
||||||
.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/");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.swaggerui.disable.controllers;
|
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.core.env.Environment;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -14,7 +14,7 @@ public class VersionController {
|
||||||
this.environment = environment;
|
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")
|
@GetMapping("/api/version")
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
return new Version("1.0", environment.getActiveProfiles());
|
return new Version("1.0", environment.getActiveProfiles());
|
||||||
|
|
Loading…
Reference in New Issue