BAEL-4956: add source code for describng REST API in openapi
This commit is contained in:
parent
74f1bfefa2
commit
618cdbdced
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue