Skip to content

Commit

Permalink
Fix(Web): 정적 리소스 핸들러 추가(#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoosungKwon authored Aug 4, 2023
2 parents 4b7d806 + 5d46836 commit 5e0ee3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.clover.habbittracker.domain.emoji.entity.Emoji;
Expand All @@ -19,6 +20,12 @@ public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new Emoji.Type.StringToEmojiTypeConverter());
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/docs/**")
.addResourceLocations("classpath:/static/");
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.clover.habbittracker.global.restdocs.enums.EnumResponse;

@RestController
@RequestMapping("/docs")
@RequestMapping("/test/docs")
public class CommonDocController {

@GetMapping("/enums")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@

public class EnumDocumentation extends RestDocsSupport {

// 커스텀 템플릿 사용을 위한 함수
public static CustomResponseFieldsSnippet customResponseFields
(String type,
PayloadSubsectionExtractor<?> subsectionExtractor,
Map<String, Object> attributes, FieldDescriptor... descriptors) {
return new CustomResponseFieldsSnippet(type, subsectionExtractor, Arrays.asList(descriptors), attributes
, true);
}

// Map으로 넘어온 enumValue를 fieldWithPath로 변경하여 리턴
private static FieldDescriptor[] enumConvertFieldDescriptor(Map<String, String> enumValues) {
return enumValues.entrySet().stream()
.map(x -> fieldWithPath(x.getKey()).description(x.getValue()))
.toArray(FieldDescriptor[]::new);
}

@Test
public void enums() throws Exception {
ResultActions result = this.mockMvc.perform(
get("/docs/enums")
get("/test/docs/enums")
.contentType(MediaType.APPLICATION_JSON)
);

Expand Down Expand Up @@ -54,22 +70,6 @@ public void enums() throws Exception {
));
}

// 커스텀 템플릿 사용을 위한 함수
public static CustomResponseFieldsSnippet customResponseFields
(String type,
PayloadSubsectionExtractor<?> subsectionExtractor,
Map<String, Object> attributes, FieldDescriptor... descriptors) {
return new CustomResponseFieldsSnippet(type, subsectionExtractor, Arrays.asList(descriptors), attributes
, true);
}

// Map으로 넘어온 enumValue를 fieldWithPath로 변경하여 리턴
private static FieldDescriptor[] enumConvertFieldDescriptor(Map<String, String> enumValues) {
return enumValues.entrySet().stream()
.map(x -> fieldWithPath(x.getKey()).description(x.getValue()))
.toArray(FieldDescriptor[]::new);
}

// mvc result 데이터 파싱
private EnumDocs getData(MvcResult result) throws IOException {
EnumResponse<EnumDocs> enumResponse = objectMapper
Expand Down

0 comments on commit 5e0ee3c

Please sign in to comment.