Class AbstractHeadersSnippet

java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.headers.AbstractHeadersSnippet
All Implemented Interfaces:
Snippet
Direct Known Subclasses:
RequestHeadersSnippet, ResponseHeadersSnippet

public abstract class AbstractHeadersSnippet extends TemplatedSnippet
Abstract TemplatedSnippet subclass that provides a base for snippets that document a RESTful resource's request or response headers.
Author:
Andreas Evers
  • Constructor Details

    • AbstractHeadersSnippet

      protected AbstractHeadersSnippet(String type, List<HeaderDescriptor> descriptors, Map<String,Object> attributes)
      Creates a new AbstractHeadersSnippet that will produce a snippet named <type>-headers. The headers will be documented using the given descriptors and the given attributes will be included in the model during template rendering.
      Parameters:
      type - the type of the headers
      descriptors - the header descriptors
      attributes - the additional attributes
  • 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
    • findMissingHeaders

      protected List<HeaderDescriptor> findMissingHeaders(Operation operation)
      Finds the headers that are missing from the operation. A header is missing if it is described by one of the headerDescriptors but is not present in the operation.
      Parameters:
      operation - the operation
      Returns:
      descriptors for the headers that are missing from the operation
    • extractActualHeaders

      protected abstract Set<String> extractActualHeaders(Operation operation)
      Extracts the names of the headers from the request or response of the given operation.
      Parameters:
      operation - the operation
      Returns:
      the header names
    • getHeaderDescriptors

      protected final List<HeaderDescriptor> getHeaderDescriptors()
      Returns the list of HeaderDescriptors that will be used to generate the documentation.
      Returns:
      the header descriptors
    • createModelForDescriptor

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