JAVA-21460 Upgrade spring-boot-swagger-jwt modules to use SpringDoc in place of SpringFox (#14296)
* JAVA-21460 Upgrade spring-boot-swagger-jwt modules to use SpringDoc in place of SpringFox * JAVA-21460 Upgrade spring-boot-swagger-2 module to use SpringDoc in place of SpringFox * JAVA-21460 Upgrade spring-boot-swagger module to use SpringDoc in place of SpringFox
This commit is contained in:
+8
-23
@@ -4,35 +4,20 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
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;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.apiInfo(apiEndPointsInfo());
|
||||
}
|
||||
|
||||
private ApiInfo apiEndPointsInfo() {
|
||||
return new ApiInfoBuilder().title("Swagger Array")
|
||||
@Bean
|
||||
public OpenAPI openAPI() {
|
||||
return new OpenAPI().info(new Info().title("Swagger Array")
|
||||
.description("This is a sample Swagger description for an Array server")
|
||||
.license("Apache 2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
|
||||
.version("1.0.0")
|
||||
.build();
|
||||
.license(new License().name("Apache 2.0")
|
||||
.url("http://www.apache.org/licenses/LICENSE-2.0.html")));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.baeldung.swagger2bootmvc.model.Foo;
|
||||
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
|
||||
@Controller
|
||||
public class FooController {
|
||||
@@ -26,7 +26,7 @@ public class FooController {
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/foos")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ResponseBody
|
||||
@ApiImplicitParams({ @ApiImplicitParam(name = "foo", value = "List of strings", paramType = "body", dataType = "Foo") })
|
||||
@Parameters({ @Parameter(name = "foo", description = "List of strings") })
|
||||
public Foo create(@RequestBody final Foo foo) {
|
||||
foo.setId(Long.parseLong(randomNumeric(2)));
|
||||
return foo;
|
||||
|
||||
+8
-9
@@ -10,27 +10,26 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.baeldung.swagger2bootmvc.model.User;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
||||
@Controller
|
||||
public class UserController {
|
||||
|
||||
public UserController() {
|
||||
super();
|
||||
} //@formatter:off
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/createUser", produces = "application/json; charset=UTF-8")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ResponseBody
|
||||
@ApiOperation(value = "Create user",
|
||||
notes = "This method creates a new user")
|
||||
public User createUser(@ApiParam(
|
||||
@Operation(summary = "Create user",
|
||||
description = "This method creates a new user")
|
||||
public User createUser(@Parameter(
|
||||
name = "firstName",
|
||||
type = "String",
|
||||
value = "First Name of the user",
|
||||
description = "First Name of the user",
|
||||
example = "Vatsal",
|
||||
required = true) @RequestParam String firstName) { //@formatter:on
|
||||
required = true) @RequestParam String firstName) {
|
||||
User user = new User(firstName);
|
||||
return user;
|
||||
}
|
||||
|
||||
+3
-4
@@ -2,14 +2,13 @@ package com.baeldung.swagger2bootmvc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@ApiModel
|
||||
@Schema
|
||||
public class Foo {
|
||||
private long id;
|
||||
|
||||
@ApiModelProperty(name = "name", dataType = "List", example = "[\"str1\", \"str2\", \"str3\"]")
|
||||
@Schema(name = "name", type = "array", example = "[\"str1\", \"str2\", \"str3\"]")
|
||||
private List<String> name;
|
||||
|
||||
public Foo() {
|
||||
|
||||
+3
-4
@@ -1,12 +1,11 @@
|
||||
package com.baeldung.swagger2bootmvc.model;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@ApiModel
|
||||
@Schema
|
||||
public class User {
|
||||
|
||||
@ApiModelProperty(value = "first name of the user", name = "firstName", dataType = "String", example = "Vatsal")
|
||||
@Schema(description = "first name of the user", name = "firstName", type = "string", example = "Vatsal")
|
||||
String firstName;
|
||||
|
||||
public User() {
|
||||
|
||||
Reference in New Issue
Block a user