본문으로 바로가기

REST API DOCS

category JAVA/SOURCECODE 2019. 10. 29. 15:56
  1. 선정이유
    • Spring boot 설치 했더니 자동으로 들어있었다. 별도의 maven 설정을 안해도 됐다.
  2. 간단 개요
    • REST API를 문서화 한다 - HTML 형태로 내려준다.
    • 서버(WAS) 구동한후 특정 URL접속 (docs/api-docs.html)
    • Junit 성공 해야 문서가 작성된다 - 모든 API를 Junit 을 만들어야한다.
    • 문서화 된 느낌(!)이 난다. 느낌이 나는 만큼 작성해야될게 많다.
    • 여럿을 연동하면 더 잘 만들어진다. 하지만 귀찮다.
    • maven install 을 하면 생성되므로 소스수정과 자동으로 연동 된다. 또 문서 수정 안해도 된다.
  3.  작성 테스트
    • 혹, maven 설정이 안된 사람은 다른 블로그 참고바람.
    • 기본 REST 호출 부터 테스트 (아래는 기본 서비스 테스트 양식)
    • 다른 것보다 어노테이션 빼먹은거 있는지 확인하자.
    • Junit 이 되야 문서 작성이 되므로 아래 양식으로 테스트 부터 하자.
@RunWith(SpringRunner.class)
@SpringBootTest
public class ServiceTests {
	
	@Rule
	public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
	
	private MockMvc mockMvc;
	
	@Autowired
	private WebApplicationContext context;
	
	@Before
	public void setup() {
		this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
				.apply(documentationConfiguration(this.restDocumentation))
				.build();
	}
	 
	
	@Test
	public void serviceTests() throws Exception {
		mockMvc.perform(get("/getUrl").param("username", "userpasswd"));
	}	
}

 

테스트 후 응용 : https://dev-elop.tistory.com/30

 

 

 

 

 

'JAVA > SOURCECODE' 카테고리의 다른 글

jar 실행시 build 위치 추가  (0) 2021.03.02
Spring Security HttpSecurity, WebSecurity 차이?  (0) 2019.11.08
윈도우 Active Directory 연동  (0) 2019.11.01
REST API DOCS 응용  (0) 2019.10.29
반복문의 속도 개선  (0) 2019.10.27