Class RestDocumentationGenerator<REQ,RESP>

java.lang.Object
org.springframework.restdocs.generate.RestDocumentationGenerator<REQ,RESP>
Type Parameters:
REQ - the request type that can be handled
RESP - the response type that can be handled

public final class RestDocumentationGenerator<REQ,RESP> extends Object
A RestDocumentationGenerator is used to generate documentation snippets from the request and response of an operation performed on a service.
Since:
1.1.0
Author:
Andy Wilkinson, Filip Hrisafov
  • Field Details

    • ATTRIBUTE_NAME_URL_TEMPLATE

      public static final String ATTRIBUTE_NAME_URL_TEMPLATE
      Name of the operation attribute used to hold the request's URL template.
      See Also:
    • ATTRIBUTE_NAME_DEFAULT_SNIPPETS

      public static final String ATTRIBUTE_NAME_DEFAULT_SNIPPETS
      Name of the operation attribute used to hold the List of default snippets.
      See Also:
    • ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR

      public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR
      Name of the operation attribute used to hold the default operation request preprocessor.
      See Also:
    • ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR

      public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR
      Name of the operation attribute used to hold the default operation response preprocessor.
      See Also:
  • Constructor Details

    • RestDocumentationGenerator

      public RestDocumentationGenerator(String identifier, RequestConverter<REQ> requestConverter, ResponseConverter<RESP> responseConverter, Snippet... snippets)
      Creates a new RestDocumentationGenerator for the operation identified by the given identifier. The given requestConverter and responseConverter are used to convert the operation's request and response into generic OperationRequest and OperationResponse instances that can then be documented. The given documentation snippets will be produced.
      Parameters:
      identifier - the identifier for the operation
      requestConverter - the request converter
      responseConverter - the response converter
      snippets - the snippets
    • RestDocumentationGenerator

      public RestDocumentationGenerator(String identifier, RequestConverter<REQ> requestConverter, ResponseConverter<RESP> responseConverter, OperationRequestPreprocessor requestPreprocessor, Snippet... snippets)
      Creates a new RestDocumentationGenerator for the operation identified by the given identifier. The given requestConverter and responseConverter are used to convert the operation's request and response into generic OperationRequest and OperationResponse instances that can then be documented. The given requestPreprocessor is applied to the request before it is documented. The given documentation snippets will be produced.
      Parameters:
      identifier - the identifier for the operation
      requestConverter - the request converter
      responseConverter - the response converter
      requestPreprocessor - the request preprocessor
      snippets - the snippets
    • RestDocumentationGenerator

      public RestDocumentationGenerator(String identifier, RequestConverter<REQ> requestConverter, ResponseConverter<RESP> responseConverter, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets)
      Creates a new RestDocumentationGenerator for the operation identified by the given identifier. The given requestConverter and responseConverter are used to convert the operation's request and response into generic OperationRequest and OperationResponse instances that can then be documented. The given responsePreprocessor is applied to the response before it is documented. The given documentation snippets will be produced.
      Parameters:
      identifier - the identifier for the operation
      requestConverter - the request converter
      responseConverter - the response converter
      responsePreprocessor - the response preprocessor
      snippets - the snippets
    • RestDocumentationGenerator

      public RestDocumentationGenerator(String identifier, RequestConverter<REQ> requestConverter, ResponseConverter<RESP> responseConverter, OperationRequestPreprocessor requestPreprocessor, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets)
      Creates a new RestDocumentationGenerator for the operation identified by the given identifier. The given requestConverter and responseConverter are used to convert the operation's request and response into generic OperationRequest and OperationResponse instances that can then be documented. The given requestPreprocessor and responsePreprocessor are applied to the request and response before they are documented. The given documentation snippets will be produced.
      Parameters:
      identifier - the identifier for the operation
      requestConverter - the request converter
      responseConverter - the response converter
      requestPreprocessor - the request preprocessor
      responsePreprocessor - the response preprocessor
      snippets - the snippets
  • Method Details

    • handle

      public void handle(REQ request, RESP response, Map<String,Object> configuration)
      Handles the given request and response, producing documentation snippets for them using the given configuration.
      Parameters:
      request - the request
      response - the request
      configuration - the configuration
      Throws:
      RestDocumentationGenerationException - if a failure occurs during handling
    • withSnippets

      public RestDocumentationGenerator<REQ,RESP> withSnippets(Snippet... snippets)
      Creates a new RestDocumentationGenerator with the same configuration as this one other than its snippets. The new generator will use the given snippets.
      Parameters:
      snippets - the snippets
      Returns:
      the new generator