Merge pull request #10932 from hmdrzsharifi/BAEL-4956
Bael 4956: Swagger @Api description is deprecated
This commit is contained in:
commit
e81d9373da
@ -0,0 +1,12 @@
|
||||
package com.baeldung.tagopenapi;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication()
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.tagopenapi.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
public class OpenApi {
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI(@Value("${springdoc.version}") String appVersion) {
|
||||
return new OpenAPI().info(new Info().title("Controller API")
|
||||
.version(appVersion)
|
||||
.description("This is a sample server created using springdocs - a library for OpenAPI 3 with spring boot.")
|
||||
.termsOfService("http://swagger.io/terms/")
|
||||
.license(new License().name("Apache 2.0")
|
||||
.url("http://springdoc.org")));
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.tagopenapi.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/book")
|
||||
@Tag(name = "book service", description = "the book API with description tag annotation")
|
||||
public class BookController {
|
||||
|
||||
@GetMapping("/")
|
||||
public List<String> getBooks() {
|
||||
return Arrays.asList("book1", "book2");
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.baeldung.apiswagger;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication()
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.baeldung.apiswagger.config;
|
||||
|
||||
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.service.Tag;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
@Configuration
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
public static final String BOOK_TAG = "book service";
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.tags(new Tag(BOOK_TAG, "the book API with description api tag"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.apiswagger.controller;
|
||||
|
||||
import com.baeldung.apiswagger.config.SwaggerConfiguration;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/book")
|
||||
@Api(tags = {SwaggerConfiguration.BOOK_TAG})
|
||||
public class BookController {
|
||||
|
||||
@GetMapping("/")
|
||||
public List<String> getBooks() {
|
||||
return Arrays.asList("book1", "book2");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user