Skip to content

Commit 21b768d

Browse files
authored
[FEAT] setting swagger
[FEAT] setting swagger
2 parents a74d95e + b2d1675 commit 21b768d

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies {
3737
//aws
3838
implementation 'com.amazonaws:aws-java-sdk-dynamodb:1.11.563'
3939

40+
//swagger
41+
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
4042
}
4143

4244
tasks.named('test') {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cloudcomputing.ohhanahana.config;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.info.Info;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
public class SwaggerConfig {
10+
11+
@Bean
12+
public OpenAPI customOpenAPI() {
13+
return new OpenAPI()
14+
.info(new Info().title("오하나하나 API")
15+
.version("1.0")
16+
.description("API documentation for 오하나하나 application"));
17+
}
18+
}

src/main/java/com/cloudcomputing/ohhanahana/controller/BusController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
import com.cloudcomputing.ohhanahana.dto.response.RecommendResponse;
55
import com.cloudcomputing.ohhanahana.dto.response.ShuttleResponse;
66
import com.cloudcomputing.ohhanahana.service.BusService;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.tags.Tag;
79
import jakarta.xml.bind.JAXBException;
810
import lombok.RequiredArgsConstructor;
911
import org.springframework.http.ResponseEntity;
1012
import org.springframework.web.bind.annotation.GetMapping;
1113
import org.springframework.web.bind.annotation.RequestMapping;
1214
import org.springframework.web.bind.annotation.RestController;
1315

16+
@Tag(name = "버스 API", description = "버스 관련 API")
1417
@RestController
1518
@RequiredArgsConstructor
1619
@RequestMapping("/bus")
1720
public class BusController {
1821

1922
private final BusService busService;
2023

24+
@Operation(summary = "주변 정류장 버스 도착 정보 조회 API", description = "주변 정류장 버스 도착 정보를 조회하는 API입니다.")
2125
@GetMapping("/recommend")
2226
public ResponseEntity<RecommendResponse> recommendBus() {
2327
try {
@@ -28,13 +32,15 @@ public ResponseEntity<RecommendResponse> recommendBus() {
2832
}
2933
}
3034

35+
@Operation(summary = "셔틀버스 도착 정보 조회 API", description = "셔틀버스 도착 정보를 조회하는 API입니다.")
3136
@GetMapping("/shuttle")
3237
public ResponseEntity<ShuttleResponse> shuttleBus() {
3338
return busService.getShuttleBus()
3439
.map(ResponseEntity::ok)
3540
.orElseGet(() -> ResponseEntity.ok(null));
3641
}
3742

43+
@Operation(summary = "전체 버스 도착 정보 조회 API", description = "전체 버스 도착 정보를 조회하는 API입니다.")
3844
@GetMapping
3945
public ResponseEntity<BusResponse> findAllBus() {
4046
try {
@@ -45,6 +51,7 @@ public ResponseEntity<BusResponse> findAllBus() {
4551
}
4652
}
4753

54+
@Operation(summary = "511번 버스 도착 정보 조회 API", description = "511번 버스 도착 정보를 조회하는 API입니다.")
4855
@GetMapping("/511")
4956
public ResponseEntity<RecommendResponse.Bus> get511Bus() {
5057
try {

src/main/java/com/cloudcomputing/ohhanahana/controller/PersonController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import com.cloudcomputing.ohhanahana.entity.Person;
44
import com.cloudcomputing.ohhanahana.repository.PersonRepository;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
57
import java.util.List;
6-
import lombok.RequiredArgsConstructor;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.web.bind.annotation.DeleteMapping;
910
import org.springframework.web.bind.annotation.GetMapping;
@@ -14,35 +15,41 @@
1415
import org.springframework.web.bind.annotation.RequestMapping;
1516
import org.springframework.web.bind.annotation.RestController;
1617

18+
@Tag(name = "Person API", description = "Person 관련 API")
1719
@RestController
1820
@RequestMapping("/persons")
1921
public class PersonController {
2022

2123
@Autowired
2224
private PersonRepository personRepository;
2325

26+
@Operation(summary = "Person 저장 API", description = "Person을 저장하는 API입니다.")
2427
@PostMapping
2528
public Person save(@RequestBody Person person) {
2629

2730
return personRepository.save(person);
2831
}
2932

33+
@Operation(summary = "Person 조회 API", description = "Person을 조회하는 API입니다.")
3034
@GetMapping("/{id}")
3135
public Person findById(@PathVariable(value = "id") String id) {
3236
return personRepository.findById(id);
3337
}
3438

39+
@Operation(summary = "Person 전체 조회 API", description = "Person 전체를 조회하는 API입니다.")
3540
@GetMapping("/all")
3641
public List<Person> findAll() {
3742
return personRepository.findAll();
3843
}
3944

45+
@Operation(summary = "Person 수정 API", description = "Person을 수정하는 API입니다.")
4046
@PutMapping("/{id}")
4147
public String update(@PathVariable(value="id") String id,
4248
@RequestBody Person person) {
4349
return personRepository.update(id, person);
4450
}
4551

52+
@Operation(summary = "Person 삭제 API", description = "Person을 삭제하는 API입니다.")
4653
@DeleteMapping("/{id}")
4754
public String delete(@PathVariable(value="id") String id) {
4855
return personRepository.delete(id);

src/main/java/com/cloudcomputing/ohhanahana/controller/SensorDataController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
import com.cloudcomputing.ohhanahana.dto.response.SensorDataResponse;
44
import com.cloudcomputing.ohhanahana.service.SensorDataService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
57
import jakarta.xml.bind.JAXBException;
68
import lombok.RequiredArgsConstructor;
79
import org.springframework.http.ResponseEntity;
810
import org.springframework.web.bind.annotation.GetMapping;
911
import org.springframework.web.bind.annotation.RequestMapping;
1012
import org.springframework.web.bind.annotation.RestController;
1113

14+
@Tag(name = "혼잡도 API", description = "혼잡도 관련 API")
1215
@RestController
1316
@RequiredArgsConstructor
1417
@RequestMapping("/congestion")
1518
public class SensorDataController {
1619

1720
private final SensorDataService sensorDataService;
1821

22+
@Operation(summary = "혼잡도 조회 API", description = "혼잡도를 조회하는 API입니다.")
1923
@GetMapping("/")
2024
public ResponseEntity<Object> findTest() throws JAXBException {
2125
return ResponseEntity.ok(sensorDataService.findLatestSensorData());
2226
}
2327

28+
@Operation(summary = "혼잡도 랜덤 조회 API", description = "혼잡도를 랜덤으로 조회하는 API입니다.")
2429
@GetMapping("/random")
2530
public ResponseEntity<Object> findRandomSensorData() throws JAXBException {
2631
return ResponseEntity.ok(sensorDataService.generateRandomSensorData());

0 commit comments

Comments
 (0)