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.

Babita Bisht
  • 385
  • 1
  • 4
  • 18

7 Answers7

11

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>
Debmalya Jash
  • 301
  • 1
  • 11
  • 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? – hadiroudsari Feb 24 '22 at 16:48
11

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

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Rohit Jakhar
  • 1,231
  • 2
  • 12
  • 21
Amit
  • 111
  • 1
  • 2
4

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

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

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);
}
Sachith Wickramaarachchi
  • 5,546
  • 6
  • 39
  • 68
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/**".

João Dias
  • 16,277
  • 6
  • 33
  • 45
  • I tried adding spring.mvc.pathpattern.matching-strategy=ant_path_matcher but it did not work – Georgian Benetatos Nov 20 '21 at 16:19
  • Have you tried the second approach? Changing your path configuration to something like `"/webjars/swagger-ui/**"`. – João Dias Nov 20 '21 at 19:25
  • 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-matcher`` – Sven Döring Jan 19 '23 at 21:37
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.

Haroldo_OK
  • 6,612
  • 3
  • 43
  • 80
0

I added this line my side is working application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 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](/help/how-to-answer). – Community Feb 21 '23 at 14:06