Skip to content

Commit

Permalink
docs: RestDocumentation ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
  • Loading branch information
begaonnuri committed Aug 13, 2020
1 parent e30d696 commit 0ea7b47
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 12 deletions.
49 changes: 49 additions & 0 deletions back/src/docs/api-docs.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ifndef::snippets[]
:snippets: ../../../build/generated-snippets
endif::[]
:toc: preamble
:toc-title: ๋ชฉ์ฐจ
:toclevels: 2
:doctitle: ์…€๋Ÿฌ๋ฆฌ API
:author: ํ„ฐํ‹€
:email: begaonnuri@gmail.com

Doc Writer <{author} : {email}>

[[resources-member]]
== ํšŒ์› ๊ด€๋ฆฌ

=== ํšŒ์› ๋กœ๊ทธ์ธ

operation::login[snippets='http-request,http-response,request-fields,request-body']

=== ํšŒ์› ๋กœ๊ทธ์ธ ์‹คํŒจ

==== ์ด๋ฉ”์ผ

operation::login/advice/email[snippets='http-request,http-response,request-fields,request-body,response-body']

==== ๋น„๋ฐ€๋ฒˆํ˜ธ

operation::login/advice/password[snippets='http-request,http-response,request-fields,request-body,response-body']

[[resources-articles]]
== ๊ฒŒ์‹œ๊ธ€ ๊ด€๋ฆฌ

=== ๊ฒŒ์‹œ๊ธ€ ํŽ˜์ด์ง€ ์กฐํšŒ

operation::articles/getPage[snippets='http-request,http-response,request-parameters,response-body']

=== ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ธ ์กฐํšŒ

operation::articles/get[snippets='http-request,http-response,path-parameters,request-parameters,response-body']

=== ๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ

operation::articles/post[snippets='http-request,http-response,request-body,response-headers']

== ์ฑ„ํŒ…๋ฐฉ ๊ด€๋ฆฌ

=== ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ

