Class AbstractBodySnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.payload.AbstractBodySnippet
- All Implemented Interfaces:
Snippet
- Direct Known Subclasses:
RequestBodySnippet
,RequestPartBodySnippet
,ResponseBodySnippet
Abstract
TemplatedSnippet
subclass that provides a base for snippets that
document a RESTful resource's request or response body.- Author:
- Andy Wilkinson, Achim Grimm
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractBodySnippet
(String name, String type, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newAbstractBodySnippet
that will produce a snippet named<name>-body
using a template named<type>-body
.protected
AbstractBodySnippet
(String type, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newAbstractBodySnippet
that will produce a snippet named<type>-body
using a template named<type>-body
. -
Method Summary
Modifier and TypeMethodDescriptioncreateModel
(Operation operation) Create the model that should be used during template rendering to document the givenoperation
.protected abstract byte[]
getContent
(Operation operation) Returns the content of the request or response extracted from the givenoperation
.protected abstract @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 org.springframework.restdocs.snippet.TemplatedSnippet
document, getAttributes, getSnippetName
-
Constructor Details
-
AbstractBodySnippet
protected AbstractBodySnippet(String type, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newAbstractBodySnippet
that will produce a snippet named<type>-body
using a template named<type>-body
. The snippet will contain the subsection of the body extracted by the givensubsectionExtractor
. If the extractor isnull
, the snippet will contain the entire body. The givenattributes
will be included in the model during template rendering- Parameters:
type
- the type of the bodysubsectionExtractor
- the subsection extractorattributes
- the attributes
-
AbstractBodySnippet
protected AbstractBodySnippet(String name, String type, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor, @Nullable Map<String, Object> attributes) Creates a newAbstractBodySnippet
that will produce a snippet named<name>-body
using a template named<type>-body
. The snippet will contain the subsection of the body extracted by the givensubsectionExtractor
. If the extractor isnull
, the snippet will contain the entire body. The givenattributes
will be included in the model during template rendering- Parameters:
name
- the name of the snippettype
- the type of the bodysubsectionExtractor
- the subsection extractorattributes
- the attributes
-
-
Method Details
-
createModel
Description copied from class:TemplatedSnippet
Create the model that should be used during template rendering to document the givenoperation
. Any additional attributes that were supplied when thisTemplatedSnippet
were created will be automatically added to the model prior to rendering.- Specified by:
createModel
in classTemplatedSnippet
- Parameters:
operation
- the operation- Returns:
- the model
-
getContent
Returns the content of the request or response extracted from the givenoperation
.- Parameters:
operation
- the operation- Returns:
- the content
- Throws:
IOException
- if the content cannot be extracted
-
getContentType
Returns the content type of the request or response extracted from the givenoperation
.- Parameters:
operation
- the operation- Returns:
- the content type
-