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

public abstract class AbstractParametersSnippet extends TemplatedSnippet
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 Details

    • AbstractParametersSnippet

      protected AbstractParametersSnippet(String snippetName, List<ParameterDescriptor> descriptors, Map<String,Object> attributes, boolean ignoreUndocumentedParameters)
      Creates a new AbstractParametersSnippet that will produce a snippet with the given snippetName that will document parameters using the given descriptors. The given attributes will be included in the model during template rendering. If ignoreUndocumentedParameters is true, undocumented parameters will be ignored and will not trigger a failure.
      Parameters:
      snippetName - the snippet name
      descriptors - the descriptors
      attributes - the additional attributes
      ignoreUndocumentedParameters - whether undocumented parameters should be ignored
  • Method Details

    • createModel

      protected Map<String,Object> createModel(Operation operation)
      Description copied from class: TemplatedSnippet
      Create the model that should be used during template rendering to document the given operation. Any additional attributes that were supplied when this TemplatedSnippet were created will be automatically added to the model prior to rendering.
      Specified by:
      createModel in class TemplatedSnippet
      Parameters:
      operation - the operation
      Returns:
      the model
    • extractActualParameters

      protected abstract Set<String> extractActualParameters(Operation operation)
      Extracts the names of the parameters that were present in the given operation.
      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 documented
      missingParameters - the parameters that were documented but were not found in the operation
    • getParameterDescriptors

      protected final Map<String,ParameterDescriptor> getParameterDescriptors()
      Returns a Map of ParameterDescriptors that will be used to generate the documentation key by their ParameterDescriptor.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, otherwise false
      Since:
      2.0.5
    • createModelForDescriptor

      protected Map<String,Object> createModelForDescriptor(ParameterDescriptor descriptor)
      Returns a model for the given descriptor.
      Parameters:
      descriptor - the descriptor
      Returns:
      the model