Skip to content

Commit

Permalink
Merge pull request #197 from techeer-sv/BE/#196
Browse files Browse the repository at this point in the history
BE/#196 Spring REST Docs 세팅
  • Loading branch information
youKeon authored Sep 6, 2023
2 parents 84078bf + 9b0b3dd commit 18033d5
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ logs/
logs/

backend/src/main/resources/application-local.yml

backend/src/main/resources/static/docs/
45 changes: 26 additions & 19 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,52 @@ dependencies {
}

tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
finalizedBy 'jacocoTestReport'
}


// ====================================== rest-docs ======================================
// =================== rest docs =================== //
ext {
snippetsDir = file('build/generated-snippets')
set('snippetsDir', file("build/generated-snippets"))
}

tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
finalizedBy 'jacocoTestReport'
}

asciidoctor {
configurations 'asciidoctorExtensions'
inputs.dir snippetsDir

dependsOn test
}

task copyDocument(type: Copy) {
asciidoctor.doFirst {
delete file('src/main/resources/static')
}

task createDocument(type: Copy) {
dependsOn asciidoctor

from file("build/docs/asciidoc")
into file("build/resources/main/static/docs")
into file("src/main/resources/static")
}

bootJar {
// duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
dependsOn copyDocument
dependsOn createDocument
from("${asciidoctor.outputDir}") {
into "static"
}
}
//
//jar {
// dependsOn bootJar
//}
//
//bootJarMainClassName {
// dependsOn copyDocument
//}

jar {
enabled = false
}

// ====================================== sonarqube ======================================
// =================== sonar qube =================== //
jacoco {
toolVersion = "0.8.7"
}
Expand All @@ -151,8 +159,7 @@ jacocoTestReport {
"**/*Application*",
"**/mapper/**",
"**/global/**",
"**/com/graphy/backend/domain/job/domain/**",
"**/com/graphy/backend/domain/job/service/**"
"**/job/**",
])
}))
}
Expand Down Expand Up @@ -191,7 +198,7 @@ sonarqube {
tasks.sonarqube.dependsOn test


// ====================================== querydsl ======================================
// =================== query dsl =================== //
def querydslDir = "$buildDir/generated/querydsl"

querydsl {
Expand Down
36 changes: 36 additions & 0 deletions backend/src/docs/asciidoc/auth.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ifndef::snippets[]
:snippets: ./build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 4

= Auth API

== 회원가입
=== 성공
operation::auth/signUp/success[snippets='request-fields,http-request,http-response']

=== 실패 : 이메일 형식 오류
operation::auth/signUp/fail/invalidEmail[snippets='http-request,http-response']

=== 실패 : 이메일 공백 오류
operation::auth/signUp/fail/emptyEmail[snippets='http-request,http-response']

=== 실패 : 비밀번호 공백 오류
operation::auth/signUp/fail/emptyPassword[snippets='http-request,http-response']

== 로그인
=== 성공
operation::auth/signIn/success[snippets='request-fields,http-request,http-response']

=== 실패 : 이메일 형식 오류
operation::auth/signIn/fail/invalidEmail[snippets='http-request,http-response']

=== 실패 : 이메일 공백 오류
operation::auth/signIn/fail/emptyEmail[snippets='http-request,http-response']

=== 실패 : 비밀번호 공백 오류
operation::auth/signIn/fail/emptyPassword[snippets='http-request,http-response']
37 changes: 37 additions & 0 deletions backend/src/docs/asciidoc/comment.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ifndef::snippets[]
:snippets: ./build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 4

= Comment API

== 댓글 저장
=== 성공
operation::comment/add/success[snippets='request-fields,http-request,http-response']

=== 실패 : content(내용) 공백 오류
operation::comment/add/fail/emptyContent[snippets='request-fields,http-request,http-response']

=== 실패 : ProjectId(프로젝트 ID) 공백 오류
operation::comment/add/fail/emptyProjectId[snippets='request-fields,http-request,http-response']

== 댓글 삭제
=== 성공
operation::comment/remove/success[snippets='path-parameters,http-request,http-response']

== 댓글 수정
=== 성공
operation::comment/modify/success[snippets='path-parameters,request-fields,http-request,http-response']

=== 실패 : content(내용) 공백 오류
operation::comment/modify/fail/emptyContent[snippets='request-fields,http-request,http-response']


== 답글 조회
=== 성공
operation::comment/reComment/findAll/success[snippets='path-parameters,http-request,http-response']

Empty file.
28 changes: 11 additions & 17 deletions backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
= Graphy API 문서
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 1

= Comment

== 삭제
=== Request
include::{snippets}/comment-delete/http-request.adoc[]

=== Response
include::{snippets}/comment-delete/http-response.adoc[]


= Graphy API Docs
:nofooter:

[width="70%"]
|===
|link:member.html[[.big]#Member API#]
|link:auth.html[[.big]#Auth API#]
|link:problem.html[[.big]#Project API#]
|link:comment.html[[.big]#Comment API#]
|link:follow.html[[.big]#Follow API#]
|===
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.time.Duration;

@Configuration
@PropertySource("classpath:application-local.yml")
@PropertySource("classpath:application-docker.yml")
public class ChatGPTConfig {

@Value("${gpt.token}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.graphy.backend;

import com.graphy.backend.test.config.TestProfile;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles(TestProfile.TEST)
class BackendApplicationTests {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import javax.servlet.http.HttpServletRequest;

import static com.graphy.backend.test.config.ApiDocumentUtil.getDocumentRequest;
import static com.graphy.backend.test.config.ApiDocumentUtil.getDocumentResponse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
Expand Down Expand Up @@ -74,6 +76,8 @@ public void signUpTest() throws Exception {

.andDo(print())
.andDo(document("auth/signUp/success",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
Expand Down Expand Up @@ -105,6 +109,8 @@ public void signUpWithEmptyEmailExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signUp/fail/emptyEmail",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
Expand Down Expand Up @@ -140,6 +146,8 @@ public void signUpWithInvalidEmailFormatExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signUp/fail/invalidEmail",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
Expand Down Expand Up @@ -175,6 +183,8 @@ public void signUpWithEmptyNicknameExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signUp/fail/emptyNickname",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
Expand Down Expand Up @@ -210,6 +220,8 @@ public void signUpWithEmptyPasswordExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signUp/fail/emptyPassword",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
Expand Down Expand Up @@ -260,6 +272,8 @@ public void signInTest() throws Exception {

.andDo(print())
.andDo(document("auth/signIn/success",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호")
Expand Down Expand Up @@ -292,6 +306,8 @@ public void signInWithEmptyEmailExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signIn/fail/emptyEmail",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호")
Expand Down Expand Up @@ -324,6 +340,8 @@ public void signInWithInvalidEmailFormatExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signIn/fail/invalidEmail",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호")
Expand Down Expand Up @@ -356,6 +374,8 @@ public void signInWithEmptyPasswordExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/signIn/fail/emptyPassword",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호")
Expand Down Expand Up @@ -391,6 +411,8 @@ public void logoutTest() throws Exception {

.andDo(print())
.andDo(document("auth/logout/success",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("accessToken").description("액세스 토큰"),
fieldWithPath("refreshToken").description("리프래시 토큰")
Expand Down Expand Up @@ -421,6 +443,8 @@ public void logoutEmptyAccessTokenExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/logout/fail/emptyAccessToken",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("accessToken").description("액세스 토큰"),
fieldWithPath("refreshToken").description("리프래시 토큰")
Expand Down Expand Up @@ -455,6 +479,8 @@ public void logoutEmptyRefreshTokenExceptionTest() throws Exception {
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("auth/logout/fail/emptyRefreshToken",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
fieldWithPath("accessToken").description("액세스 토큰"),
fieldWithPath("refreshToken").description("리프래시 토큰")
Expand Down Expand Up @@ -491,6 +517,8 @@ public void reIssueTest() throws Exception {

.andDo(print())
.andDo(document("auth/reissue/success",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("code").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
Expand Down
Loading

0 comments on commit 18033d5

Please sign in to comment.