-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Rest Docs 적용 #73
Merged
linglong67
merged 7 commits into
Kernel360:develop
from
linglong67:feature/rest-doc-setting
Jan 19, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d1b5b10
feat: Rest Docs 관련 설정
linglong67 8105efb
feat: Rest Docs 샘플 코드 작성 (java)
linglong67 8ec970a
feat: Rest Docs - adoc 파일 추가
linglong67 bf891da
chore: Rest Docs 샘플 - 추후 삭제 예정인 부분들 표기
linglong67 3ff0a61
chore: .gitignore 내용 추가
linglong67 b1da48e
chore: .gitignore 내용 추가 (수정..)
linglong67 af72ded
style: 삭제 예정 관련 주석 -> FIXME 키워드 사용
linglong67 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
= API Document | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 2 | ||
:sectlinks: | ||
|
||
include::overview.adoc[] | ||
include::sample-api.adoc[] | ||
// !!! 위 라인 1줄은 추후 삭제 예정입니다 !!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[overview]] | ||
== Overview | ||
|
||
[[overview-host]] | ||
=== Domain | ||
|
||
[cols="3,7"] | ||
|=== | ||
| 환경 | Domain | ||
| 개발 서버 | ||
| `http://washpedia.my-project.life` | ||
| 운영 서버 | ||
| | ||
|=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// !!! 삭제 예정 파일입니다 !!! | ||
== 샘플 API | ||
|
||
// [[]] 안에는 a 태그 이름 들어갑니다 (http://localhost:8080/docs/index#공통코드-조회) | ||
[[공통코드-조회]] | ||
=== 공통코드 조회 | ||
|
||
// [Request] 실제로 API 에서 필요한 내용들만 아래 내용을 추가합니다 | ||
==== Request | ||
include::{snippets}/commoncode/get-common-codes/path-parameters.adoc[] | ||
// include::{snippets}/commoncode/get-common-codes/query-parameters.adoc[] | ||
// include::{snippets}/commoncode/get-common-codes/request-fields.adoc[] | ||
|
||
===== HTTP Request 예시 | ||
include::{snippets}/commoncode/get-common-codes/http-request.adoc[] | ||
|
||
// [Response] 실제로 API 에서 필요한 내용들만 아래 내용을 추가합니다 | ||
==== Response | ||
// include::{snippets}/commoncode/get-common-codes/response-fields.adoc[] | ||
include::{snippets}/commoncode/get-common-codes/response-fields-value.adoc[] | ||
|
||
===== HTTP Response 예시 | ||
include::{snippets}/commoncode/get-common-codes/http-response.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
module-api/src/test/java/com/kernel360/common/ControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.kernel360.common; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.kernel360.commoncode.controller.CommonCodeController; | ||
import com.kernel360.commoncode.service.CommonCodeService; | ||
import com.kernel360.member.controller.MemberController; | ||
import com.kernel360.member.service.MemberService; | ||
import com.kernel360.product.controller.ProductController; | ||
import com.kernel360.product.service.ProductService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest({ | ||
CommonCodeController.class, | ||
MemberController.class, | ||
ProductController.class | ||
}) | ||
@AutoConfigureRestDocs | ||
public abstract class ControllerTest { | ||
|
||
@Autowired | ||
protected MockMvc mockMvc; | ||
|
||
@Autowired | ||
protected ObjectMapper objectMapper; | ||
|
||
@MockBean | ||
protected CommonCodeService commonCodeService; | ||
|
||
@MockBean | ||
protected MemberService memberService; | ||
|
||
@MockBean | ||
protected ProductService productService; | ||
} |
19 changes: 19 additions & 0 deletions
19
module-api/src/test/java/com/kernel360/common/utils/RestDocumentUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.kernel360.common.utils; | ||
|
||
import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor; | ||
import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor; | ||
|
||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
|
||
public interface RestDocumentUtils { | ||
|
||
static OperationRequestPreprocessor getDocumentRequest() { | ||
return preprocessRequest(modifyUris().scheme("http") | ||
.host("washpedia.my-project.life") | ||
.removePort(), prettyPrint()); | ||
} | ||
|
||
static OperationResponsePreprocessor getDocumentResponse() { | ||
return preprocessResponse(prettyPrint()); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...i/src/test/java/com/kernel360/commoncode/controller/CommonCodeControllerRestDocsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.kernel360.commoncode.controller; | ||
|
||
import com.kernel360.common.ControllerTest; | ||
import com.kernel360.commoncode.dto.CommonCodeDto; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.restdocs.payload.JsonFieldType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.kernel360.common.utils.RestDocumentUtils.getDocumentRequest; | ||
import static com.kernel360.common.utils.RestDocumentUtils.getDocumentResponse; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
import static org.springframework.restdocs.request.RequestDocumentation.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
// !!! 삭제 예정 파일입니다 !!! | ||
class CommonCodeControllerRestDocsTest extends ControllerTest { | ||
|
||
@Test | ||
void commmonCodeSearch() throws Exception { | ||
//given | ||
List<CommonCodeDto> responseList = Arrays.asList( | ||
CommonCodeDto.of( | ||
11L, | ||
"Sedan", | ||
10, | ||
"cartype", | ||
1, | ||
true, | ||
"세단", | ||
LocalDate.now(), | ||
"admin", | ||
null, | ||
null), | ||
CommonCodeDto.of( | ||
12L, | ||
"Hatchback", | ||
10, | ||
"cartype", | ||
2, | ||
true, | ||
"해치백", | ||
LocalDate.now(), | ||
"admin", | ||
null, | ||
null) | ||
); | ||
|
||
String pathVariable = "color"; | ||
given(commonCodeService.getCodes(pathVariable)).willReturn(responseList); | ||
|
||
|
||
//when | ||
ResultActions result = this.mockMvc.perform( | ||
get("/commoncode/test/{codeName}", pathVariable)); | ||
|
||
|
||
//then | ||
//pathParameters, pathParameters, requestFields, responseFields는 필요 시 각각 작성 | ||
result.andExpect(status().isOk()) | ||
.andDo(document( | ||
"commoncode/get-common-codes", | ||
getDocumentRequest(), | ||
getDocumentResponse(), | ||
pathParameters( | ||
parameterWithName("codeName").description("코드명") | ||
), | ||
// pathParameters( | ||
// parameterWithName("size").description("size").optional(), | ||
// parameterWithName("page").description("page").optional() | ||
// ), | ||
// requestFields( | ||
// fieldWithPath("codeName").type(JsonFieldType.STRING).description("코드명"), | ||
// fieldWithPath("upperName").type(JsonFieldType.STRING).description("상위 코드명").optional() | ||
// ), | ||
// responseFields( | ||
// fieldWithPath("codeNo").type(JsonFieldType.NUMBER).description("코드번호"), | ||
// ) | ||
responseFields(beneathPath("value").withSubsectionId("value"), | ||
fieldWithPath("codeNo").type(JsonFieldType.NUMBER).description("코드번호"), | ||
fieldWithPath("codeName").type(JsonFieldType.STRING).description("코드명"), | ||
fieldWithPath("upperNo").type(JsonFieldType.NUMBER).description("상위 코드번호").optional(), | ||
fieldWithPath("upperName").type(JsonFieldType.STRING).description("상위 코드명").optional(), | ||
fieldWithPath("sortOrder").type(JsonFieldType.NUMBER).description("정렬순서"), | ||
fieldWithPath("isUsed").type(JsonFieldType.BOOLEAN).description("사용여부"), | ||
fieldWithPath("description").type(JsonFieldType.STRING).description("설명"), | ||
fieldWithPath("createdAt").type(JsonFieldType.STRING).description("생성일시"), | ||
fieldWithPath("createdBy").type(JsonFieldType.STRING).description("생성자"), | ||
fieldWithPath("modifiedAt").type(JsonFieldType.STRING).description("수정일시").optional(), | ||
fieldWithPath("modifiedBy").type(JsonFieldType.STRING).description("수정자").optional() | ||
) | ||
)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
module-api/src/test/resources/org/springframework/restdocs/templates/path-parameters.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
===== End Point | ||
{{path}} | ||
|
||
===== Path Parameters | ||
|=== | ||
|
||
|파라미터|설명 | ||
|
||
{{#parameters}} | ||
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
{{/parameters}} | ||
|
||
|=== |
12 changes: 12 additions & 0 deletions
12
...le-api/src/test/resources/org/springframework/restdocs/templates/query-parameters.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
===== Query Parameters | ||
|=== | ||
|
||
|파라미터|필수값|설명 | ||
|
||
{{#parameters}} | ||
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{^optional}}true{{/optional}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
{{/parameters}} | ||
|
||
|=== |
13 changes: 13 additions & 0 deletions
13
module-api/src/test/resources/org/springframework/restdocs/templates/request-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
===== Request Fields | ||
|=== | ||
|
||
|필드명|타입|필수값|설명 | ||
|
||
{{#fields}} | ||
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{^optional}}true{{/optional}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
{{/fields}} | ||
|
||
|=== |
12 changes: 12 additions & 0 deletions
12
module-api/src/test/resources/org/springframework/restdocs/templates/response-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
===== Response Fields | ||
|=== | ||
|
||
|필드명|타입|설명 | ||
|
||
{{#fields}} | ||
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
{{/fields}} | ||
|
||
|=== |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some findings and suggestions for the code patch:
Dependency Upgrade: Consider upgrading the dependencies to their latest versions, as newer versions often include bug fixes and improvements.
Configuration Block: Move the
ext
block inside thejava
block for better organization.Output Directory: Add the output directory for Asciidoctor generated snippets (
snippetsDir
) as an input for theasciidoctor
task to track changes properly.Configuration Name: Change
asciidoctorExt
to a more descriptive name, likerestdocsAsciidoctor
, as it is used for Spring REST Docs.Ensure Clean Slate: Delete the existing
src/main/resources/static/docs
directory before generating new documentation to avoid any stale files remaining.Documentation Copy: Create a task named
copyDocument
that depends on theasciidoctor
task. This task copies the generated AsciiDoc files frombuild/docs/asciidoc
tosrc/main/resources/static/docs
.Jar Creation: Configure the
bootJar
task to depend on thecopyDocument
task so that the generated documentation is included in the final JAR file.Overall, these changes improve the build process and ensure that the latest documentation is included in the application's distribution.