Search in sources :

Example 1 with ActuatorProvider

use of org.springdoc.core.providers.ActuatorProvider in project springdoc-openapi by springdoc.

the class AbstractOpenApiResource method getActuatorURI.

/**
 * Gets actuator uri.
 *
 * @param scheme the scheme
 * @param host the host
 * @return the actuator uri
 */
protected URI getActuatorURI(String scheme, String host) {
    final Optional<ActuatorProvider> actuatorProviderOptional = springDocProviders.getActuatorProvider();
    URI uri = null;
    if (actuatorProviderOptional.isPresent()) {
        ActuatorProvider actuatorProvider = actuatorProviderOptional.get();
        int port;
        String path;
        if (ACTUATOR_DEFAULT_GROUP.equals(this.groupName)) {
            port = actuatorProvider.getActuatorPort();
            path = actuatorProvider.getActuatorPath();
        } else {
            port = actuatorProvider.getApplicationPort();
            path = actuatorProvider.getContextPath();
            String mvcServletPath = this.openAPIService.getContext().getBean(Environment.class).getProperty(SPRING_MVC_SERVLET_PATH);
            if (StringUtils.isNotEmpty(mvcServletPath))
                path = path + mvcServletPath;
        }
        try {
            uri = new URI(StringUtils.defaultIfEmpty(scheme, "http"), null, StringUtils.defaultIfEmpty(host, "localhost"), port, path, null, null);
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to parse the URL: scheme {}, host {}, port {}, path {}", scheme, host, port, path);
        }
    }
    return uri;
}
Also used : Environment(org.springframework.core.env.Environment) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ActuatorProvider(org.springdoc.core.providers.ActuatorProvider)

Example 2 with ActuatorProvider

use of org.springdoc.core.providers.ActuatorProvider in project springdoc-openapi by springdoc.

the class OpenApiResource method getPaths.

