본문 바로가기

웹 개발/Spring

[Spring] Spring REST Docs 호스트 변경

Spring REST Docs를 사용하다 보면, 위 사진처럼 default로 되어 있는 호스트(localhost)와 포트(8080)를 확인할 수 있다.

 

그런데, 프론트엔트나 모바일 개발자 분들의 요청으로(예를 들어, HATEOAS를 적용했을 때 호스트와 포트가 localhost:8080으로 되어 있을 경우) 이 부분을 수정해야 할 때가 종종 있다.

 

이 때, @AutoConfigureRestDocs 애노테이션으로 Spring REST Docs의 설정 사항들을 자동 설정했다면 호스트와 포트를 간편하게 바꿀 수 있다.

 

@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc    
@AutoConfigureRestDocs(uriHost = "myhost", uriPort = "80")
public class Test { 

    @Autowired
    MockMvc mockMvc;

    ...

 

 

위와 같이 호스트(myhost), 포트(80)을 @AutoConfigureRestDocs 애노테이션의 파라미터로 넣어주면

이후 생성되는 문서에서 Host가 변경되는 것을 확인할 수 있다. 

 

출처 : 

stackoverflow.com/questions/33448963/how-to-change-host-in-curl-snippet-in-spring-rest-docs

 

How to change host in curl snippet in Spring REST Docs

Spring REST Docs produces a curl snippet which is very convenient when testing. It is equivalent to the MockMvc call as said in its docs but it would be good if its host part can be replaced with a...

stackoverflow.com