Class LinksSnippet

java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.hypermedia.LinksSnippet
All Implemented Interfaces:
Snippet

public class LinksSnippet extends TemplatedSnippet
A Snippet that documents a RESTful resource's links.
Author:
Andy Wilkinson
See Also:
  • Constructor Details

    • LinksSnippet

      protected LinksSnippet(LinkExtractor linkExtractor, List<LinkDescriptor> descriptors)
      Creates a new LinksSnippet that will extract links using the given linkExtractor and document them using the given descriptors. Undocumented links will trigger a failure.
      Parameters:
      linkExtractor - the link extractor
      descriptors - the link descriptors
    • LinksSnippet

      protected LinksSnippet(LinkExtractor linkExtractor, List<LinkDescriptor> descriptors, boolean ignoreUndocumentedLinks)
      Creates a new LinksSnippet that will extract links using the given linkExtractor and document them using the given descriptors. If ignoreUndocumentedLinks is true, undocumented links will be ignored and will not trigger a failure.
      Parameters:
      linkExtractor - the link extractor
      descriptors - the link descriptors
      ignoreUndocumentedLinks - whether undocumented links should be ignored
    • LinksSnippet

      protected LinksSnippet(LinkExtractor linkExtractor, List<LinkDescriptor> descriptors, Map<String,Object> attributes)
      Creates a new LinksSnippet that will extract links using the given linkExtractor and document them using the given descriptors. The given attributes will be included in the model during template rendering. Undocumented links will trigger a failure.
      Parameters:
      linkExtractor - the link extractor
      descriptors - the link descriptors
      attributes - the additional attributes
    • LinksSnippet

      protected LinksSnippet(LinkExtractor linkExtractor, List<LinkDescriptor> descriptors, Map<String,Object> attributes, boolean ignoreUndocumentedLinks)
      Creates a new LinksSnippet that will extract links using the given linkExtractor and document them using the given descriptors. The given attributes will be included in the model during template rendering. If ignoreUndocumentedLinks is true, undocumented links will be ignored and will not trigger a failure.
      Parameters:
      linkExtractor - the link extractor
      descriptors - the link descriptors
      attributes - the additional attributes
      ignoreUndocumentedLinks - whether undocumented links 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
    • getDescriptorsByRel

      protected final Map<String,LinkDescriptor> getDescriptorsByRel()
      Returns a Map of LinkDescriptors keyed by their rels.
      Returns:
      the link descriptors
    • createModelForDescriptor

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

      public final LinksSnippet and(LinkDescriptor... additionalDescriptors)
      Returns a new LinksSnippet configured with this snippet's link extractor and attributes, and its descriptors combined with the given additionalDescriptors.
      Parameters:
      additionalDescriptors - the additional descriptors
      Returns:
      the new snippet
    • and

      public final LinksSnippet and(List<LinkDescriptor> additionalDescriptors)
      Returns a new LinksSnippet configured with this snippet's link extractor and attributes, and its descriptors combined with the given additionalDescriptors.
      Parameters:
      additionalDescriptors - the additional descriptors
      Returns:
      the new snippet