Class AbstractFieldsSnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.payload.AbstractFieldsSnippet
- All Implemented Interfaces:
Snippet
- Direct Known Subclasses:
RequestFieldsSnippet
,RequestPartFieldsSnippet
,ResponseFieldsSnippet
Abstract
TemplatedSnippet
subclass that provides a base for snippets that
document a RESTful resource's request or response fields.- Author:
- Andreas Evers, Andy Wilkinson, Mathias Düsterhöft
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractFieldsSnippet
(String name, String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippet
that will produce a snippet named<name>-fields
using a template named<type>-fields
.protected
AbstractFieldsSnippet
(String name, String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippet
that will produce a snippet named<name>-fields
using a template named<type>-fields
.protected
AbstractFieldsSnippet
(String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippet
that will produce a snippet named<type>-fields
using a template named<type>-fields
.protected
AbstractFieldsSnippet
(String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippet
that will produce a snippet named<type>-fields
using a template named<type>-fields
. -
Method Summary
Modifier and TypeMethodDescriptioncreateModel
(Operation operation) Create the model that should be used during template rendering to document the givenoperation
.createModelForDescriptor
(FieldDescriptor descriptor) Returns a model for the givendescriptor
.protected abstract byte[]
getContent
(Operation operation) Returns the content of the request or response extracted form 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
.protected final List
<FieldDescriptor> Returns the list ofFieldDescriptors
that will be used to generate the documentation.protected final @Nullable PayloadSubsectionExtractor
<?> Returns thePayloadSubsectionExtractor
, if any, used by this snippet.protected final boolean
Returns whether or not this snippet ignores undocumented fields.Methods inherited from class org.springframework.restdocs.snippet.TemplatedSnippet
document, getAttributes, getSnippetName
-
Constructor Details
-
AbstractFieldsSnippet
protected AbstractFieldsSnippet(String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippet
that will produce a snippet named<type>-fields
using a template named<type>-fields
. The fields will be documented using the givendescriptors
and the givenattributes
will be included in the model during template rendering. IfignoreUndocumentedFields
istrue
, undocumented fields will be ignored and will not trigger a failure.- Parameters:
type
- the type of the fieldsdescriptors
- the field descriptorsattributes
- the additional attributesignoreUndocumentedFields
- whether undocumented fields should be ignored
-
AbstractFieldsSnippet
protected AbstractFieldsSnippet(String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippet
that will produce a snippet named<type>-fields
using a template named<type>-fields
. The fields in the subsection of the payload extracted by the givensubsectionExtractor
will be documented using the givendescriptors
. If the extractor isnull
, the fields of the entire payload will be documented. The givenattributes
will be included in the model during template rendering. IfignoreUndocumentedFields
istrue
, undocumented fields will be ignored and will not trigger a failure.- Parameters:
type
- the type of the fieldsdescriptors
- the field descriptorsattributes
- the additional attributesignoreUndocumentedFields
- whether undocumented fields should be ignoredsubsectionExtractor
- the subsection extractor ornull
to document the fields of the entire payload- Since:
- 1.2.0
-
AbstractFieldsSnippet
protected AbstractFieldsSnippet(String name, String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippet
that will produce a snippet named<name>-fields
using a template named<type>-fields
. The fields will be documented using the givendescriptors
and the givenattributes
will be included in the model during template rendering. IfignoreUndocumentedFields
istrue
, undocumented fields will be ignored and will not trigger a failure.- Parameters:
name
- the name of the snippettype
- the type of the fieldsdescriptors
- the field descriptorsattributes
- the additional attributesignoreUndocumentedFields
- whether undocumented fields should be ignored
-
AbstractFieldsSnippet
protected AbstractFieldsSnippet(String name, String type, List<FieldDescriptor> descriptors, @Nullable Map<String, Object> attributes, boolean ignoreUndocumentedFields, @Nullable PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippet
that will produce a snippet named<name>-fields
using a template named<type>-fields
. The fields in the subsection of the payload extracted by the givensubsectionExtractor
will be documented using the givendescriptors
. If the extractor isnull
, the fields of the entire payload will be documented. The givenattributes
will be included in the model during template rendering. IfignoreUndocumentedFields
istrue
, undocumented fields will be ignored and will not trigger a failure.- Parameters:
name
- the name of the snippettype
- the type of the fieldsdescriptors
- the field descriptorsattributes
- the additional attributesignoreUndocumentedFields
- whether undocumented fields should be ignoredsubsectionExtractor
- the subsection extractor ornull
to document the fields of the entire payload.- Since:
- 1.2.0
-
-
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
-
getContentType
Returns the content type of the request or response extracted from the givenoperation
.- Parameters:
operation
- the operation- Returns:
- the content type
-
getContent
Returns the content of the request or response extracted form the givenoperation
.- Parameters:
operation
- the operation- Returns:
- the content
- Throws:
IOException
- if the content cannot be extracted
-
getFieldDescriptors
Returns the list ofFieldDescriptors
that will be used to generate the documentation.- Returns:
- the field descriptors
-
isIgnoredUndocumentedFields
protected final boolean isIgnoredUndocumentedFields()Returns whether or not this snippet ignores undocumented fields.- Returns:
true
if undocumented fields are ignored, otherwisefalse
-
getSubsectionExtractor
Returns thePayloadSubsectionExtractor
, if any, used by this snippet.- Returns:
- the subsection extractor or
null
- Since:
- 1.2.4
-
createModelForDescriptor
Returns a model for the givendescriptor
.- Parameters:
descriptor
- the descriptor- Returns:
- the model
-