@Override
@SuppressWarnings("unchecked")
protected void getPaths(Map<String, Object> restControllers, Locale locale) {
    Optional<SpringWebProvider> springWebProviderOptional = springDocProviders.getSpringWebProvider();
    springWebProviderOptional.ifPresent(springWebProvider -> {
        Map<RequestMappingInfo, HandlerMethod> map = springWebProvider.getHandlerMethods();
        Optional<RepositoryRestResourceProvider> repositoryRestResourceProviderOptional = springDocProviders.getRepositoryRestResourceProvider();
        repositoryRestResourceProviderOptional.ifPresent(restResourceProvider -> {
            List<RouterOperation> operationList = restResourceProvider.getRouterOperations(openAPIService.getCalculatedOpenAPI(), locale);
            calculatePath(operationList, locale);
            restResourceProvider.customize(openAPIService.getCalculatedOpenAPI());
            Map<RequestMappingInfo, HandlerMethod> mapDataRest = restResourceProvider.getHandlerMethods();
            Map<String, Object> requestMappingMap = restResourceProvider.getBasePathAwareControllerEndpoints();
            Class[] additionalRestClasses = requestMappingMap.values().stream().map(AopUtils::getTargetClass).toArray(Class[]::new);
            AbstractOpenApiResource.addRestControllers(additionalRestClasses);
            map.putAll(mapDataRest);
        });
        Optional<ActuatorProvider> actuatorProviderOptional = springDocProviders.getActuatorProvider();
        if (actuatorProviderOptional.isPresent() && springDocConfigProperties.isShowActuator()) {
            Map<RequestMappingInfo, HandlerMethod> actuatorMap = actuatorProviderOptional.get().getMethods();
            this.openAPIService.addTag(new HashSet<>(actuatorMap.values()), getTag());
            map.putAll(actuatorMap);
        }
        calculatePath(restControllers, map, locale);
    });
    Optional<SecurityOAuth2Provider> securityOAuth2ProviderOptional = springDocProviders.getSpringSecurityOAuth2Provider();
    if (securityOAuth2ProviderOptional.isPresent()) {
        SecurityOAuth2Provider securityOAuth2Provider = securityOAuth2ProviderOptional.get();
        Map<RequestMappingInfo, HandlerMethod> mapOauth = securityOAuth2Provider.getHandlerMethods();
        Map<String, Object> requestMappingMapSec = securityOAuth2Provider.getFrameworkEndpoints();
        Class[] additionalRestClasses = requestMappingMapSec.values().stream().map(AopUtils::getTargetClass).toArray(Class[]::new);
        AbstractOpenApiResource.addRestControllers(additionalRestClasses);
        calculatePath(requestMappingMapSec, mapOauth, locale);
    }
    springDocProviders.getRouterFunctionProvider().ifPresent(routerFunctions -> routerFunctions.getRouterFunctionPaths().ifPresent(routerBeans -> routerBeans.forEach((beanName, routerFunctionVisitor) -> getRouterFunctionPaths(beanName, routerFunctionVisitor, locale))));
}
Also used : OperationCustomizer(org.springdoc.core.customizers.OperationCustomizer) ActuatorProvider(org.springdoc.core.providers.ActuatorProvider) GenericResponseService(org.springdoc.core.GenericResponseService) AopUtils(org.springframework.aop.support.AopUtils) ActuatorProvider.getTag(org.springdoc.core.providers.ActuatorProvider.getTag) AbstractOpenApiResource(org.springdoc.api.AbstractOpenApiResource) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PathUtils(io.swagger.v3.core.util.PathUtils) MimeType(org.springframework.util.MimeType) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HandlerMethod(org.springframework.web.method.HandlerMethod) HttpServletRequest(javax.servlet.http.HttpServletRequest) OpenApiMethodFilter(org.springdoc.core.filters.OpenApiMethodFilter) Locale(java.util.Locale) OpenAPI(io.swagger.v3.oas.models.OpenAPI) DEFAULT_GROUP_NAME(org.springdoc.core.Constants.DEFAULT_GROUP_NAME) Map(java.util.Map) OperationService(org.springdoc.core.OperationService) OpenAPIService(org.springdoc.core.OpenAPIService) AbstractRequestService(org.springdoc.core.AbstractRequestService) SpringDocProviders(org.springdoc.core.SpringDocProviders) OpenApiCustomiser(org.springdoc.core.customizers.OpenApiCustomiser) RouterOperation(org.springdoc.core.fn.RouterOperation) SecurityOAuth2Provider(org.springdoc.core.providers.SecurityOAuth2Provider) SpringDocConfigProperties(org.springdoc.core.SpringDocConfigProperties) Set(java.util.Set) SpringWebProvider(org.springdoc.core.providers.SpringWebProvider) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectFactory(org.springframework.beans.factory.ObjectFactory) List(java.util.List) TreeMap(java.util.TreeMap) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) RepositoryRestResourceProvider(org.springdoc.core.providers.RepositoryRestResourceProvider) Comparator(java.util.Comparator) SpringWebProvider(org.springdoc.core.providers.SpringWebProvider) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HandlerMethod(org.springframework.web.method.HandlerMethod) ActuatorProvider(org.springdoc.core.providers.ActuatorProvider) RouterOperation(org.springdoc.core.fn.RouterOperation) RepositoryRestResourceProvider(org.springdoc.core.providers.RepositoryRestResourceProvider) SecurityOAuth2Provider(org.springdoc.core.providers.SecurityOAuth2Provider)

Aggregations

ActuatorProvider (org.springdoc.core.providers.ActuatorProvider)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 PathUtils (io.swagger.v3.core.util.PathUtils)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AbstractOpenApiResource (org.springdoc.api.AbstractOpenApiResource)1 AbstractRequestService (org.springdoc.core.AbstractRequestService)1 DEFAULT_GROUP_NAME (org.springdoc.core.Constants.DEFAULT_GROUP_NAME)1 GenericResponseService (org.springdoc.core.GenericResponseService)1