Class AbstractBodySnippet

java.lang.Object
org.springframework.restdocs.snippet.TemplatedSnippet
org.springframework.restdocs.payload.AbstractBodySnippet
All Implemented Interfaces:
Snippet
Direct Known Subclasses:
RequestBodySnippet, RequestPartBodySnippet, ResponseBodySnippet

public abstract class AbstractBodySnippet extends TemplatedSnippet
Abstract TemplatedSnippet subclass that provides a base for snippets that document a RESTful resource's request or response body.
Author:
Andy Wilkinson, Achim Grimm
  • Constructor Details

    • AbstractBodySnippet

      protected AbstractBodySnippet(String type, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String,Object> attributes)
      Creates a new AbstractBodySnippet that will produce a snippet named <type>-body using a template named <type>-body. The snippet will contain the subsection of the body extracted by the given subsectionExtractor. The given attributes will be included in the model during template rendering
      Parameters:
      type - the type of the body
      subsectionExtractor - the subsection extractor
      attributes - the attributes
    • AbstractBodySnippet

      protected AbstractBodySnippet(String name, String type, PayloadSubsectionExtractor<?> subsectionExtractor, Map<String,Object> attributes)
      Creates a new AbstractBodySnippet that will produce a snippet named <name>-body using a template named <type>-body. The snippet will contain the subsection of the body extracted by the given subsectionExtractor. The given attributes will be included in the model during template rendering
      Parameters:
      name - the name of the snippet
      type - the type of the body
      subsectionExtractor - the subsection extractor
      attributes - the 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
    • getContent

      protected abstract byte[] getContent(Operation operation) throws IOException
      Returns the content of the request or response extracted from the given operation.
      Parameters:
      operation - the operation
      Returns:
      the content
      Throws:
      IOException - if the content cannot be extracted
    • getContentType

      protected abstract org.springframework.http.MediaType getContentType(Operation operation)
      Returns the content type of the request or response extracted from the given operation.
      Parameters:
      operation - the operation
      Returns:
      the content type