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
ConstructorsModifierConstructorDescriptionprotectedAbstractFieldsSnippet(String name, String type, List<FieldDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippetthat will produce a snippet named<name>-fieldsusing a template named<type>-fields.protectedAbstractFieldsSnippet(String name, String type, List<FieldDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedFields, PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippetthat will produce a snippet named<name>-fieldsusing a template named<type>-fields.protectedAbstractFieldsSnippet(String type, List<FieldDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippetthat will produce a snippet named<type>-fieldsusing a template named<type>-fields.protectedAbstractFieldsSnippet(String type, List<FieldDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedFields, PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippetthat will produce a snippet named<type>-fieldsusing 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 org.springframework.http.MediaTypegetContentType(Operation operation) Returns the content type of the request or response extracted from the givenoperation.protected final List<FieldDescriptor>Returns the list ofFieldDescriptorsthat will be used to generate the documentation.protected final PayloadSubsectionExtractor<?>Returns thePayloadSubsectionExtractor, if any, used by this snippet.protected final booleanReturns 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, Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippetthat will produce a snippet named<type>-fieldsusing a template named<type>-fields. The fields will be documented using the givendescriptorsand the givenattributeswill be included in the model during template rendering. IfignoreUndocumentedFieldsistrue, 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, Map<String, Object> attributes, boolean ignoreUndocumentedFields, PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippetthat will produce a snippet named<type>-fieldsusing a template named<type>-fields. The fields in the subsection of the payload extracted by the givensubsectionExtractorwill be documented using the givendescriptorsand the givenattributeswill be included in the model during template rendering. IfignoreUndocumentedFieldsistrue, 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- Since:
- 1.2.0
-
AbstractFieldsSnippet
protected AbstractFieldsSnippet(String name, String type, List<FieldDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedFields) Creates a newAbstractFieldsSnippetthat will produce a snippet named<name>-fieldsusing a template named<type>-fields. The fields will be documented using the givendescriptorsand the givenattributeswill be included in the model during template rendering. IfignoreUndocumentedFieldsistrue, 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, Map<String, Object> attributes, boolean ignoreUndocumentedFields, PayloadSubsectionExtractor<?> subsectionExtractor) Creates a newAbstractFieldsSnippetthat will produce a snippet named<name>-fieldsusing a template named<type>-fields. The fields in the subsection of the payload identified bysubsectionPathwill be documented using the givendescriptorsand the givenattributeswill be included in the model during template rendering. IfignoreUndocumentedFieldsistrue, 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 documented.nullor an empty string can be used to indicate that the entire payload should be documented.- Since:
- 1.2.0
-
-
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
-
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 ofFieldDescriptorsthat 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:
trueif 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
-