Class AbstractParametersSnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.request.AbstractParametersSnippet
- All Implemented Interfaces:
Snippet
- Direct Known Subclasses:
FormParametersSnippet
,PathParametersSnippet
,QueryParametersSnippet
Abstract
TemplatedSnippet
subclass that provides a base for snippets that
document parameters from a request sent to a RESTful resource.- Author:
- Andreas Evers, Andy Wilkinson
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractParametersSnippet
(String snippetName, List<ParameterDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedParameters) Creates a newAbstractParametersSnippet
that will produce a snippet with the givensnippetName
that will document parameters using the givendescriptors
. -
Method Summary
Modifier and TypeMethodDescriptioncreateModel
(Operation operation) Create the model that should be used during template rendering to document the givenoperation
.createModelForDescriptor
(ParameterDescriptor descriptor) Returns a model for the givendescriptor
.extractActualParameters
(Operation operation) Extracts the names of the parameters that were present in the givenoperation
.protected final Map<String,
ParameterDescriptor> Returns aMap
ofParameterDescriptors
that will be used to generate the documentation key by theirParameterDescriptor.getName()
.protected final boolean
Returns whether to ignore undocumented parameters.protected abstract void
verificationFailed
(Set<String> undocumentedParameters, Set<String> missingParameters) Called when the documented parameters do not match the actual parameters.Methods inherited from class org.springframework.restdocs.snippet.TemplatedSnippet
document, getAttributes, getSnippetName
-
Constructor Details
-
AbstractParametersSnippet
protected AbstractParametersSnippet(String snippetName, List<ParameterDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedParameters) Creates a newAbstractParametersSnippet
that will produce a snippet with the givensnippetName
that will document parameters using the givendescriptors
. The givenattributes
will be included in the model during template rendering. IfignoreUndocumentedParameters
istrue
, undocumented parameters will be ignored and will not trigger a failure.- Parameters:
snippetName
- the snippet namedescriptors
- the descriptorsattributes
- the additional attributesignoreUndocumentedParameters
- whether undocumented parameters should be ignored
-
-
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
-
extractActualParameters
Extracts the names of the parameters that were present in the givenoperation
.- Parameters:
operation
- the operation- Returns:
- the parameters
-
verificationFailed
protected abstract void verificationFailed(Set<String> undocumentedParameters, Set<String> missingParameters) Called when the documented parameters do not match the actual parameters.- Parameters:
undocumentedParameters
- the parameters that were found in the operation but were not documentedmissingParameters
- the parameters that were documented but were not found in the operation
-
getParameterDescriptors
Returns aMap
ofParameterDescriptors
that will be used to generate the documentation key by theirParameterDescriptor.getName()
.- Returns:
- the map of path descriptors
-
isIgnoreUndocumentedParameters
protected final boolean isIgnoreUndocumentedParameters()Returns whether to ignore undocumented parameters.- Returns:
true
if undocumented parameters should be ignored, otherwisefalse
- Since:
- 2.0.5
-
createModelForDescriptor
Returns a model for the givendescriptor
.- Parameters:
descriptor
- the descriptor- Returns:
- the model
-