Class RequestBodySnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.payload.AbstractBodySnippet
org.springframework.restdocs.payload.RequestBodySnippet
- All Implemented Interfaces:
Snippet
A
Snippet
that documents the body of a request.- Author:
- Andy Wilkinson
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newRequestBodySnippet
.RequestBodySnippet
(@Nullable Map<String, Object> attributes) Creates a newRequestBodySnippet
with the given additionalattributes
that will be included in the model during template rendering.RequestBodySnippet
(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newRequestBodySnippet
that will document the subsection of the request body extracted by the givensubsectionExtractor
.RequestBodySnippet
(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newRequestBodySnippet
that will document the subsection of the request 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.MediaType
getContentType
(Operation operation) Returns the content type of the request or response extracted from the givenoperation
.Methods inherited from class AbstractBodySnippet
createModel
Methods inherited from class TemplatedSnippet
document, getAttributes, getSnippetName
-
Constructor Details
-
RequestBodySnippet
public RequestBodySnippet()Creates a newRequestBodySnippet
. -
RequestBodySnippet
Creates a newRequestBodySnippet
that will document the subsection of the request body extracted by the givensubsectionExtractor
. If the extractor isnull
, the fields of the entire payload will be documented.- Parameters:
subsectionExtractor
- the subsection extractor, ornull
to document the entire body.
-
RequestBodySnippet
-
RequestBodySnippet
public RequestBodySnippet(@Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newRequestBodySnippet
that will document the subsection of the request body extracted by the givensubsectionExtractor
. If the extractor isnull
, the entire body will be documented. The given additionalattributes
that will be included in the model during template rendering.- Parameters:
subsectionExtractor
- the subsection extractor ornull
to document the entire bodyattributes
- the additional attributes
-
-
Method Details
-
getContent
Description copied from class:AbstractBodySnippet
Returns the content of the request or response extracted from the givenoperation
.- Specified by:
getContent
in classAbstractBodySnippet
- Parameters:
operation
- the operation- Returns:
- the content
- Throws:
IOException
- if the content cannot be extracted
-
getContentType
Description copied from class:AbstractBodySnippet
Returns the content type of the request or response extracted from the givenoperation
.- Specified by:
getContentType
in classAbstractBodySnippet
- Parameters:
operation
- the operation- Returns:
- the content type
-