84
84
import org .springdoc .core .SpringDocConfigProperties .GroupConfig ;
85
85
import org .springdoc .core .SpringDocProviders ;
86
86
import org .springdoc .core .annotations .RouterOperations ;
87
- import org .springdoc .core .customizers .OpenApiCustomiser ;
87
+ import org .springdoc .core .customizers .DataRestRouterOperationCustomizer ;
88
88
import org .springdoc .core .customizers .OpenApiLocaleCustomizer ;
89
89
import org .springdoc .core .customizers .OperationCustomizer ;
90
90
import org .springdoc .core .customizers .RouterOperationCustomizer ;
91
- import org .springdoc .core .filters . OpenApiMethodFilter ;
91
+ import org .springdoc .core .customizers . SpringDocCustomizers ;
92
92
import org .springdoc .core .fn .AbstractRouterFunctionVisitor ;
93
93
import org .springdoc .core .fn .RouterFunctionData ;
94
94
import org .springdoc .core .fn .RouterOperation ;
113
113
114
114
import static org .springdoc .core .Constants .ACTUATOR_DEFAULT_GROUP ;
115
115
import static org .springdoc .core .Constants .DOT ;
116
- import static org .springdoc .core .Constants .LINKS_SCHEMA_CUSTOMISER ;
117
116
import static org .springdoc .core .Constants .OPERATION_ATTRIBUTE ;
118
117
import static org .springdoc .core .Constants .SPRING_MVC_SERVLET_PATH ;
119
118
import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .isDeprecated ;
@@ -182,84 +181,51 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
182
181
*/
183
182
private final OperationService operationParser ;
184
183
185
- /**
186
- * The Open api customizers.
187
- */
188
- private final Optional <List <OpenApiCustomiser >> openApiCustomisers ;
189
-
190
- /**
191
- * The Operation customizers.
192
- */
193
- private final Optional <List <OperationCustomizer >> operationCustomizers ;
194
-
195
- /**
196
- * The RouterOperation customizers.
197
- */
198
- private final Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ;
199
-
200
- /**
201
- * The method filters to use.
202
- */
203
- private final Optional <List <OpenApiMethodFilter >> methodFilters ;
204
-
205
184
/**
206
185
* The Ant path matcher.
207
186
*/
208
187
private final AntPathMatcher antPathMatcher = new AntPathMatcher ();
209
188
210
- /**
211
- * The OpenApi with locale customizers.
212
- */
213
- private final Map <String , OpenApiLocaleCustomizer > openApiLocaleCustomizers ;
214
189
215
190
/**
216
191
* The Open api builder.
217
192
*/
218
193
protected OpenAPIService openAPIService ;
219
194
195
+ /**
196
+ * The Spring doc customizers.
197
+ */
198
+ protected final SpringDocCustomizers springDocCustomizers ;
199
+
220
200
/**
221
201
* Instantiates a new Abstract open api resource.
202
+ *
222
203
* @param groupName the group name
223
204
* @param openAPIBuilderObjectFactory the open api builder object factory
224
205
* @param requestBuilder the request builder
225
206
* @param responseBuilder the response builder
226
207
* @param operationParser the operation parser
227
- * @param operationCustomizers the operation customizers
228
- * @param openApiCustomisers the open api customisers
229
- * @param routerOperationCustomizers the router operation customisers
230
- * @param methodFilters the method filters
231
208
* @param springDocConfigProperties the spring doc config properties
232
209
* @param springDocProviders the spring doc providers
210
+ * @param springDocCustomizers the spring doc customizers
233
211
*/
234
212
protected AbstractOpenApiResource (String groupName , ObjectFactory <OpenAPIService > openAPIBuilderObjectFactory ,
235
213
AbstractRequestService requestBuilder ,
236
214
GenericResponseService responseBuilder , OperationService operationParser ,
237
- Optional <List <OperationCustomizer >> operationCustomizers ,
238
- Optional <List <OpenApiCustomiser >> openApiCustomisers ,
239
- Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ,
240
- Optional <List <OpenApiMethodFilter >> methodFilters ,
241
- SpringDocConfigProperties springDocConfigProperties , SpringDocProviders springDocProviders ) {
215
+ SpringDocConfigProperties springDocConfigProperties ,
216
+ SpringDocProviders springDocProviders , SpringDocCustomizers springDocCustomizers ) {
242
217
super ();
243
218
this .groupName = Objects .requireNonNull (groupName , "groupName" );
244
219
this .openAPIBuilderObjectFactory = openAPIBuilderObjectFactory ;
245
220
this .openAPIService = openAPIBuilderObjectFactory .getObject ();
246
221
this .requestBuilder = requestBuilder ;
247
222
this .responseBuilder = responseBuilder ;
248
223
this .operationParser = operationParser ;
249
- this .openApiCustomisers = openApiCustomisers ;
250
- this .routerOperationCustomizers = routerOperationCustomizers ;
251
- this .methodFilters = methodFilters ;
252
224
this .springDocProviders = springDocProviders ;
253
- //add the default customizers
254
- Map <String , OpenApiCustomiser > existingOpenApiCustomisers = openAPIService .getContext ().getBeansOfType (OpenApiCustomiser .class );
255
- if (!CollectionUtils .isEmpty (existingOpenApiCustomisers ) && existingOpenApiCustomisers .containsKey (LINKS_SCHEMA_CUSTOMISER ))
256
- openApiCustomisers .ifPresent (openApiCustomisersList -> openApiCustomisersList .add (existingOpenApiCustomisers .get (LINKS_SCHEMA_CUSTOMISER )));
257
225
this .springDocConfigProperties = springDocConfigProperties ;
258
- operationCustomizers .ifPresent (customizers -> customizers .removeIf (Objects ::isNull ));
259
- this .operationCustomizers = operationCustomizers ;
226
+ this .springDocCustomizers =springDocCustomizers ;
260
227
if (springDocConfigProperties .isPreLoadingEnabled ())
261
228
Executors .newSingleThreadExecutor ().execute (this ::getOpenApi );
262
- this .openApiLocaleCustomizers = openAPIService .getContext ().getBeansOfType (OpenApiLocaleCustomizer .class );
263
229
}
264
230
265
231
/**
@@ -389,8 +355,8 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
389
355
LOGGER .warn ("Json Processing Exception occurred: {}" , e .getMessage ());
390
356
}
391
357
392
- openApiLocaleCustomizers .values ().forEach (openApiLocaleCustomizer -> openApiLocaleCustomizer .customise (openAPI , finalLocale ));
393
- openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openAPI )));
358
+ openAPIService . getContext (). getBeansOfType ( OpenApiLocaleCustomizer . class ) .values ().forEach (openApiLocaleCustomizer -> openApiLocaleCustomizer .customise (openAPI , finalLocale ));
359
+ springDocCustomizers . getOpenApiCustomizers () .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openAPI )));
394
360
if (!CollectionUtils .isEmpty (openAPI .getServers ()) && !openAPI .getServers ().equals (serversCopy ))
395
361
openAPIService .setServersPresent (true );
396
362
@@ -608,6 +574,8 @@ else if (routerOperation.getOperationModel() != null && StringUtils.isNotBlank(r
608
574
* @param locale the locale
609
575
*/
610
576
protected void calculatePath (RouterOperation routerOperation , Locale locale , OpenAPI openAPI ) {
577
+ routerOperation = customizeDataRestRouterOperation (routerOperation );
578
+
611
579
String operationPath = routerOperation .getPath ();
612
580
io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
613
581
String [] methodConsumes = routerOperation .getConsumes ();
@@ -728,7 +696,7 @@ && isPackageToScan(handlerMethod.getBeanType().getPackage())
728
696
* @return whether the method should be included in the current OpenAPI definition
729
697
*/
730
698
protected boolean isMethodToFilter (HandlerMethod handlerMethod ) {
731
- return this .methodFilters
699
+ return this .springDocCustomizers . getMethodFilters ()
732
700
.map (Collection ::stream )
733
701
.map (stream -> stream .allMatch (m -> m .isMethodToInclude (handlerMethod .getMethod ())))
734
702
.orElse (true );
@@ -868,8 +836,8 @@ protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
868
836
* @return the operation
869
837
*/
870
838
protected Operation customizeOperation (Operation operation , HandlerMethod handlerMethod ) {
871
- if (operationCustomizers .isPresent ()) {
872
- List <OperationCustomizer > operationCustomizerList = operationCustomizers .get ();
839
+ if (springDocCustomizers . getOperationCustomizers () .isPresent ()) {
840
+ List <OperationCustomizer > operationCustomizerList = springDocCustomizers . getOperationCustomizers () .get ();
873
841
for (OperationCustomizer operationCustomizer : operationCustomizerList )
874
842
operation = operationCustomizer .customize (operation , handlerMethod );
875
843
}
@@ -883,8 +851,8 @@ protected Operation customizeOperation(Operation operation, HandlerMethod handle
883
851
* @return the router operation
884
852
*/
885
853
protected RouterOperation customizeRouterOperation (RouterOperation routerOperation , HandlerMethod handlerMethod ) {
886
- if (routerOperationCustomizers .isPresent ()) {
887
- List <RouterOperationCustomizer > routerOperationCustomizerList = routerOperationCustomizers .get ();
854
+ if (springDocCustomizers . getRouterOperationCustomizers () .isPresent ()) {
855
+ List <RouterOperationCustomizer > routerOperationCustomizerList = springDocCustomizers . getRouterOperationCustomizers () .get ();
888
856
for (RouterOperationCustomizer routerOperationCustomizer : routerOperationCustomizerList ) {
889
857
routerOperation = routerOperationCustomizer .customize (routerOperation , handlerMethod );
890
858
}
@@ -1380,4 +1348,20 @@ enum ConditionType {
1380
1348
*/
1381
1349
HEADERS
1382
1350
}
1351
+
1352
+ /**
1353
+ * Customize data rest router operation router operation.
1354
+ *
1355
+ * @param routerOperation the router operation
1356
+ * @return the router operation
1357
+ */
1358
+ private RouterOperation customizeDataRestRouterOperation (RouterOperation routerOperation ) {
1359
+ if (springDocCustomizers .getDataRestRouterOperationCustomizers ().isPresent ()) {
1360
+ List <DataRestRouterOperationCustomizer > dataRestRouterOperationCustomizerList = springDocCustomizers .getDataRestRouterOperationCustomizers ().get ();
1361
+ for (DataRestRouterOperationCustomizer dataRestRouterOperationCustomizer : dataRestRouterOperationCustomizerList ) {
1362
+ routerOperation = dataRestRouterOperationCustomizer .customize (routerOperation );
1363
+ }
1364
+ }
1365
+ return routerOperation ;
1366
+ }
1383
1367
}
0 commit comments