BAEL-4956: add source code for describing REST API in swagger
This commit is contained in:
parent
071dae8feb
commit
74f1bfefa2
|
@ -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…
Reference in New Issue