[ERROR] Fields with the following paths were not found in the payload

zirryo·2022년 9월 14일
0

❌ ERROR

목록 보기
3/6
post-thumbnail

Error

  1. error message
    The following parts of the payload were not documented:
    {
      "memberId" : 1
    }
    Fields with the following paths were not found in the payload: [email]
    org.springframework.restdocs.snippet.SnippetException: The following parts of the payload were not documented:
    {
      "memberId" : 1
    }
  2. code
    requestFields(
    	List.of(
    		fieldWithPath("email").type(JsonFieldType.STRING).description("이메일").ignored(),
    		fieldWithPath("name").type(JsonFieldType.STRING).description("이름").optional(),
    		fieldWithPath("phone").type(JsonFieldType.STRING).description("휴대폰 번호").optional(),
    		fieldWithPath("memberStatus").type(JsonFieldType.STRING).description("회원 상태").optional()
        )
    ),




Solution

에러 메세지를 보면 payload 에 email 은 없으며,
반대로 memberId 는 payload에 있으나 문서화되지 못했다는 것을 알 수 있다.

  1. field를 잘못 매칭한 경우 -> field 수정
// 기존 오류 코드
fieldWithPath("email").type(JsonFieldType.STRING).description("이메일").ignored()

// 변경된 코드
fieldWithPath("memberId").type(JsonFieldType.STRING).description("회원 식별자").ignored()

// memberId는 path variable 정보로 memberId를 전달 받기 때문에 ignored() 를 통해 API 스펙에서 제외

  1. 선택적으로 값이 입력되는 필드 -> optional() 추가
  • 위의 코드에서 name, phone, memberStatus 과 같이 null(or absent) 가 발생하는 값에 optional() 이 없는 경우 같은 에러가 발생할 수 있다.

🔗 reference

0개의 댓글