46
46
import org .springdoc .core .fn .RouterOperation ;
47
47
import org .springdoc .core .utils .SpringDocDataRestUtils ;
48
48
49
+ import org .springframework .beans .BeansException ;
49
50
import org .springframework .context .ApplicationContext ;
51
+ import org .springframework .context .ApplicationContextAware ;
50
52
import org .springframework .core .annotation .AnnotatedElementUtils ;
51
53
import org .springframework .core .annotation .AnnotationUtils ;
52
54
import org .springframework .data .mapping .PersistentEntity ;
75
77
*
76
78
* @author bnasslahsen
77
79
*/
78
- public class SpringRepositoryRestResourceProvider implements RepositoryRestResourceProvider {
80
+ public class SpringRepositoryRestResourceProvider implements RepositoryRestResourceProvider , ApplicationContextAware {
79
81
80
82
/**
81
83
* The constant SPRING_DATA_REST_PACKAGE.
@@ -136,31 +138,11 @@ public class SpringRepositoryRestResourceProvider implements RepositoryRestResou
136
138
}
137
139
}
138
140
139
- /**
140
- * The Mappings.
141
- */
142
- private final ResourceMappings mappings ;
143
-
144
- /**
145
- * The Repositories.
146
- */
147
- private final Repositories repositories ;
148
-
149
- /**
150
- * The Associations.
151
- */
152
- private final Associations associations ;
153
-
154
141
/**
155
142
* The Data rest router operation builder.
156
143
*/
157
144
private final DataRestRouterOperationService dataRestRouterOperationService ;
158
145
159
- /**
160
- * The Persistent entities.
161
- */
162
- private final PersistentEntities persistentEntities ;
163
-
164
146
/**
165
147
* The Mapper.
166
148
*/
@@ -169,7 +151,7 @@ public class SpringRepositoryRestResourceProvider implements RepositoryRestResou
169
151
/**
170
152
* The Application context.
171
153
*/
172
- private final ApplicationContext applicationContext ;
154
+ private ApplicationContext applicationContext ;
173
155
174
156
/**
175
157
* The Spring doc data rest utils.
@@ -184,24 +166,13 @@ public class SpringRepositoryRestResourceProvider implements RepositoryRestResou
184
166
/**
185
167
* Instantiates a new Spring repository rest resource provider.
186
168
*
187
- * @param mappings the mappings
188
- * @param repositories the repositories
189
- * @param associations the associations
190
- * @param applicationContext the application context
191
169
* @param dataRestRouterOperationService the data rest router operation builder
192
- * @param persistentEntities the persistent entities
193
170
* @param mapper the mapper
194
171
* @param springDocDataRestUtils the spring doc data rest utils
195
172
*/
196
- public SpringRepositoryRestResourceProvider (ResourceMappings mappings , Repositories repositories ,
197
- Associations associations , ApplicationContext applicationContext , DataRestRouterOperationService dataRestRouterOperationService ,
198
- PersistentEntities persistentEntities , ObjectMapper mapper , SpringDocDataRestUtils springDocDataRestUtils ) {
199
- this .mappings = mappings ;
200
- this .repositories = repositories ;
201
- this .associations = associations ;
202
- this .applicationContext = applicationContext ;
173
+ public SpringRepositoryRestResourceProvider (DataRestRouterOperationService dataRestRouterOperationService ,
174
+ ObjectMapper mapper , SpringDocDataRestUtils springDocDataRestUtils ) {
203
175
this .dataRestRouterOperationService = dataRestRouterOperationService ;
204
- this .persistentEntities = persistentEntities ;
205
176
this .mapper = mapper ;
206
177
this .springDocDataRestUtils = springDocDataRestUtils ;
207
178
}
@@ -217,6 +188,10 @@ public SpringRepositoryRestResourceProvider(ResourceMappings mappings, Repositor
217
188
public List <RouterOperation > getRouterOperations (OpenAPI openAPI , Locale locale ) {
218
189
List <RouterOperation > routerOperationList = new ArrayList <>();
219
190
handlerMappingList = getHandlerMappingList ();
191
+ Associations associations = applicationContext .getBean (Associations .class );
192
+ ResourceMappings mappings = applicationContext .getBean (ResourceMappings .class );
193
+ PersistentEntities persistentEntities = applicationContext .getBean (PersistentEntities .class );
194
+ Repositories repositories = applicationContext .getBean (Repositories .class );
220
195
for (Class <?> domainType : repositories ) {
221
196
Class <?> repository = repositories .getRequiredRepositoryInformation (domainType ).getRepositoryInterface ();
222
197
DataRestRepository dataRestRepository = new DataRestRepository (domainType , repository , locale );
@@ -274,7 +249,7 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping beanBasePathAware
274
249
}
275
250
}
276
251
// search
277
- findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , dataRestRepository , resourceMetadata );
252
+ findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , dataRestRepository , resourceMetadata , associations );
278
253
}
279
254
}
280
255
return routerOperationList ;
@@ -312,6 +287,8 @@ public Map getHandlerMethods() {
312
287
*/
313
288
@ Override
314
289
public void customize (OpenAPI openAPI ) {
290
+ ResourceMappings mappings = applicationContext .getBean (ResourceMappings .class );
291
+ PersistentEntities persistentEntities = applicationContext .getBean (PersistentEntities .class );
315
292
springDocDataRestUtils .customise (openAPI , mappings , persistentEntities );
316
293
}
317
294
@@ -346,9 +323,10 @@ private List<HandlerMapping> getHandlerMappingList() {
346
323
* @param handlerMappingList the handler mapping list
347
324
* @param dataRestRepository the repository data rest
348
325
* @param resourceMetadata the resource metadata
326
+ * @param associations the associations
349
327
*/
350
328
private void findSearchResourceMappings (OpenAPI openAPI , List <RouterOperation > routerOperationList , List <HandlerMapping > handlerMappingList ,
351
- DataRestRepository dataRestRepository , ResourceMetadata resourceMetadata ) {
329
+ DataRestRepository dataRestRepository , ResourceMetadata resourceMetadata , Associations associations ) {
352
330
for (HandlerMapping handlerMapping : handlerMappingList ) {
353
331
if (handlerMapping instanceof RepositoryRestHandlerMapping repositoryRestHandlerMapping ) {
354
332
Map <RequestMappingInfo , HandlerMethod > handlerMethodMap = repositoryRestHandlerMapping .getHandlerMethods ();
@@ -406,4 +384,8 @@ private List<RouterOperation> findControllers(List<RouterOperation> routerOperat
406
384
return routerOperationList ;
407
385
}
408
386
387
+ @ Override
388
+ public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
389
+ this .applicationContext = applicationContext ;
390
+ }
409
391
}
0 commit comments