3333import org .springdoc .api .AbstractOpenApiResource ;
3434import org .springdoc .core .RepositoryRestResourceProvider ;
3535import org .springdoc .core .fn .RouterOperation ;
36+ import org .springdoc .data .rest .core .DataRestRepository ;
3637import org .springdoc .data .rest .core .DataRestRouterOperationBuilder ;
3738
3839import org .springframework .data .repository .support .Repositories ;
@@ -123,6 +124,8 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
123124 List <RouterOperation > routerOperationList = new ArrayList <>();
124125 List <HandlerMapping > handlerMappingList = delegatingHandlerMapping .getDelegates ();
125126 for (Class <?> domainType : repositories ) {
127+ Class <?> repository = repositories .getRequiredRepositoryInformation (domainType ).getRepositoryInterface ();
128+ DataRestRepository dataRestRepository = new DataRestRepository (domainType , repository );
126129 ResourceMetadata resourceMetadata = mappings .getMetadataFor (domainType );
127130 if (resourceMetadata .isExported ()) {
128131 for (HandlerMapping handlerMapping : handlerMappingList ) {
@@ -135,9 +138,9 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
135138 .getValue ().getBeanType ().getName ()))
136139 .filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
137140 .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 );
139142 }
140- else if (handlerMapping instanceof BasePathAwareHandlerMapping ) {
143+ else if (handlerMapping instanceof BasePathAwareHandlerMapping ) {
141144 BasePathAwareHandlerMapping beanBasePathAwareHandlerMapping = (BasePathAwareHandlerMapping ) handlerMapping ;
142145 Map <RequestMappingInfo , HandlerMethod > handlerMethodMap = beanBasePathAwareHandlerMapping .getHandlerMethods ();
143146 Map <RequestMappingInfo , HandlerMethod > handlerMethodMapFiltered = handlerMethodMap .entrySet ().stream ()
@@ -146,7 +149,7 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
146149 .filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
147150 .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
148151
149- findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , domainType , openAPI );
152+ findControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , dataRestRepository , openAPI );
150153 handlerMethodMapFiltered = handlerMethodMap .entrySet ().stream ()
151154 .filter (requestMappingInfoHandlerMethodEntry -> ProfileController .class .equals (requestMappingInfoHandlerMethodEntry
152155 .getValue ().getBeanType ()) || AlpsController .class .equals (requestMappingInfoHandlerMethodEntry
@@ -157,7 +160,7 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
157160 }
158161 }
159162 // search
160- findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , domainType , resourceMetadata );
163+ findSearchResourceMappings (openAPI , routerOperationList , handlerMappingList , dataRestRepository , resourceMetadata );
161164 }
162165 return routerOperationList ;
163166 }
@@ -168,10 +171,10 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
168171 * @param openAPI the open api
169172 * @param routerOperationList the router operation list
170173 * @param handlerMappingList the handler mapping list
171- * @param domainType the domain type
174+ * @param dataRestRepository the repository data rest
172175 * @param resourceMetadata the resource metadata
173176 */
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 ) {
175178 for (HandlerMapping handlerMapping : handlerMappingList ) {
176179 if (handlerMapping instanceof RepositoryRestHandlerMapping ) {
177180 RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping ) handlerMapping ;
@@ -181,10 +184,10 @@ private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> r
181184 .getValue ().getBeanType ().getName ()))
182185 .filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getBeanType ()))
183186 .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 () );
185188 SearchResourceMappings searchResourceMappings = metadata .getSearchResourceMappings ();
186189 if (searchResourceMappings .isExported ()) {
187- findSearchControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , domainType , openAPI , searchResourceMappings );
190+ findSearchControllers (routerOperationList , handlerMethodMapFiltered , resourceMetadata , dataRestRepository , openAPI , searchResourceMappings );
188191 }
189192 }
190193 }
@@ -196,16 +199,16 @@ private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> r
196199 * @param routerOperationList the router operation list
197200 * @param handlerMethodMap the handler method map
198201 * @param resourceMetadata the resource metadata
199- * @param domainType the domain type
202+ * @param dataRestRepository the repository data rest
200203 * @param openAPI the open api
201204 * @param searchResourceMappings the search resource mappings
202205 * @return the list
203206 */
204207 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 ) {
206209 Stream <MethodResourceMapping > methodResourceMappingStream = searchResourceMappings .getExportedMappings ();
207210 methodResourceMappingStream .forEach (methodResourceMapping -> dataRestRouterOperationBuilder .buildSearchRouterOperationList (
208- routerOperationList , handlerMethodMap , resourceMetadata , domainType , openAPI , methodResourceMapping ));
211+ routerOperationList , handlerMethodMap , resourceMetadata , dataRestRepository , openAPI , methodResourceMapping ));
209212 return routerOperationList ;
210213 }
211214
@@ -216,16 +219,16 @@ private List<RouterOperation> findSearchControllers(List<RouterOperation> router
216219 * @param routerOperationList the router operation list
217220 * @param handlerMethodMap the handler method map
218221 * @param resourceMetadata the resource metadata
219- * @param domainType the domain type
222+ * @param dataRestRepository the repository data rest
220223 * @param openAPI the open api
221224 * @return the list
222225 */
223226 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 ) {
227230 dataRestRouterOperationBuilder .buildEntityRouterOperationList (routerOperationList , handlerMethodMap , resourceMetadata ,
228- domainType , openAPI );
231+ dataRestRepository , openAPI );
229232 return routerOperationList ;
230233 }
231234
0 commit comments