Skip to content

Commit

Permalink
Merge pull request #37 from Team-Tiki/init/#35-swagger
Browse files Browse the repository at this point in the history
[INIT] Swagger 설정
  • Loading branch information
Chan531 authored Jul 11, 2024
2 parents 8875de1 + f91c0f5 commit c0c7a74
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation("software.amazon.awssdk:bom:2.21.0")
implementation("software.amazon.awssdk:s3:2.21.0")

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
}

tasks.named('test') {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/tiki/server/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
Expand All @@ -29,6 +30,7 @@ public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
permitSwaggerUri(http);
return http
.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
Expand Down Expand Up @@ -56,4 +58,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
)
.build();
}

private void permitSwaggerUri(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
.requestMatchers(new AntPathRequestMatcher("/v3/api-docs/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/swagger-ui/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll());
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/tiki/server/common/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tiki.server.common.config;

import static io.swagger.v3.oas.models.security.SecurityScheme.Type.HTTP;

import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.val;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI openApi() {
val securityScheme = new SecurityScheme();
securityScheme.setType(HTTP);
securityScheme.setScheme("bearer");
securityScheme.setBearerFormat("JWT");

val components = new Components();
components.addSecuritySchemes("BearerAuthentication", securityScheme);

val securityRequirement = new SecurityRequirement();
securityRequirement.addList("BearerAuthentication");

val info = new Info();
info.setTitle("TIKI API Document");
info.setDescription("티키 API 명세서");
info.setVersion("1.0.0");

return new OpenAPI()
.components(components)
.security(List.of(securityRequirement))
.info(info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.external.controller.docs.S3ControllerDocs;
import com.tiki.server.external.dto.request.PreSignedUrlRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.util.S3Service;
Expand All @@ -20,10 +21,11 @@
@RestController
@RequestMapping("api/v1/file")
@RequiredArgsConstructor
public class S3Controller {
public class S3Controller implements S3ControllerDocs {

private final S3Service s3Service;

@Override
@GetMapping("/upload")
public ResponseEntity<SuccessResponse<PreSignedUrlResponse>> getPreSignedUrl(@RequestBody PreSignedUrlRequest request) {
val response = s3Service.getUploadPreSignedUrl(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.tiki.server.external.controller.docs;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

import com.tiki.server.common.dto.ErrorResponse;
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.external.dto.request.PreSignedUrlRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "S3", description = "AWS S3 API")
public interface S3ControllerDocs {

@Operation(
summary = "Presigned Url 생성",
description = "s3로부터 Presigned Url을 생성한다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "S3 PRESIGNED URL 불러오기 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<PreSignedUrlResponse>> getPreSignedUrl(
@RequestBody PreSignedUrlRequest request
);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.tiki.server.member.adapter;

import static com.tiki.server.member.message.ErrorCode.INVALID_MEMBER;
import static com.tiki.server.team.message.ErrorCode.INVALID_TEAM;

import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.member.entity.Member;
import com.tiki.server.member.exception.MemberException;
import com.tiki.server.member.repository.MemberRepository;
import com.tiki.server.team.entity.Team;
import com.tiki.server.team.exception.TeamException;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.UriGenerator;
import com.tiki.server.timeblock.controller.docs.TimeBlockControllerDocs;
import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse;
import com.tiki.server.timeblock.service.TimeBlockService;
Expand All @@ -25,14 +26,15 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1/time-blocks")
public class TimeBlockController {
public class TimeBlockController implements TimeBlockControllerDocs {

private final TimeBlockService timeBlockService;

@Override
@PostMapping("/team/{teamId}/time-block")
public ResponseEntity<SuccessResponse<TimeBlockCreationResponse>> createTimeBlock(
Principal principal,
@PathVariable("teamId") long teamId,
@PathVariable long teamId,
@RequestParam String type,
@RequestBody TimeBlockCreationRequest request
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.tiki.server.timeblock.controller.docs;

import java.security.Principal;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.tiki.server.common.dto.ErrorResponse;
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "time-blocks", description = "타임 블록 API")
public interface TimeBlockControllerDocs {

@Operation(
summary = "타임 블록 생성",
description = "타임 블록을 생성한다.",
responses = {
@ApiResponse(
responseCode = "201",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@ApiResponse(
responseCode = "400",
description = "타입 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "403",
description = "접근 권한 없음",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "404",
description = "팀에 존재하지 않는 회원",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "404",
description = "유효하지 않은 팀",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<TimeBlockCreationResponse>> createTimeBlock(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
)
@PathVariable long teamId,
@Parameter(
name = "type",
description = "타임라인 타입",
in = ParameterIn.QUERY,
example = "executive, member"
) @RequestParam String type,
@RequestBody TimeBlockCreationRequest request
);
}

0 comments on commit c0c7a74

Please sign in to comment.