Search in sources :

Example 1 with RouterOperations

use of org.springdoc.core.annotations.RouterOperations 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)

Example 2 with RouterOperations

use of org.springdoc.core.annotations.RouterOperations in project springdoc-openapi by springdoc.

the class SpringCloudFunctionProvider method getRouterFunctionPaths.

/**
 * Gets router function paths.
 *
 * @param beanName the bean name
 * @return the router function paths
 */
protected RouterOperation getRouterFunctionPaths(String beanName, RequestMethod requestMethod) {
    RouterOperations routerOperations = applicationContext.findAnnotationOnBean(beanName, RouterOperations.class);
    RouterOperation routerOperationResult = null;
    if (routerOperations == null) {
        org.springdoc.core.annotations.RouterOperation routerOperation = applicationContext.findAnnotationOnBean(beanName, org.springdoc.core.annotations.RouterOperation.class);
        if (routerOperation != null)
            routerOperationResult = new RouterOperation(routerOperation);
    } else {
        org.springdoc.core.annotations.RouterOperation[] routerOperationArray = routerOperations.value();
        if (ArrayUtils.isNotEmpty(routerOperationArray)) {
            if (routerOperationArray.length == 1)
                routerOperationResult = new RouterOperation(routerOperationArray[0]);
            else {
                Optional<org.springdoc.core.annotations.RouterOperation> routerOperationOptional = Arrays.stream(routerOperationArray).filter(routerOperation -> Arrays.asList(routerOperation.method()).contains(requestMethod)).findAny();
                if (routerOperationOptional.isPresent())
                    routerOperationResult = new RouterOperation(routerOperationOptional.get(), requestMethod);
            }
        }
    }
    return routerOperationResult;
}
Also used : RouterOperations(org.springdoc.core.annotations.RouterOperations) Arrays(java.util.Arrays) GenericResponseService(org.springdoc.core.GenericResponseService) Parameter(io.swagger.v3.oas.models.parameters.Parameter) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Operation(io.swagger.v3.oas.models.Operation) GET(org.springframework.web.bind.annotation.RequestMethod.GET) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RoutingFunction(org.springframework.cloud.function.context.config.RoutingFunction) Schema(io.swagger.v3.oas.models.media.Schema) RouterOperation(org.springdoc.core.fn.RouterOperation) AntPathMatcher(org.springframework.util.AntPathMatcher) POST(org.springframework.web.bind.annotation.RequestMethod.POST) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) SpringDocConfigProperties(org.springdoc.core.SpringDocConfigProperties) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Content(io.swagger.v3.oas.models.media.Content) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) BeansException(org.springframework.beans.BeansException) ApplicationContext(org.springframework.context.ApplicationContext) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Type(java.lang.reflect.Type) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) FunctionCatalog(org.springframework.cloud.function.context.FunctionCatalog) FunctionInvocationWrapper(org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper) SpringDocAnnotationsUtils(org.springdoc.core.SpringDocAnnotationsUtils) ApplicationContextAware(org.springframework.context.ApplicationContextAware) RouterOperation(org.springdoc.core.fn.RouterOperation) RouterOperations(org.springdoc.core.annotations.RouterOperations)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 Operation (io.swagger.v3.oas.models.Operation)2 Schema (io.swagger.v3.oas.models.media.Schema)2 Parameter (io.swagger.v3.oas.models.parameters.Parameter)2 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)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