Controller
@Tag(name = "유저", description = "유저 관련 API입니다.")
@RestController
public class TestController {
@Operation(summary = "유저 다건 조회", description = "유저 단건 조회 API입니다.")
@GetMapping("/users")
public ResponseEntity<TestResponse> get() {
return ResponseEntity.ok(new TestResponse("test"));
}
@Operation(summary = "유저 가입", description = "유저 가입 API입니다.")
@PostMapping("/users")
public ResponseEntity<TestResponse> post(
@RequestBody TestRequest testRequest
) {
TestResponse response = new TestResponse("1");
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("{id}")
.buildAndExpand(response.getName())
.toUri();
return ResponseEntity.created(location)
.body(response);
}
}
@Tag
: api 그룹 설정을 위한 어노테이션
@Operation
: api 상세 정보 설정을 위한 어노테이션
DTO
public class TestRequest {
@Schema(description = "이름", defaultValue = "testName")
private String name;
}
public class TestResponse {
@Schema(description = "반환 이름", defaultValue = "testName")
private String name;
}
@Schema
: Request, Resposne 객체에 대한 설정을 위한 어노테이션
참고
Swaager에 대해