use of org.springdoc.core.customizers.OpenApiLocaleCustomizer in project springdoc-openapi by springdoc.
the class AbstractOpenApiResource method getOpenApi.
/**
* Gets open api.
* @param locale the locale
* @return the open api
*/
protected synchronized OpenAPI getOpenApi(Locale locale) {
OpenAPI openApi;
final Locale finalLocale = locale == null ? Locale.getDefault() : locale;
if (openAPIService.getCachedOpenAPI(finalLocale) == null || springDocConfigProperties.isCacheDisabled()) {
Instant start = Instant.now();
openAPIService.build(finalLocale);
Map<String, Object> mappingsMap = openAPIService.getMappingsMap().entrySet().stream().filter(controller -> (AnnotationUtils.findAnnotation(controller.getValue().getClass(), Hidden.class) == null)).filter(controller -> !AbstractOpenApiResource.isHiddenRestControllers(controller.getValue().getClass())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1));
Map<String, Object> findControllerAdvice = openAPIService.getControllerAdviceMap();
// calculate generic responses
openApi = openAPIService.getCalculatedOpenAPI();
if (springDocConfigProperties.isOverrideWithGenericResponse()) {
if (!CollectionUtils.isEmpty(mappingsMap))
findControllerAdvice.putAll(mappingsMap);
responseBuilder.buildGenericResponse(openApi.getComponents(), findControllerAdvice, finalLocale);
}
getPaths(mappingsMap, finalLocale);
Optional<CloudFunctionProvider> cloudFunctionProviderOptional = springDocProviders.getSpringCloudFunctionProvider();
cloudFunctionProviderOptional.ifPresent(cloudFunctionProvider -> {
List<RouterOperation> routerOperationList = cloudFunctionProvider.getRouterOperations(openApi);
if (!CollectionUtils.isEmpty(routerOperationList))
this.calculatePath(routerOperationList, locale);
});
if (!CollectionUtils.isEmpty(openApi.getServers()))
openAPIService.setServersPresent(true);
openAPIService.updateServers(openApi);
if (springDocConfigProperties.isRemoveBrokenReferenceDefinitions())
this.removeBrokenReferenceDefinitions(openApi);
// run the optional customisers
List<Server> servers = openApi.getServers();
List<Server> serversCopy = null;
try {
serversCopy = Json.mapper().readValue(Json.mapper().writeValueAsString(servers), new TypeReference<List<Server>>() {
});
} catch (JsonProcessingException e) {
LOGGER.warn("Json Processing Exception occurred: {}", e.getMessage());
}
openApiLocaleCustomizers.values().forEach(openApiLocaleCustomizer -> openApiLocaleCustomizer.customise(openApi, finalLocale));
openApiCustomisers.ifPresent(apiCustomisers -> apiCustomisers.forEach(openApiCustomiser -> openApiCustomiser.customise(openApi)));
if (!CollectionUtils.isEmpty(openApi.getServers()) && !openApi.getServers().equals(serversCopy))
openAPIService.setServersPresent(true);
openAPIService.setCachedOpenAPI(openApi, finalLocale);
openAPIService.resetCalculatedOpenAPI();
LOGGER.info("Init duration for springdoc-openapi is: {} ms", Duration.between(start, Instant.now()).toMillis());
} else {
LOGGER.debug("Fetching openApi document from cache");
openApi = openAPIService.updateServers(openAPIService.getCachedOpenAPI(finalLocale));
}
return openApi;
}
Aggregations