spring-restdocs
spring-restdocs copied to clipboard
Replace factory with builder when creating operation requests/responses
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
.
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.