39
39
import org .springdoc .api .AbstractOpenApiResource ;
40
40
import org .springdoc .core .AbstractRequestService ;
41
41
import org .springdoc .core .GenericResponseService ;
42
- import org .springdoc .core .filters .OpenApiMethodFilter ;
43
42
import org .springdoc .core .OpenAPIService ;
44
43
import org .springdoc .core .OperationService ;
45
44
import org .springdoc .core .SpringDocConfigProperties ;
46
45
import org .springdoc .core .SpringDocProviders ;
47
46
import org .springdoc .core .customizers .OpenApiCustomiser ;
48
47
import org .springdoc .core .customizers .OperationCustomizer ;
48
+ import org .springdoc .core .filters .OpenApiMethodFilter ;
49
49
import org .springdoc .core .fn .RouterOperation ;
50
50
import org .springdoc .core .providers .ActuatorProvider ;
51
51
import org .springdoc .core .providers .RepositoryRestResourceProvider ;
@@ -89,7 +89,7 @@ public OpenApiResource(String groupName, ObjectFactory<OpenAPIService> openAPIBu
89
89
Optional <List <OpenApiMethodFilter >> methodFilters ,
90
90
SpringDocConfigProperties springDocConfigProperties ,
91
91
SpringDocProviders springDocProviders ) {
92
- super (groupName , openAPIBuilderObjectFactory , requestBuilder , responseBuilder , operationParser , operationCustomizers , openApiCustomisers ,methodFilters , springDocConfigProperties , springDocProviders );
92
+ super (groupName , openAPIBuilderObjectFactory , requestBuilder , responseBuilder , operationParser , operationCustomizers , openApiCustomisers , methodFilters , springDocConfigProperties , springDocProviders );
93
93
}
94
94
95
95
/**
@@ -152,30 +152,30 @@ public String openapiYaml(HttpServletRequest request,
152
152
@ Override
153
153
@ SuppressWarnings ("unchecked" )
154
154
protected void getPaths (Map <String , Object > restControllers , Locale locale ) {
155
- SpringWebProvider springWebProvider = springDocProviders .getSpringWebProvider ();
156
- Map <RequestMappingInfo , HandlerMethod > map = springWebProvider .getHandlerMethods ();
155
+ Optional <SpringWebProvider > springWebProviderOptional = springDocProviders .getSpringWebProvider ();
156
+ springWebProviderOptional .ifPresent (springWebProvider -> {
157
+ Map <RequestMappingInfo , HandlerMethod > map = springWebProvider .getHandlerMethods ();
157
158
158
- Optional <RepositoryRestResourceProvider > repositoryRestResourceProviderOptional = springDocProviders .getRepositoryRestResourceProvider ();
159
- repositoryRestResourceProviderOptional .ifPresent (restResourceProvider -> {
160
- List <RouterOperation > operationList = restResourceProvider .getRouterOperations (openAPIService .getCalculatedOpenAPI (), locale );
161
- calculatePath (operationList , locale );
162
- restResourceProvider .customize (openAPIService .getCalculatedOpenAPI ());
163
- Map <RequestMappingInfo , HandlerMethod > mapDataRest = restResourceProvider .getHandlerMethods ();
164
- Map <String , Object > requestMappingMap = restResourceProvider .getBasePathAwareControllerEndpoints ();
165
- Class [] additionalRestClasses = requestMappingMap .values ().stream ().map (Object ::getClass ).toArray (Class []::new );
166
- AbstractOpenApiResource .addRestControllers (additionalRestClasses );
167
- calculatePath (requestMappingMap , mapDataRest , locale );
168
- });
159
+ Optional <RepositoryRestResourceProvider > repositoryRestResourceProviderOptional = springDocProviders .getRepositoryRestResourceProvider ();
160
+ repositoryRestResourceProviderOptional .ifPresent (restResourceProvider -> {
161
+ List <RouterOperation > operationList = restResourceProvider .getRouterOperations (openAPIService .getCalculatedOpenAPI (), locale );
162
+ calculatePath (operationList , locale );
163
+ restResourceProvider .customize (openAPIService .getCalculatedOpenAPI ());
164
+ Map <RequestMappingInfo , HandlerMethod > mapDataRest = restResourceProvider .getHandlerMethods ();
165
+ Map <String , Object > requestMappingMap = restResourceProvider .getBasePathAwareControllerEndpoints ();
166
+ Class [] additionalRestClasses = requestMappingMap .values ().stream ().map (Object ::getClass ).toArray (Class []::new );
167
+ AbstractOpenApiResource .addRestControllers (additionalRestClasses );
168
+ calculatePath (requestMappingMap , mapDataRest , locale );
169
+ });
169
170
170
- calculatePath (restControllers , map , locale );
171
- Optional <ActuatorProvider > actuatorProviderOptional = springDocProviders .getActuatorProvider ();
172
- if (actuatorProviderOptional .isPresent () && springDocConfigProperties .isShowActuator ()) {
173
- map = actuatorProviderOptional .get ().getMethods ();
174
- this .openAPIService .addTag (new HashSet <>(map .values ()), getTag ());
175
171
calculatePath (restControllers , map , locale );
176
- }
177
-
178
-
172
+ Optional <ActuatorProvider > actuatorProviderOptional = springDocProviders .getActuatorProvider ();
173
+ if (actuatorProviderOptional .isPresent () && springDocConfigProperties .isShowActuator ()) {
174
+ map = actuatorProviderOptional .get ().getMethods ();
175
+ this .openAPIService .addTag (new HashSet <>(map .values ()), getTag ());
176
+ calculatePath (restControllers , map , locale );
177
+ }
178
+ });
179
179
180
180
Optional <SecurityOAuth2Provider > securityOAuth2ProviderOptional = springDocProviders .getSpringSecurityOAuth2Provider ();
181
181
if (securityOAuth2ProviderOptional .isPresent ()) {
@@ -202,29 +202,31 @@ protected void getPaths(Map<String, Object> restControllers, Locale locale) {
202
202
protected void calculatePath (Map <String , Object > restControllers , Map <RequestMappingInfo , HandlerMethod > map , Locale locale ) {
203
203
List <Map .Entry <RequestMappingInfo , HandlerMethod >> entries = new ArrayList <>(map .entrySet ());
204
204
entries .sort (byReversedRequestMappingInfos ());
205
- SpringWebProvider springWebProvider = springDocProviders .getSpringWebProvider ();
206
- for (Map .Entry <RequestMappingInfo , HandlerMethod > entry : entries ) {
207
- RequestMappingInfo requestMappingInfo = entry .getKey ();
208
- HandlerMethod handlerMethod = entry .getValue ();
209
- Set <String > patterns = springWebProvider .getActivePatterns (requestMappingInfo );
210
- if (!CollectionUtils .isEmpty (patterns )) {
211
- Map <String , String > regexMap = new LinkedHashMap <>();
212
- for (String pattern : patterns ) {
213
- String operationPath = PathUtils .parsePath (pattern , regexMap );
214
- String [] produces = requestMappingInfo .getProducesCondition ().getProducibleMediaTypes ().stream ().map (MimeType ::toString ).toArray (String []::new );
215
- String [] consumes = requestMappingInfo .getConsumesCondition ().getConsumableMediaTypes ().stream ().map (MimeType ::toString ).toArray (String []::new );
216
- String [] headers = requestMappingInfo .getHeadersCondition ().getExpressions ().stream ().map (Object ::toString ).toArray (String []::new );
217
- if ((isRestController (restControllers , handlerMethod , operationPath ) || isActuatorRestController (operationPath , handlerMethod ))
218
- && isFilterCondition (handlerMethod , operationPath , produces , consumes , headers )) {
219
- Set <RequestMethod > requestMethods = requestMappingInfo .getMethodsCondition ().getMethods ();
220
- // default allowed requestmethods
221
- if (requestMethods .isEmpty ())
222
- requestMethods = this .getDefaultAllowedHttpMethods ();
223
- calculatePath (handlerMethod , operationPath , requestMethods , locale );
205
+ Optional <SpringWebProvider > springWebProviderOptional = springDocProviders .getSpringWebProvider ();
206
+ springWebProviderOptional .ifPresent (springWebProvider -> {
207
+ for (Map .Entry <RequestMappingInfo , HandlerMethod > entry : entries ) {
208
+ RequestMappingInfo requestMappingInfo = entry .getKey ();
209
+ HandlerMethod handlerMethod = entry .getValue ();
210
+ Set <String > patterns = springWebProvider .getActivePatterns (requestMappingInfo );
211
+ if (!CollectionUtils .isEmpty (patterns )) {
212
+ Map <String , String > regexMap = new LinkedHashMap <>();
213
+ for (String pattern : patterns ) {
214
+ String operationPath = PathUtils .parsePath (pattern , regexMap );
215
+ String [] produces = requestMappingInfo .getProducesCondition ().getProducibleMediaTypes ().stream ().map (MimeType ::toString ).toArray (String []::new );
216
+ String [] consumes = requestMappingInfo .getConsumesCondition ().getConsumableMediaTypes ().stream ().map (MimeType ::toString ).toArray (String []::new );
217
+ String [] headers = requestMappingInfo .getHeadersCondition ().getExpressions ().stream ().map (Object ::toString ).toArray (String []::new );
218
+ if ((isRestController (restControllers , handlerMethod , operationPath ) || isActuatorRestController (operationPath , handlerMethod ))
219
+ && isFilterCondition (handlerMethod , operationPath , produces , consumes , headers )) {
220
+ Set <RequestMethod > requestMethods = requestMappingInfo .getMethodsCondition ().getMethods ();
221
+ // default allowed requestmethods
222
+ if (requestMethods .isEmpty ())
223
+ requestMethods = this .getDefaultAllowedHttpMethods ();
224
+ calculatePath (handlerMethod , operationPath , requestMethods , locale );
225
+ }
224
226
}
225
227
}
226
228
}
227
- }
229
+ });
228
230
}
229
231
230
232
0 commit comments