I am using springdoc-openapi-ui for spring boot API documentation and facing the following issue -
I have added all the necessary configuration as follows -
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.2</version>
</dependency>
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.
Invalid mapping pattern detected: / /swagger-ui/ ^ No more pattern data allowed after {*...} or ** pattern element Fix this pattern in your application or switch to the legacy parser implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.
Swagger UI. Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy...
To use Swagger UI, we need to add an additional Maven dependency: Now we can test it in our browser by visiting: The result should look something like this: 5.2. Exploring Swagger Documentation
11. Conclusion In this article, we set up Swagger 2 to generate documentation for a Spring REST API. We also explored ways to visualize and customize Swagger's output. And finally, we looked at a simple OAuth configuration for Swagger. The full implementation of this tutorial can be found in the GitHub project.
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>
I added below line in my app application.properties that worked for me.
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
The above item works
spring.mvc.pathpattern.matching-strategy=ant_path_matcher
However, it should be ant-path-matcher
- dashes not underscores
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);
}
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/**"
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With