'No operations defined in spec! while specifying multiple paths in swagger ui

I want to display two REST API endpoints in Swagger ui: /cart and /post.

When I specify either /cart or /post works fine but with both showing me error as

No operations defined in spec!

in swagger-ui

@Bean
public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.ant("/cart"))
        .paths(PathSelectors.ant("/post"))
        .build();
}


Solution 1:[1]

Another option is to use .paths(PathSelectors.any()) instead of .paths(PathSelectors.ant("/cart")) and .paths(PathSelectors.ant("/post"))

Solution 2:[2]

With Spring boot 2.6.x you also need:

spring:  
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

Solution 3:[3]

It because you use AND condition

  public ApiSelectorBuilder paths(Predicate<String> selector) {
    pathSelector = pathSelector.and(selector);
    return this;
  }

you can combine conditions by using OR clause

.paths(PathSelectors.ant("/cart").or(PathSelectors.ant("/post")))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cesar Nicolás Cabo
Solution 2 Peyman
Solution 3 Arthur Gazizov