Spring REST Docs
Swagger์์ ์ฐจ์ด์
์ฌ์ฉ๋ฒ
๋ฉ์๋
this.mockMvc.perform(post("/api/events") .contentType(MediaType.APPLICATION_JSON) .accept(MediaTypes.HAL_JSON) .content(this.objectMapper.writeValueAsString(event))) .andDo(print()) .andExpect(status().isCreated()) .andExpect(jsonPath("id").exists()) .andExpect(header().exists(HttpHeaders.LOCATION)) .andExpect(header().string(HttpHeaders.CONTENT_TYPE,"application/hal+json;charset=UTF-8")) .andExpect(jsonPath("free").value(false)) .andExpect(jsonPath("offline").value(true)) .andExpect(jsonPath("eventStatus").value(EventStatus.DRAFT.name())) .andExpect(jsonPath("_links.self").exists()) .andExpect(jsonPath("_links.query-events").exists()) .andExpect(jsonPath("_links.update-event").exists()) .andDo(document("create-event", links( linkWithRel("self").description("link to self"), linkWithRel("query-events").description("link to query-events"), linkWithRel("update-event").description("link to update-event") ), requestHeaders( headerWithName(HttpHeaders.ACCEPT).description("accept header"), headerWithName(HttpHeaders.CONTENT_TYPE).description("content type header") ), requestFields( fieldWithPath("name").description("Name of Event"), fieldWithPath("description").description("Description of Event"), fieldWithPath("beginEnrollmentDateTime").description("๋ฑ๋ก์์๊ธฐ๊ฐ of Event"), fieldWithPath("closeEnrollmentDateTime").description("๋ฑ๋ก๋ง๊ฐ๊ธฐ๊ฐ of Event"), fieldWithPath("beginEventDateTime").description("์์๊ธฐ๊ฐ of Event"), fieldWithPath("endEventDateTime").description("์ข ๋ฃ๊ธฐ๊ฐ of Event"), fieldWithPath("location").description("location of Event"), fieldWithPath("basePrice").description("BasePrice of Event"), fieldWithPath("maxPrice").description("MaxPrice of Event"), fieldWithPath("limitOfEnrollment").description("๋ฑ๋ก ์ ํ of Event") ) ,responseHeaders( headerWithName(HttpHeaders.LOCATION).description("location header"), headerWithName(HttpHeaders.CONTENT_TYPE).description("content type header") ), responseFields( fieldWithPath("id").description("identifier of Event"), fieldWithPath("name").description("Name of Event"), fieldWithPath("description").description("Description of Event"), fieldWithPath("beginEnrollmentDateTime").description("๋ฑ๋ก์์๊ธฐ๊ฐ of Event"), fieldWithPath("closeEnrollmentDateTime").description("๋ฑ๋ก๋ง๊ฐ๊ธฐ๊ฐ of Event"), fieldWithPath("beginEventDateTime").description("์์๊ธฐ๊ฐ of Event"), fieldWithPath("endEventDateTime").description("์ข ๋ฃ๊ธฐ๊ฐ of Event"), fieldWithPath("location").description("location of Event"), fieldWithPath("basePrice").description("BasePrice of Event"), fieldWithPath("maxPrice").description("MaxPrice of Event"), fieldWithPath("limitOfEnrollment").description("๋ฑ๋ก ์ ํ of Event"), fieldWithPath("offline").description("์คํ๋ผ์ธ์ธ์ง of Event"), fieldWithPath("free").description("๋ฌด๋ฃ์ธ์ง of Event"), fieldWithPath("eventStatus").description("eventStatus of Event"), fieldWithPath("_links.self.href").description("link to self"), fieldWithPath("_links.query-events.href").description("link to query-events"), fieldWithPath("_links.update-event.href").description("link to update-event") ) ));
configurer.operationPreprocessors().withRequestDefaults(prettyPrint()).withResponseDefaults(prettyPrint());
Customize
build
Reference
Last updated