Skip to content

Commit

Permalink
Merge pull request #142 from c0smosaur/dev
Browse files Browse the repository at this point in the history
[DOC] #141 Swagger 추가
  • Loading branch information
c0smosaur authored Jun 17, 2024
2 parents fa20114 + 3b31414 commit 1098200
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -17,6 +18,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/club")
@Tag(name = "Club", description = "소모임 관련 API")
public class ClubController {

private final ClubService clubService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -23,6 +24,7 @@
@RestController
@RequestMapping("/api/v1/club")
@RequiredArgsConstructor
@Tag(name = "Club - Member", description = "소모임 인원 관리 관련 API")
public class ClubMemberController {

private final ClubMemberService clubMemberService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -15,6 +16,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/club")
@Tag(name = "Club", description = "소모임 정모 관련 API")
public class ClubMeetingController {

private final ClubMeetingService clubMeetingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -15,6 +16,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/club")
@Tag(name = "Club - Comment", description = "소모임 댓글 관련 API")
public class ClubCommentController {

private final ClubCommentService clubCommentService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -16,6 +17,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/club")
@Tag(name = "Club - Notice", description = "소모임 게시글/공지사항 관련 API")
public class ClubNoticeController {

private final ClubNoticeService clubNoticeService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/api/v1/category/*",

//소모임 - 비로그인 범위
"/api/v1/club/search").permitAll()
"/api/v1/club/search",

// Swagger UI
"/v3/api-docs/**",
"/swagger-ui/**",
"/swagger-ui.html").permitAll()

.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/com/core/linkup/common/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.core.linkup.common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SwaggerConfig {
private static final String SECURITY_SCHEME_NAME = "Authorization";
private static final String SECURITY_SCHEME_REFRESH_NAME = "refresh-token";

@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
return new ModelResolver(objectMapper);
}

@Bean
public OpenAPI swaggerApi(){
return new OpenAPI()
.components(new Components()
.addSecuritySchemes(SECURITY_SCHEME_NAME, new SecurityScheme()
.name(SECURITY_SCHEME_NAME)
.type(SecurityScheme.Type.HTTP)
.scheme("Bearer")
.bearerFormat("JWT"))
.addSecuritySchemes(SECURITY_SCHEME_REFRESH_NAME, new SecurityScheme()
.name(SECURITY_SCHEME_REFRESH_NAME)
.type(SecurityScheme.Type.HTTP)
.in(SecurityScheme.In.HEADER)
.scheme("Bearer")
.bearerFormat("JWT"))
)
.addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME))
.info(new Info()
.title("패스트캠퍼스 기업연계 프로젝트-3조 LinkUp 백엔드")
.description("공유오피스 서비스 프로젝트"))
.servers(List.of(
new Server().url("https://api.linkup3mw.com")))
.path("/api/v1/member/logout", new PathItem()
.get(new Operation()
.operationId("logout")
.description("Log out the current user")
.addTagsItem("Authentication")
.addParametersItem(new Parameter()
.in("header")
.name("Logout")
.description("Bearer token")
.required(true)
.schema(new StringSchema().format("string"))
.example("Bearer <token>"))
.responses(new ApiResponses()
.addApiResponse("200", new ApiResponse()
.description("Logout successful"))
.addApiResponse("401", new ApiResponse()
.description("Unauthorized")))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.core.linkup.common.entity.enums.IndustryType;
import com.core.linkup.common.entity.enums.OccupationType;
import com.core.linkup.common.response.BaseResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -19,6 +20,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/category")
@Tag(name = "Category", description = "프론트 필터링에 필요한 카테고리 제공 API")
public class CategoryController {

@GetMapping("/city")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.core.linkup.member.service.MemberService;
import com.core.linkup.member.service.ValidationService;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,6 +24,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/member")
@Tag(name = "Authentication", description = "인증/인가 관련 API")
public class MemberController {

private final MemberService memberService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.core.linkup.office.response.OfficeResponse;
import com.core.linkup.office.response.OfficeSearchResponse;
import com.core.linkup.office.service.OfficeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -16,6 +17,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/office")
@Tag(name = "Search", description = "지점 탐색 관련 API")
public class OfficeController {

private final OfficeService officeService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.core.linkup.reservation.reservation.response.ReservationResponse;
import com.core.linkup.reservation.reservation.service.CompanyMembershipReservationService;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -19,7 +20,7 @@
@Slf4j
@RestController
@RequestMapping("/api/v1/reservation/company")
@RequiredArgsConstructor
@RequiredArgsConstructor@Tag(name = "Reservation - Company", description = "기업 멤버십 예약 관련 API")
public class CompanyMembershipReservationController {

private final CompanyMembershipReservationService companyMembershipReservationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.core.linkup.reservation.reservation.response.*;
import com.core.linkup.reservation.reservation.service.IndividualMembershipReservationService;
import com.core.linkup.security.MemberDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -18,6 +19,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/reservation/individual")
@Tag(name = "Reservation - Individual", description = "개인 멤버십 예약 관련 API")
public class IndividualMembershipReservationController {

private final IndividualMembershipReservationService individualMembershipReservationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.core.linkup.reservation.reservation.service.ReservationService;
import com.core.linkup.security.MemberDetails;
import com.querydsl.core.Tuple;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -21,6 +22,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/reservation")
@Tag(name = "Reservation", description = "예약 관련 API")
public class ReservationController {

private final MembershipReservationService membershipReservationService;
Expand Down

0 comments on commit 1098200

Please sign in to comment.