Class AbstractParametersSnippet
java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.request.AbstractParametersSnippet
- All Implemented Interfaces:
Snippet
- Direct Known Subclasses:
PathParametersSnippet,RequestParametersSnippet
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
ConstructorsModifierConstructorDescriptionprotectedAbstractParametersSnippet(String snippetName, List<ParameterDescriptor> descriptors, Map<String, Object> attributes, boolean ignoreUndocumentedParameters) Creates a newAbstractParametersSnippetthat will produce a snippet with the givensnippetNamethat 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 aMapofParameterDescriptorsthat will be used to generate the documentation key by theirParameterDescriptor.getName().protected final booleanReturns whether to ignore undocumented parameters.protected abstract voidverificationFailed(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 newAbstractParametersSnippetthat will produce a snippet with the givensnippetNamethat will document parameters using the givendescriptors. The givenattributeswill be included in the model during template rendering. IfignoreUndocumentedParametersistrue, 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: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
-
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 aMapofParameterDescriptorsthat 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:
trueif undocumented parameters should be ignored, otherwisefalse- Since:
- 2.0.5
-
createModelForDescriptor
Returns a model for the givendescriptor.- Parameters:
descriptor- the descriptor- Returns:
- the model
-