operation::chat-rooms/post[snippets='http-request,http-response,request-fields,request-body,response-headers']
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ void createArticle() throws Exception {
.description("๊ฒŒ์‹œ๊ธ€์˜ ์ œ๋ชฉ"),
fieldWithPath("category").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ์นดํ…Œ๊ณ ๋ฆฌ"),
fieldWithPath("contents").type(JsonFieldType.NUMBER)
fieldWithPath("contents").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๋‚ด์šฉ"),
fieldWithPath("price").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฐ€๊ฒฉ"),
fieldWithPath("tradeState").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ํŒ๋งค ์ƒํƒœ"),
// fieldWithPath("tradeState").type(JsonFieldType.STRING)
// .description("๊ฒŒ์‹œ๊ธ€์˜ ํŒ๋งค ์ƒํƒœ"),
fieldWithPath("tradeType").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฑฐ๋ž˜ ์œ ํ˜•"),
fieldWithPath("tradeLocation").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฑฐ๋ž˜ ์ง€์—ญ"),
fieldWithPath("tags").type(JsonFieldType.ARRAY)
.description("ํƒœ๊ทธ์˜ ๋ฆฌ์ŠคํŠธ"),
fieldWithPath("photos").type(JsonFieldType.ARRAY)
Expand Down Expand Up @@ -120,6 +124,18 @@ void showPage() throws Exception {
requestParameters(
parameterWithName("lastArticleId").description("๋งˆ์ง€๋ง‰ ๊ฒŒ์‹œ๊ธ€์˜ ID"),
parameterWithName("size").description("๊ฐ€์ ธ์˜ฌ ํŽ˜์ด์ง€์˜ ํฌ๊ธฐ(๊ฒŒ์‹œ๋ฌผ ์ˆ˜)")
),
responseFields(
fieldWithPath("[].id").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ID"),
fieldWithPath("[].price").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฐ€๊ฒฉ"),
fieldWithPath("[].favoriteCount").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ์ฐœ ๊ฐœ์ˆ˜"),
fieldWithPath("[].tags").type(JsonFieldType.ARRAY)
.description("ํƒœ๊ทธ์˜ ๋ฆฌ์ŠคํŠธ"),
fieldWithPath("[].photos").type(JsonFieldType.ARRAY)
.description("์‚ฌ์ง„์˜ ๋ฆฌ์ŠคํŠธ")
)
));
}
Expand All @@ -132,11 +148,14 @@ void showArticle() throws Exception {

// URI Path variable์„ ๊ฐ€์ ธ์™€์•ผ ํ•ด์„œ RestDocumentationRequestBuilders.get()์„ ์‚ฌ์šฉํ–ˆ์Œ
mockMvc.perform(
RestDocumentationRequestBuilders.get(ARTICLE_URI + "/{id}", ARTICLE1.getId())
RestDocumentationRequestBuilders
.get(ARTICLE_URI + "/{id}", ARTICLE1.getId())
.param("memberId", String.valueOf(MEMBER1.getId())))
.andDo(print())
.andExpect(status().isOk())
.andDo(document("articles/get",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
// requestHeaders(
// headerWithName("Authorization").description("ํšŒ์›์˜ ํ† ํฐ")
// ),
Expand All @@ -145,6 +164,38 @@ void showArticle() throws Exception {
),
pathParameters(
parameterWithName("id").description("๊ฒŒ์‹œ๊ธ€์˜ ID")
),
responseFields(
fieldWithPath("id").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ID"),
fieldWithPath("title").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ์ œ๋ชฉ"),
fieldWithPath("category").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ์นดํ…Œ๊ณ ๋ฆฌ"),
fieldWithPath("contents").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๋‚ด์šฉ"),
fieldWithPath("price").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฐ€๊ฒฉ"),
fieldWithPath("tradeType").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฑฐ๋ž˜ ์œ ํ˜•"),
fieldWithPath("tradeLocation").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ๊ฑฐ๋ž˜ ์ง€์—ญ"),
fieldWithPath("tradeState").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€์˜ ํŒ๋งค ์ƒํƒœ"),
fieldWithPath("photos").type(JsonFieldType.ARRAY)
.description("์‚ฌ์ง„์˜ ๋ฆฌ์ŠคํŠธ"),
fieldWithPath("author.avatar").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ์ž์˜ ํ”„๋กœํ•„ ์‚ฌ์ง„"),
fieldWithPath("author.nickname").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ์ž์˜ ๋‹‰๋„ค์ž„"),
fieldWithPath("author.score").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ์ž์˜ ์ ์ˆ˜"),
fieldWithPath("favoriteState").type(JsonFieldType.BOOLEAN)
.description("์ž‘์„ฑ์ž์˜ ๊ฒŒ์‹œ๊ธ€ ์ฐœ ์—ฌ๋ถ€"),
fieldWithPath("favoriteCount").type(JsonFieldType.NUMBER)
.description("๊ฒŒ์‹œ๊ธ€์˜ ์ฐœ ๊ฐœ์ˆ˜"),
fieldWithPath("createdTime").type(JsonFieldType.STRING)
.description("๊ฒŒ์‹œ๊ธ€ ์ƒ์„ฑ ์‹œ๊ฐ„")
)
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @author kouz95
*/

package sellerlee.back.chatroom.presentation;

import static org.mockito.ArgumentMatchers.*;
Expand Down Expand Up @@ -75,6 +71,7 @@ void createChatRoom() throws Exception {
.andExpect(status().isCreated())
.andDo(document("chat-rooms/post",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
// requestHeaders(
// headerWithName("Authorization").description("ํšŒ์›์˜ ํ† ํฐ")
// ),
Expand All @@ -101,6 +98,7 @@ void showChatRoomOfArticle() throws Exception {
.param("articleId", "1"))
.andExpect(status().isOk())
.andDo(document("chat-rooms/",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
// requestHeaders(
// headerWithName("Authorization").description("ํšŒ์›์˜ ํ† ํฐ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
Expand Down Expand Up @@ -64,6 +65,8 @@ void handleIllegalMemberLoginException_InvalidEmail() throws Exception {
.andDo(print())
.andExpect(status().isBadRequest())
.andDo(document("login/advice/email",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("email").type(JsonFieldType.STRING)
.description("์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ด๋ฉ”์ผ"),
Expand All @@ -88,6 +91,8 @@ void handleIllegalMemberLoginException_InvalidPassword() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(document("login/advice/password",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("email").description("์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ด๋ฉ”์ผ"),
fieldWithPath("password").description("์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/**
* @author lxxjn0
*/

package sellerlee.back.member.presentation;

import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
Expand Down Expand Up @@ -61,6 +58,8 @@ void login() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("login",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("email").description("์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ด๋ฉ”์ผ"),
fieldWithPath("password").description("์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ")
Expand Down

0 comments on commit 0ea7b47

Please sign in to comment.