Search in sources :

Example 1 with AbstractRouterFunctionVisitor

use of org.springdoc.core.fn.AbstractRouterFunctionVisitor in project springdoc-openapi by springdoc.

the class RouterFunctionWebMvcProvider method getRouterFunctionPaths.

/**
 * Gets web mvc router function paths.
 *
 * @return the web mvc router function paths
 */
public Optional<Map<String, AbstractRouterFunctionVisitor>> getRouterFunctionPaths() {
    Map<String, RouterFunction> routerBeans = applicationContext.getBeansOfType(RouterFunction.class);
    if (CollectionUtils.isEmpty(routerBeans))
        return Optional.empty();
    Map<String, AbstractRouterFunctionVisitor> routerFunctionVisitorMap = new HashMap<>();
    for (Map.Entry<String, RouterFunction> entry : routerBeans.entrySet()) {
        RouterFunction routerFunction = entry.getValue();
        RouterFunctionVisitor routerFunctionVisitor = new RouterFunctionVisitor();
        routerFunction.accept(routerFunctionVisitor);
        routerFunctionVisitorMap.put(entry.getKey(), routerFunctionVisitor);
    }
    return Optional.of(routerFunctionVisitorMap);
}
Also used : HashMap(java.util.HashMap) AbstractRouterFunctionVisitor(org.springdoc.core.fn.AbstractRouterFunctionVisitor) RouterFunction(org.springframework.web.servlet.function.RouterFunction) AbstractRouterFunctionVisitor(org.springdoc.core.fn.AbstractRouterFunctionVisitor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AbstractRouterFunctionVisitor

use of org.springdoc.core.fn.AbstractRouterFunctionVisitor in project springdoc-openapi by springdoc.

the class AbstractOpenApiResource method getRouterFunctionPaths.

/**
 * Gets router function paths.
 *
 * @param beanName the bean name
 * @param routerFunctionVisitor the router function visitor
 * @param locale the locale
 */
protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVisitor routerFunctionVisitor, Locale locale) {
    boolean withRouterOperation = routerFunctionVisitor.getRouterFunctionDatas().stream().anyMatch(routerFunctionData -> routerFunctionData.getAttributes().containsKey(OPERATION_ATTRIBUTE));
    if (withRouterOperation) {
        List<RouterOperation> operationList = routerFunctionVisitor.getRouterFunctionDatas().stream().map(RouterOperation::new).collect(Collectors.toList());
        calculatePath(operationList, locale);
    } else {
        List<org.springdoc.core.annotations.RouterOperation> routerOperationList = new ArrayList<>();
        ApplicationContext applicationContext = openAPIService.getContext();
        RouterOperations routerOperations = applicationContext.findAnnotationOnBean(beanName, RouterOperations.class);
        if (routerOperations == null) {
            org.springdoc.core.annotations.RouterOperation routerOperation = applicationContext.findAnnotationOnBean(beanName, org.springdoc.core.annotations.RouterOperation.class);
            if (routerOperation != null)
                routerOperationList.add(routerOperation);
        } else
            routerOperationList.addAll(Arrays.asList(routerOperations.value()));
        if (routerOperationList.size() == 1)
            calculatePath(routerOperationList.stream().map(routerOperation -> new RouterOperation(routerOperation, routerFunctionVisitor.getRouterFunctionDatas().get(0))).collect(Collectors.toList()), locale);
        else {
            List<RouterOperation> operationList = routerOperationList.stream().map(RouterOperation::new).collect(Collectors.toList());
            mergeRouters(routerFunctionVisitor.getRouterFunctionDatas(), operationList);
            calculatePath(operationList, locale);
        }
    }
}
Also used : RouterOperations(org.springdoc.core.annotations.RouterOperations) Arrays(java.util.Arrays) JsonView(com.fasterxml.jackson.annotation.JsonView) URLDecoder(java.net.URLDecoder) AopUtils(org.springframework.aop.support.AopUtils) Yaml(io.swagger.v3.core.util.Yaml) URISyntaxException(java.net.URISyntaxException) Parameter(io.swagger.v3.oas.models.parameters.Parameter) LoggerFactory(org.slf4j.LoggerFactory) Operation(io.swagger.v3.oas.models.Operation) DOT(org.springdoc.core.Constants.DOT) StringUtils(org.apache.commons.lang3.StringUtils) OpenApiLocaleCustomizer(org.springdoc.core.customizers.OpenApiLocaleCustomizer) HandlerMethod(org.springframework.web.method.HandlerMethod) JavadocProvider(org.springdoc.core.providers.JavadocProvider) OpenApiMethodFilter(org.springdoc.core.filters.OpenApiMethodFilter) SchemaPropertyDeprecatingConverter.isDeprecated(org.springdoc.core.converters.SchemaPropertyDeprecatingConverter.isDeprecated) Locale(java.util.Locale) Duration(java.time.Duration) Map(java.util.Map) OperationService(org.springdoc.core.OperationService) CloudFunctionProvider(org.springdoc.core.providers.CloudFunctionProvider) URI(java.net.URI) RouterOperation(org.springdoc.core.fn.RouterOperation) AntPathMatcher(org.springframework.util.AntPathMatcher) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ACTUATOR_DEFAULT_GROUP(org.springdoc.core.Constants.ACTUATOR_DEFAULT_GROUP) Method(java.lang.reflect.Method) SortedOpenAPIMixin(org.springdoc.api.mixins.SortedOpenAPIMixin) MethodAttributes(org.springdoc.core.MethodAttributes) Hidden(io.swagger.v3.oas.annotations.Hidden) Collection(java.util.Collection) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Paths(io.swagger.v3.oas.models.Paths) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) DEFAULT_PATH_SEPARATOR(org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR) Objects(java.util.Objects) List(java.util.List) HttpMethod(io.swagger.v3.oas.models.PathItem.HttpMethod) Server(io.swagger.v3.oas.models.servers.Server) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Environment(org.springframework.core.env.Environment) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Feature(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature) OperationCustomizer(org.springdoc.core.customizers.OperationCustomizer) AnnotatedElementUtils(org.springframework.core.annotation.AnnotatedElementUtils) ActuatorProvider(org.springdoc.core.providers.ActuatorProvider) Json(io.swagger.v3.core.util.Json) GenericResponseService(org.springdoc.core.GenericResponseService) AbstractRouterFunctionVisitor(org.springdoc.core.fn.AbstractRouterFunctionVisitor) OPERATION_ATTRIBUTE(org.springdoc.core.Constants.OPERATION_ATTRIBUTE) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) SpecFilter(io.swagger.v3.core.filter.SpecFilter) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) ArrayList(java.util.ArrayList) LINKS_SCHEMA_CUSTOMISER(org.springdoc.core.Constants.LINKS_SCHEMA_CUSTOMISER) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SortedSchemaMixin(org.springdoc.api.mixins.SortedSchemaMixin) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) OpenAPIService(org.springdoc.core.OpenAPIService) AbstractRequestService(org.springdoc.core.AbstractRequestService) Schema(io.swagger.v3.oas.models.media.Schema) SpringDocProviders(org.springdoc.core.SpringDocProviders) OpenApiCustomiser(org.springdoc.core.customizers.OpenApiCustomiser) GenericParameterService(org.springdoc.core.GenericParameterService) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) SpringDocConfigProperties(org.springdoc.core.SpringDocConfigProperties) Logger(org.slf4j.Logger) RouterFunctionData(org.springdoc.core.fn.RouterFunctionData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PathItem(io.swagger.v3.oas.models.PathItem) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Callback(io.swagger.v3.oas.annotations.callbacks.Callback) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ApplicationContext(org.springframework.context.ApplicationContext) GroupConfig(org.springdoc.core.SpringDocConfigProperties.GroupConfig) ReflectionUtils(io.swagger.v3.core.util.ReflectionUtils) ObjectFactory(org.springframework.beans.factory.ObjectFactory) Components(io.swagger.v3.oas.models.Components) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) SPRING_MVC_SERVLET_PATH(org.springdoc.core.Constants.SPRING_MVC_SERVLET_PATH) Collections(java.util.Collections) RouterOperations(org.springdoc.core.annotations.RouterOperations) ArrayList(java.util.ArrayList) RouterOperation(org.springdoc.core.fn.RouterOperation) ApplicationContext(org.springframework.context.ApplicationContext)

Aggregations

Map (java.util.Map)2 AbstractRouterFunctionVisitor (org.springdoc.core.fn.AbstractRouterFunctionVisitor)2 JsonView (com.fasterxml.jackson.annotation.JsonView)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Feature (com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature)1 SpecFilter (io.swagger.v3.core.filter.SpecFilter)1 Json (io.swagger.v3.core.util.Json)1 ReflectionUtils (io.swagger.v3.core.util.ReflectionUtils)1 Yaml (io.swagger.v3.core.util.Yaml)1 Hidden (io.swagger.v3.oas.annotations.Hidden)1 Callback (io.swagger.v3.oas.annotations.callbacks.Callback)1 ParameterIn (io.swagger.v3.oas.annotations.enums.ParameterIn)1 Components (io.swagger.v3.oas.models.Components)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 Operation (io.swagger.v3.oas.models.Operation)1