Search in sources :

Example 1 with ActuatorOperationCustomizer

use of org.springdoc.core.customizers.ActuatorOperationCustomizer in project jhipster-bom by jhipster.

the class JHipsterSpringDocGroupsConfiguration method openAPIDefaultGroupedOpenAPI.

/**
 * OpenApi default group configuration.
 *
 * @return the GroupedOpenApi configuration
 */
@Bean
@ConditionalOnMissingBean(name = "openAPIDefaultGroupedOpenAPI")
public GroupedOpenApi openAPIDefaultGroupedOpenAPI(List<OpenApiCustomiser> openApiCustomisers, List<OperationCustomizer> operationCustomizers, @Qualifier("apiFirstGroupedOpenAPI") Optional<GroupedOpenApi> apiFirstGroupedOpenAPI, SpringDocConfigProperties springDocConfigProperties) {
    log.debug("Initializing JHipster OpenApi default group");
    Builder builder = GroupedOpenApi.builder().group(DEFAULT_GROUP_NAME).pathsToMatch(properties.getDefaultIncludePattern());
    openApiCustomisers.stream().filter(customiser -> !(customiser instanceof ActuatorOpenApiCustomizer)).forEach(builder::addOpenApiCustomiser);
    operationCustomizers.stream().filter(customiser -> !(customiser instanceof ActuatorOperationCustomizer)).forEach(builder::addOperationCustomizer);
    apiFirstGroupedOpenAPI.ifPresent(apiFirst -> {
        if (apiFirst.getPackagesToScan() != null) {
            apiFirst.getPackagesToScan().stream().forEach(builder::packagesToExclude);
        }
    });
    return builder.build();
}
Also used : ActuatorOpenApiCustomizer(org.springdoc.core.customizers.ActuatorOpenApiCustomizer) OperationCustomizer(org.springdoc.core.customizers.OperationCustomizer) Builder(org.springdoc.core.GroupedOpenApi.Builder) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) JHipsterOpenApiCustomizer(tech.jhipster.config.apidoc.customizer.JHipsterOpenApiCustomizer) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ByteBuffer(java.nio.ByteBuffer) Value(org.springframework.beans.factory.annotation.Value) JHipsterProperties(tech.jhipster.config.JHipsterProperties) DEFAULT_GROUP_NAME(org.springdoc.core.Constants.DEFAULT_GROUP_NAME) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SpringDocUtils.getConfig(org.springdoc.core.SpringDocUtils.getConfig) OpenApiCustomiser(org.springdoc.core.customizers.OpenApiCustomiser) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) SpringDocConfigProperties(org.springdoc.core.SpringDocConfigProperties) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Logger(org.slf4j.Logger) GroupedOpenApi(org.springdoc.core.GroupedOpenApi) Info(io.swagger.v3.oas.models.info.Info) Configuration(org.springframework.context.annotation.Configuration) SPRINGDOC_SHOW_ACTUATOR(org.springdoc.core.Constants.SPRINGDOC_SHOW_ACTUATOR) List(java.util.List) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) ActuatorOperationCustomizer(org.springdoc.core.customizers.ActuatorOperationCustomizer) ActuatorOpenApiCustomizer(org.springdoc.core.customizers.ActuatorOpenApiCustomizer) Builder(org.springdoc.core.GroupedOpenApi.Builder) ActuatorOperationCustomizer(org.springdoc.core.customizers.ActuatorOperationCustomizer) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ActuatorOperationCustomizer

use of org.springdoc.core.customizers.ActuatorOperationCustomizer in project springdoc-openapi by springdoc.

the class SpringdocActuatorBeanFactoryConfigurer method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    final BindResult<WebEndpointProperties> result = Binder.get(environment).bind(MANAGEMENT_ENDPOINTS_WEB, WebEndpointProperties.class);
    if (result.isBound()) {
        WebEndpointProperties webEndpointProperties = result.get();
        List<GroupedOpenApi> newGroups = new ArrayList<>();
        ActuatorOpenApiCustomizer actuatorOpenApiCustomiser = new ActuatorOpenApiCustomizer(webEndpointProperties);
        beanFactory.registerSingleton("actuatorOpenApiCustomiser", actuatorOpenApiCustomiser);
        ActuatorOperationCustomizer actuatorCustomizer = new ActuatorOperationCustomizer();
        beanFactory.registerSingleton("actuatorCustomizer", actuatorCustomizer);
        GroupedOpenApi actuatorGroup = GroupedOpenApi.builder().group(ACTUATOR_DEFAULT_GROUP).pathsToMatch(webEndpointProperties.getBasePath() + ALL_PATTERN).pathsToExclude(webEndpointProperties.getBasePath() + HEALTH_PATTERN).addOperationCustomizer(actuatorCustomizer).addOpenApiCustomiser(actuatorOpenApiCustomiser).build();
        // Add the actuator group
        newGroups.add(actuatorGroup);
        if (CollectionUtils.isEmpty(groupedOpenApis)) {
            GroupedOpenApi defaultGroup = GroupedOpenApi.builder().group(DEFAULT_GROUP_NAME).pathsToMatch(ALL_PATTERN).pathsToExclude(webEndpointProperties.getBasePath() + ALL_PATTERN).build();
            // Register the default group
            newGroups.add(defaultGroup);
        }
        newGroups.forEach(elt -> beanFactory.registerSingleton(elt.getGroup(), elt));
    }
    initBeanFactoryPostProcessor(beanFactory);
}
Also used : ActuatorOpenApiCustomizer(org.springdoc.core.customizers.ActuatorOpenApiCustomizer) WebEndpointProperties(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties) ArrayList(java.util.ArrayList) ActuatorOperationCustomizer(org.springdoc.core.customizers.ActuatorOperationCustomizer)

Aggregations

ActuatorOpenApiCustomizer (org.springdoc.core.customizers.ActuatorOpenApiCustomizer)2 ActuatorOperationCustomizer (org.springdoc.core.customizers.ActuatorOperationCustomizer)2 Info (io.swagger.v3.oas.models.info.Info)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DEFAULT_GROUP_NAME (org.springdoc.core.Constants.DEFAULT_GROUP_NAME)1 SPRINGDOC_SHOW_ACTUATOR (org.springdoc.core.Constants.SPRINGDOC_SHOW_ACTUATOR)1 GroupedOpenApi (org.springdoc.core.GroupedOpenApi)1 Builder (org.springdoc.core.GroupedOpenApi.Builder)1 SpringDocConfigProperties (org.springdoc.core.SpringDocConfigProperties)1 SpringDocUtils.getConfig (org.springdoc.core.SpringDocUtils.getConfig)1 OpenApiCustomiser (org.springdoc.core.customizers.OpenApiCustomiser)1 OperationCustomizer (org.springdoc.core.customizers.OperationCustomizer)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Value (org.springframework.beans.factory.annotation.Value)1