Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
}
like image 968
Navin Gelot Avatar asked May 11 '18 11:05

Navin Gelot


People also ask

How does Swagger define operations?

operationId is an optional unique string used to identify an operation. If provided, these IDs must be unique among all operations described in your API. /users: operationId: getUsers. summary: Gets all users.

How many operations can be tested using swagger UI?

Swagger 2.0 supports get , post , put , patch , delete , head , and options . A single path can support multiple operations, for example, GET /users to get a list of users and POST /users to add a new user. Swagger defines a unique operation as a combination of a path and an HTTP method.

Is Swagger deprecated?

The Swagger API interface in the AppDynamics Platform is deprecated starting version 4.5. 15.


2 Answers

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

like image 114
Cesar Nicolás Cabo Avatar answered Sep 30 '22 13:09

Cesar Nicolás Cabo


With Spring boot 2.6.x you also need:

spring:  
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
like image 34
Peyman Avatar answered Sep 30 '22 13:09

Peyman