Home > Software design >  Invalid mapping pattern detected: /**/swagger-ui/**
Invalid mapping pattern detected: /**/swagger-ui/**

Time:09-23

I am using springdoc-openapi-ui for spring boot API documentation and facing the following issue -

This is the error screen

I have added all the necessary configuration as follows -

  1. The maven dependency -
<dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.5.2</version>
</dependency>
  1. This is the main file -
package com.abc.tl;
    
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@OpenAPIDefinition
public class TLApplication {

    public static void main(String[] args) {

        SpringApplication.run(TLApplication.class, args);

    }
}


Using java version - 11, Not sure where is the Issue, the project is not able to run.

CodePudding user response:

Seems The PathPatternParser doesn't allow ** to appear in the middle, and will reject such a pattern (see more details: https://github.com/spring-projects/spring-boot/issues/21694).

It looks like code here inserted a ** in the middle of the path pattern.

    uiRootPath.append(ALL_PATTERN);
    registry.addResourceHandler(uiRootPath   SWAGGER_UI_PATTERN)

Full code

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    StringBuilder uiRootPath = new StringBuilder();
    if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
        uiRootPath.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
    if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort())
        uiRootPath.append(actuatorProvider.get().getBasePath());

    uiRootPath.append(ALL_PATTERN);
    registry.addResourceHandler(uiRootPath   SWAGGER_UI_PATTERN)
            .addResourceLocations(CLASSPATH_RESOURCE_LOCATION   DEFAULT_WEB_JARS_PREFIX_URL   DEFAULT_PATH_SEPARATOR)
            .resourceChain(false)
            .addTransformer(swaggerIndexTransformer);
}

CodePudding user response:

Somewhere in your code (I would guess in the security configuration) you have configured /**/swagger-ui/**. Recently (Spring 5.3) these path configurations are now analyzed by PathPatternParser (that replaced the old AntPathMatcher that allowed paths just like these).

Either add spring.mvc.pathpattern.matching-strategy=ant_path_matcher to your application.properties as suggested or change the your path configuration to something like "/webjars/swagger-ui/**".

  • Related