Class TemplatedSnippet

java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
All Implemented Interfaces:
Snippet
Direct Known Subclasses:
AbstractBodySnippet, AbstractCookiesSnippet, AbstractFieldsSnippet, AbstractHeadersSnippet, AbstractParametersSnippet, CurlRequestSnippet, HttpieRequestSnippet, HttpRequestSnippet, HttpResponseSnippet, LinksSnippet, RequestPartsSnippet

public abstract class TemplatedSnippet extends Object implements Snippet
Base class for a Snippet that is produced using a Template and TemplateEngine.
Author:
Andy Wilkinson
  • Constructor Details

    • TemplatedSnippet

      protected TemplatedSnippet(String snippetName, Map<String,Object> attributes)
      Creates a new TemplatedSnippet that will produce a snippet with the given snippetName. The snippetName will also be used as the name of the template. The given attributes will be included in the model during rendering of the template.
      Parameters:
      snippetName - the name of the snippet
      attributes - the additional attributes
      See Also:
    • TemplatedSnippet

      protected TemplatedSnippet(String snippetName, String templateName, Map<String,Object> attributes)
      Creates a new TemplatedSnippet that will produce a snippet with the given snippetName using a template with the given templateName. The given attributes will be included in the model during rendering of the template.
      Parameters:
      snippetName - the name of the snippet
      templateName - the name of the template
      attributes - the additional attributes
  • Method Details

    • document

      public void document(Operation operation) throws IOException
      Description copied from interface: Snippet
      Documents the call to the RESTful API described by the given operation.
      Specified by:
      document in interface Snippet
      Parameters:
      operation - the API operation
      Throws:
      IOException - if a failure occurs will documenting the operation
    • createModel

      protected abstract Map<String,Object> createModel(Operation operation)
      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.
      Parameters:
      operation - the operation
      Returns:
      the model
      Throws:
      ModelCreationException - if model creation fails
    • getAttributes

      protected final Map<String,Object> getAttributes()
      Returns the additional attributes that will be included in the model during template rendering.
      Returns:
      the additional attributes
    • getSnippetName

      protected final String getSnippetName()
      Returns the name of the snippet that will be created.
      Returns:
      the snippet name