Skip to content

Commit e5aa5ba

Browse files
committed
Make it easier to write a preprocessor that only changes req or resp
The commit introduces OperationPreprocessorAdapter, an abstract implementation of OperationProcessor that returns to request and response as-is. OperationPreprocessorAdapter is intended to be subclassed by OperationProcessor implementations that only modify the request or the response. Implementations the modify both should continue to implement OperationPreprocess directly. Closes gh-154
1 parent 2da1a0a commit e5aa5ba

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.restdocs.operation.preprocess;
18+
19+
import org.springframework.restdocs.operation.OperationRequest;
20+
import org.springframework.restdocs.operation.OperationResponse;
21+
22+
/**
23+
* An implementation of {@link OperationPreprocessor} that returns the request and
24+
* response as-is. To be subclasses by preprocessor implementations that only modify the
25+
* request or the response.
26+
*
27+
* @author Andy Wilkinson
28+
* @since 1.1.0
29+
*/
30+
public abstract class OperationPreprocessorAdapter implements OperationPreprocessor {
31+
32+
/**
33+
* Returns the given {@code request} as-is.
34+
*
35+
* @param request the request
36+
* @return the unmodified request
37+
*/
38+
@Override
39+
public OperationRequest preprocess(OperationRequest request) {
40+
return request;
41+
}
42+
43+
/**
44+
* Returns the given {@code response} as-is.
45+
*
46+
* @param response the response
47+
* @return the unmodified response
48+
*/
49+
@Override
50+
public OperationResponse preprocess(OperationResponse response) {
51+
return response;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)