33
33
import org .springdoc .api .AbstractOpenApiResource ;
34
34
import org .springdoc .core .RepositoryRestResourceProvider ;
35
35
import org .springdoc .core .fn .RouterOperation ;
36
+ import org .springdoc .data .rest .core .DataRestRepository ;
36
37
import org .springdoc .data .rest .core .DataRestRouterOperationBuilder ;
37
38
38
39
import org .springframework .data .repository .support .Repositories ;
@@ -123,6 +124,8 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
123
124
List <RouterOperation > routerOperationList = new ArrayList <>();
124
125
List <HandlerMapping > handlerMappingList = delegatingHandlerMapping .getDelegates ();
125
126
for (Class <?> domainType : repositories ) {
127
+ Class <?> repository = repositories .getRequiredRepositoryInformation (domainType ).getRepositoryInterface ();
128
+ DataRestRepository dataRestRepository = new DataRestRepository (domainType , repository );
126
129
ResourceMetadata resourceMetadata = mappings .getMetadataFor (domainType );
127
130
if (resourceMetadata .isExported ()) {
128
131
for (HandlerMapping handlerMapping : handlerMappingList ) {
@@ -135,9 +138,9 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
135
138
.getValue ().getBeanType ().getName ()))
136
139
.filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
137
140
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
138
- findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , domainType , openAPI );
141
+ findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , dataRestRepository , openAPI );
139
142
}
140
- else if (handlerMapping instanceof BasePathAwareHandlerMapping ) {
143
+ else if (handlerMapping instanceof BasePathAwareHandlerMapping ) {
141
144
BasePathAwareHandlerMapping beanBasePathAwareHandlerMapping = (BasePathAwareHandlerMapping ) handlerMapping ;
142
145
Map <RequestMappingInfo , HandlerMethod > handlerMethodMap = beanBasePathAwareHandlerMapping .getHandlerMethods ();
143
146
Map <RequestMappingInfo , HandlerMethod > handlerMethodMapFiltered = handlerMethodMap .entrySet ().stream ()
@@ -146,7 +149,7 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
146
149
.filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
147
150
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
148
151
149
- findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , domainType , openAPI );
152
+ findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , dataRestRepository , openAPI );
150
153
handlerMethodMapFiltered = handlerMethodMap .entrySet ().stream ()
151
154
.filter (requestMappingInfoHandlerMethodEntry -> ProfileController .class .equals (requestMappingInfoHandlerMethodEntry
152
155
.getValue ().getBeanType ()) || AlpsController .class .equals (requestMappingInfoHandlerMethodEntry
@@ -157,7 +160,7 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
157
160
}
158
161
}
159
162
// search
160
- findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , domainType , resourceMetadata );
163
+ findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , dataRestRepository , resourceMetadata );
161
164
}
162
165
return routerOperationList ;
163
166
}
@@ -168,10 +171,10 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
168
171
* @param openAPI the open api
169
172
* @param routerOperationList the router operation list
170
173
* @param handlerMappingList the handler mapping list
171
- * @param domainType the domain type
174
+ * @param dataRestRepository the repository data rest
172
175
* @param resourceMetadata the resource metadata
173
176
*/
174
- private void findSearchResourceMappings (OpenAPI openAPI , List <RouterOperation > routerOperationList , List <HandlerMapping > handlerMappingList , Class <?> domainType , ResourceMetadata resourceMetadata ) {
177
+ private void findSearchResourceMappings (OpenAPI openAPI , List <RouterOperation > routerOperationList , List <HandlerMapping > handlerMappingList , DataRestRepository dataRestRepository , ResourceMetadata resourceMetadata ) {
175
178
for (HandlerMapping handlerMapping : handlerMappingList ) {
176
179
if (handlerMapping instanceof RepositoryRestHandlerMapping ) {
177
180
RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping ) handlerMapping ;
@@ -181,10 +184,10 @@ private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> r
181
184
.getValue ().getBeanType ().getName ()))
182
185
.filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
183
186
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
184
- ResourceMetadata metadata = associations .getMetadataFor (domainType );
187
+ ResourceMetadata metadata = associations .getMetadataFor (dataRestRepository . getDomainType () );
185
188
SearchResourceMappings searchResourceMappings = metadata .getSearchResourceMappings ();
186
189
if (searchResourceMappings .isExported ()) {
187
- findSearchControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , domainType , openAPI , searchResourceMappings );
190
+ findSearchControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , dataRestRepository , openAPI , searchResourceMappings );
188
191
}
189
192
}
190
193
}
@@ -196,16 +199,16 @@ private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> r
196
199
* @param routerOperationList the router operation list
197
200
* @param handlerMethodMap the handler method map
198
201
* @param resourceMetadata the resource metadata
199
- * @param domainType the domain type
202
+ * @param dataRestRepository the repository data rest
200
203
* @param openAPI the open api
201
204
* @param searchResourceMappings the search resource mappings
202
205
* @return the list
203
206
*/
204
207
private List <RouterOperation > findSearchControllers (List <RouterOperation > routerOperationList ,
205
- Map <RequestMappingInfo , HandlerMethod > handlerMethodMap , ResourceMetadata resourceMetadata , Class <?> domainType , OpenAPI openAPI , SearchResourceMappings searchResourceMappings ) {
208
+ Map <RequestMappingInfo , HandlerMethod > handlerMethodMap , ResourceMetadata resourceMetadata , DataRestRepository dataRestRepository , OpenAPI openAPI , SearchResourceMappings searchResourceMappings ) {
206
209
Stream <MethodResourceMapping > methodResourceMappingStream = searchResourceMappings .getExportedMappings ();
207
210
methodResourceMappingStream .forEach (methodResourceMapping -> dataRestRouterOperationBuilder .buildSearchRouterOperationList (
208
- routerOperationList , handlerMethodMap , resourceMetadata , domainType , openAPI , methodResourceMapping ));
211
+ routerOperationList , handlerMethodMap , resourceMetadata , dataRestRepository , openAPI , methodResourceMapping ));
209
212
return routerOperationList ;
210
213
}
211
214
@@ -216,16 +219,16 @@ private List<RouterOperation> findSearchControllers(List<RouterOperation> router
216
219
* @param routerOperationList the router operation list
217
220
* @param handlerMethodMap the handler method map
218
221
* @param resourceMetadata the resource metadata
219
- * @param domainType the domain type
222
+ * @param dataRestRepository the repository data rest
220
223
* @param openAPI the open api
221
224
* @return the list
222
225
*/
223
226
private List <RouterOperation > findControllers
224
- (List <RouterOperation > routerOperationList ,
225
- Map <RequestMappingInfo , HandlerMethod > handlerMethodMap , ResourceMetadata resourceMetadata ,
226
- Class <?> domainType , OpenAPI openAPI ) {
227
+ (List <RouterOperation > routerOperationList ,
228
+ Map <RequestMappingInfo , HandlerMethod > handlerMethodMap , ResourceMetadata resourceMetadata ,
229
+ DataRestRepository dataRestRepository , OpenAPI openAPI ) {
227
230
dataRestRouterOperationBuilder .buildEntityRouterOperationList (routerOperationList , handlerMethodMap , resourceMetadata ,
228
- domainType , openAPI );
231
+ dataRestRepository , openAPI );
229
232
return routerOperationList ;
230
233
}
231
234
0 commit comments