-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from linglong67/feature/rest-doc-setting
[feat] Rest Docs 적용
- Loading branch information
Showing
13 changed files
with
311 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,5 +39,8 @@ out/ | |
### MAC ### | ||
.DS_Store | ||
|
||
### rest docs ### | ||
!**/src/main/**/static/docs | ||
|
||
### log ### | ||
*.log |
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[] | ||
// FIXME :: 위 라인 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 @@ | ||
// FIXME :: 삭제 예정 파일입니다 | ||
== 샘플 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; | ||
|
||
// FIXME :: 삭제 예정 파일입니다 | ||
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("코드명") | ||
), | ||
// queryParameters( | ||
// 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}} | ||
|
||
|=== |
Oops, something went wrong.