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
ConstructorsModifierConstructorDescriptionprotectedAbstractBodySnippet(String name, String type, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String, Object> attributes) Creates a newAbstractBodySnippetthat will produce a snippet named<name>-bodyusing a template named<type>-body.protectedAbstractBodySnippet(String type, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String, Object> attributes) Creates a newAbstractBodySnippetthat will produce a snippet named<type>-bodyusing 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 org.springframework.http.MediaTypegetContentType(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, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String, Object> attributes) Creates a newAbstractBodySnippetthat will produce a snippet named<type>-bodyusing a template named<type>-body. The snippet will contain the subsection of the body extracted by the givensubsectionExtractor. The givenattributeswill 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, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String, Object> attributes) Creates a newAbstractBodySnippetthat will produce a snippet named<name>-bodyusing a template named<type>-body. The snippet will contain the subsection of the body extracted by the givensubsectionExtractor. The givenattributeswill 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:TemplatedSnippetCreate the model that should be used during template rendering to document the givenoperation. Any additional attributes that were supplied when thisTemplatedSnippetwere created will be automatically added to the model prior to rendering.- Specified by:
createModelin 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
-