Invalid mapping pattern detected: /**/swagger-ui/**
Asked Answered
A

8

10

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.

Avow answered 22/9, 2021 at 11:33 Comment(2)
Have you tried to specify swagger path directly through properties file: springdoc.swagger-ui.path=/swagger-ui.htmlAciniform
@Aciniform - yes I have tried that also but no luckAvow
S
13

I added below line in my app application.properties that worked for me.

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Sextodecimo answered 21/1, 2022 at 15:10 Comment(0)
C
12

With following dependencies, solved this issue.

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.0</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.5.12</version>
</dependency>
Christinchristina answered 20/11, 2021 at 0:11 Comment(1)
It failed the build for me due o Relying upon circular references is discouraged and they are prohibited by default. Is it a good Idea to allow circular dependency?Eleonoreleonora
B
4

The above item works spring.mvc.pathpattern.matching-strategy=ant_path_matcher

However, it should be ant-path-matcher - dashes not underscores

Brim answered 7/1, 2022 at 19:41 Comment(0)
S
2

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);
}
Statuesque answered 22/9, 2021 at 11:47 Comment(3)
Where do I need to to add this code ?Avow
@BabitaBisht see how u config your web config fileStatuesque
I am new to spring boot, where will I find this web config file ?Avow
N
1

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/**".

Nutshell answered 22/9, 2021 at 14:49 Comment(3)
I tried adding spring.mvc.pathpattern.matching-strategy=ant_path_matcher but it did not workDiablerie
Have you tried the second approach? Changing your path configuration to something like "/webjars/swagger-ui/**".Subtile
The second approach worked for me. (I updated from Spring Boot 2.5 to 2.7. Since 2.6 the PathPatternParser is the default.) Try this property instead: spring.mvc.pathmatch.matching-strategy=ant-path-matcherConstructive
B
1

In my case, I was using old versions of springdoc-openapi-ui springdoc-openapi-data-rest, which happened to be incompatible with the latest version of Spring Boot. Looking up for the most recent maven package on https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui and using that version, solved the problem.

Blasphemy answered 21/2, 2022 at 14:14 Comment(0)
S
0

I added this line my side is working application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Sweatshop answered 17/2, 2023 at 7:46 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Frisk
A
0

In my case springdoc-openapi-ui was in outstanding module. And I just exclude springdoc-openapi-ui.

    <dependency>
        <groupId>some.group</groupId>
        <artifactId>some.artifact</artifactId>
        <version>LATEST</version>
        <exclusions>
            <exclusion>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-ui</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Archivist answered 14/9, 2023 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.