2016-10-05 4 views
0

Spring REST Docs library을 사용하여 휴식 서비스 문서를 작성하고 있습니다.Spring REST Doc unamed 요청 매개 변수

문제점은 JSON 구조의 POST 요청을 이름이없는 입력으로 허용한다는 점입니다.

요청은 다음과 같이 보입니다 : I는 입력 구조를 문서화하고 싶은

POST /images?limit=3&offset=12 HTTP/1.1 
Content-Type: application/json 
Host: localhost:8080 
Content-Length: 289 

{"acquisitionWindow":0,"platformName":"myPlatform","requireImageFile":false,"requireImageFileOrQuicklook":false,"strictPolygon":false,"showInternal":false,"imageNames":["%"],"startTimeOfYear":0,"stopTimeOfYear":0,"resolutionLowerBound":0.0,"resolutionUpperBound":0.0,"reducedResolution":0} 

을하지만, 지금까지 그것을 할 수있는 방법을 발견했다.

this.mockMvc.perform(get("/users?page=2&per_page=100")) 
    .andExpect(status().isOk()) 
    .andDo(document("users", requestParameters( 
      parameterWithName("page").description("The page to retrieve"), 
      parameterWithName("per_page").description("Entries per page") 
    ))); 

하지만 내 매개 변수는 이름이없는 :

문서는 다음과 같이 설명합니다.

내가 멀리하려고 노력 무엇

: 나는 또한 빈 이름 ("")로 시도

requestParameters(
    // TODO: Insert ImageSearch here 
    parameterWithName("{}").description("ImageSearch Structure ")) 

및 배열 표기 ("[]"). 지금까지 행운이 없습니다.

수정되지 않은 매개 변수를 문서화 할 수 있습니까? 아니면 다른 구조로 포장해야합니까?

감사합니다,

+0

이름없는 매개 변수가 무엇인지 이해하지 못했습니다. POST 요청의 본문에 JSON입니까? –

+0

예! json 객체 전체를 백엔드 측 ImageSearch라고합니다. 이 개체에는 많은 검색 매개 변수가 포함되어 있습니다. – jlengrand

답변

1

당신은 요청에서 전송 년대 JSON 페이로드를 문서화하는 org.springframework.restdocs.payload.PayloadDocumentationrequestFields를 사용할 수 있습니다. 예 :

this.mockMvc.perform(get("/users?page=2&per_page=100")) 
    .andExpect(status().isOk()) 
    .andDo(document("users", requestFields( 
      fieldWithPath("acquisitionWindow").description("…"), 
      fieldWithPath("platformName").description("…")))); 

자세한 내용은 Request and response payloads section of the documentation을 참조하십시오.

+0

좋아, 내가 염두에 두었던 것을 확인한다. 이러한 항목을 문서의 개별 객체로 문서화하려면 수동으로 (정적으로) 최상위 JSON 객체를 ImageSearch로 지정해야합니다. 감사 – jlengrand

관련 문제