@@ -57,17 +57,16 @@ public final class RestDocumentationGenerator<REQ, RESP> {
57
57
public static final String ATTRIBUTE_NAME_DEFAULT_SNIPPETS = "org.springframework.restdocs.defaultSnippets" ;
58
58
59
59
/**
60
- * Name of the operation attribute used to hold the default operation request preprocessor.
60
+ * Name of the operation attribute used to hold the default operation request
61
+ * preprocessor.
61
62
*/
62
- public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR =
63
- "org.springframework.restdocs.defaultOperationRequestPreprocessor" ;
63
+ public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR = "org.springframework.restdocs.defaultOperationRequestPreprocessor" ;
64
64
65
65
/**
66
- * Name of the operation attribute used to hold the default operation response preprocessor.
66
+ * Name of the operation attribute used to hold the default operation response
67
+ * preprocessor.
67
68
*/
68
- public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR =
69
- "org.springframework.restdocs.defaultOperationResponsePreprocessor" ;
70
-
69
+ public static final String ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR = "org.springframework.restdocs.defaultOperationResponsePreprocessor" ;
71
70
72
71
private final String identifier ;
73
72
@@ -198,8 +197,10 @@ public RestDocumentationGenerator(String identifier,
198
197
*/
199
198
public void handle (REQ request , RESP response , Map <String , Object > configuration ) {
200
199
Map <String , Object > attributes = new HashMap <>(configuration );
201
- OperationRequest operationRequest = preprocessRequest (request , attributes );
202
- OperationResponse operationResponse = preprocessResponse (response , attributes );
200
+ OperationRequest operationRequest = preprocessRequest (
201
+ this .requestConverter .convert (request ), attributes );
202
+ OperationResponse operationResponse = preprocessResponse (
203
+ this .responseConverter .convert (response ), attributes );
203
204
Operation operation = new StandardOperation (this .identifier , operationRequest ,
204
205
operationResponse , attributes );
205
206
try {
@@ -239,40 +240,45 @@ private List<Snippet> getSnippets(Map<String, Object> configuration) {
239
240
return combinedSnippets ;
240
241
}
241
242
242
- private OperationRequest preprocessRequest (REQ request , Map <String , Object > configuration ) {
243
- List <OperationRequestPreprocessor > requestPreprocessors = getRequestPreprocessors (configuration );
244
- OperationRequest operationRequest = this .requestConverter .convert (request );
243
+ private OperationRequest preprocessRequest (OperationRequest request ,
244
+ Map <String , Object > configuration ) {
245
+ List <OperationRequestPreprocessor > requestPreprocessors = getRequestPreprocessors (
246
+ configuration );
245
247
for (OperationRequestPreprocessor preprocessor : requestPreprocessors ) {
246
- operationRequest = preprocessor .preprocess (operationRequest );
248
+ request = preprocessor .preprocess (request );
247
249
}
248
- return operationRequest ;
250
+ return request ;
249
251
}
250
252
251
- private List <OperationRequestPreprocessor > getRequestPreprocessors (Map <String , Object > configuration ) {
252
- List <OperationRequestPreprocessor > preprocessors = new ArrayList <>(2 );
253
- preprocessors .add (this .requestPreprocessor );
254
- OperationRequestPreprocessor defaultRequestPreprocessor = (OperationRequestPreprocessor ) configuration .get (
255
- RestDocumentationGenerator .ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR );
256
- if (defaultRequestPreprocessor != null ) {
257
- preprocessors .add (defaultRequestPreprocessor );
258
- }
259
- return preprocessors ;
253
+ private List <OperationRequestPreprocessor > getRequestPreprocessors (
254
+ Map <String , Object > configuration ) {
255
+ return getPreprocessors (this .requestPreprocessor ,
256
+ RestDocumentationGenerator .ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR ,
257
+ configuration );
260
258
}
261
259
262
- private OperationResponse preprocessResponse (RESP response , Map < String , Object > configuration ) {
263
- List < OperationResponsePreprocessor > responsePreprocessors = getResponsePreprocessors ( configuration );
264
- OperationResponse operationResponse = this . responseConverter . convert ( response );
265
- for ( OperationResponsePreprocessor preprocessor : responsePreprocessors ) {
266
- operationResponse = preprocessor .preprocess (operationResponse );
260
+ private OperationResponse preprocessResponse (OperationResponse response ,
261
+ Map < String , Object > configuration ) {
262
+ for ( OperationResponsePreprocessor preprocessor : getResponsePreprocessors (
263
+ configuration ) ) {
264
+ response = preprocessor .preprocess (response );
267
265
}
268
- return operationResponse ;
266
+ return response ;
269
267
}
270
268
271
- private List <OperationResponsePreprocessor > getResponsePreprocessors (Map <String , Object > configuration ) {
272
- List <OperationResponsePreprocessor > preprocessors = new ArrayList <>(2 );
273
- preprocessors .add (this .responsePreprocessor );
274
- OperationResponsePreprocessor defaultResponsePreprocessor = (OperationResponsePreprocessor ) configuration .get (
275
- RestDocumentationGenerator .ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR );
269
+ private List <OperationResponsePreprocessor > getResponsePreprocessors (
270
+ Map <String , Object > configuration ) {
271
+ return getPreprocessors (this .responsePreprocessor ,
272
+ RestDocumentationGenerator .ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR ,
273
+ configuration );
274
+ }
275
+
276
+ @ SuppressWarnings ("unchecked" )
277
+ private <T > List <T > getPreprocessors (T preprocessor , String preprocessorAttribute ,
278
+ Map <String , Object > configuration ) {
279
+ List <T > preprocessors = new ArrayList <>(2 );
280
+ preprocessors .add (preprocessor );
281
+ T defaultResponsePreprocessor = (T ) configuration .get (preprocessorAttribute );
276
282
if (defaultResponsePreprocessor != null ) {
277
283
preprocessors .add (defaultResponsePreprocessor );
278
284
}
0 commit comments