Class ResponseBodySnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.payload.AbstractBodySnippet
org.springframework.restdocs.payload.ResponseBodySnippet
- All Implemented Interfaces:
Snippet
A
Snippet that documents the body of a response.- Author:
- Andy Wilkinson
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newResponseBodySnippet.ResponseBodySnippet(@Nullable Map<String, Object> attributes) Creates a newResponseBodySnippetwith the given additionalattributesthat will be included in the model during template rendering.ResponseBodySnippet(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newResponseBodySnippetthat will document the subsection of the response body extracted by the givensubsectionExtractor.ResponseBodySnippet(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newResponseBodySnippetthat will document the subsection of the response body extracted by the givensubsectionExtractor. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]getContent(Operation operation) Returns the content of the request or response extracted from the givenoperation.protected @Nullable org.springframework.http.MediaTypegetContentType(Operation operation) Returns the content type of the request or response extracted from the givenoperation.Methods inherited from class AbstractBodySnippet
createModelMethods inherited from class TemplatedSnippet
document, getAttributes, getSnippetName
-
Constructor Details
-
ResponseBodySnippet
public ResponseBodySnippet()Creates a newResponseBodySnippet. -
ResponseBodySnippet
Creates a newResponseBodySnippetthat will document the subsection of the response body extracted by the givensubsectionExtractor. If the extractor isnullthe entire response body will be documented.- Parameters:
subsectionExtractor- the subsection extractor, ornullto document the entire response body
-
ResponseBodySnippet
-
ResponseBodySnippet
public ResponseBodySnippet(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newResponseBodySnippetthat will document the subsection of the response body extracted by the givensubsectionExtractor. If the extractor isnullthe entire response body will be documented. The given additionalattributesthat will be included in the model during template rendering.- Parameters:
subsectionExtractor- the subsection extractor, ornullto document the entire response bodyattributes- the additional attributes
-
-
Method Details
-
getContent
Description copied from class:AbstractBodySnippetReturns the content of the request or response extracted from the givenoperation.- Specified by:
getContentin classAbstractBodySnippet- Parameters:
operation- the operation- Returns:
- the content
- Throws:
IOException- if the content cannot be extracted
-
getContentType
Description copied from class:AbstractBodySnippetReturns the content type of the request or response extracted from the givenoperation.- Specified by:
getContentTypein classAbstractBodySnippet- Parameters:
operation- the operation- Returns:
- the content type
-