spring-restdocs icon indicating copy to clipboard operation
spring-restdocs copied to clipboard

Replace factory with builder when creating operation requests/responses

Open AugustoRavazoli opened this issue 1 year ago • 1 comments

Both the OperationRequestFactory and OperationResponseFactory leads to unnecessary code in custom pre-processors:

new OperationRequestFactory().create(
  uri,
  request.getMethod(),
  request.getContent(),
  headers,
  request.getParts(),
  cookies
);

A possible way to simplify the request creation is to use the Builder design pattern:

new OperationRequestBuider(request)
  .withUri(uri)
  .withHeaders(headers)
  .withCookies(cookies)
  .build();

The OperationRequestBuilder will builds the new request using the request argument fields as defaults, like a StringBuilder.

AugustoRavazoli avatar Apr 09 '23 16:04 AugustoRavazoli

While this is quite a low-level API that many people won't touch, I can see the value in making it more concise and easier to use. Before doing so, I'd like the outcome of https://github.com/spring-projects/spring-restdocs/issues/733 to be decided.

wilkinsona avatar May 09 '23 16:05 wilkinsona