Reputation: 530
I have rest controllers in a spring-boot application.
Project structure:
Controllers
Package1
ControllerClass1.java
ControllerClass2.java
Package2
ControllerClass3.java
ControllerClass4.java
Services
Models
localhost:8080/app/swagger-ui.html shows only one package controllers.
ControllerClass1
Method1 GET
Method2 POST
ControllerClass2
Method1 PUT
Method2 POST
I want to put all controllers from all packages on swagger UI.
Upvotes: 1
Views: 3393
Reputation: 530
It is fixed by adding the base package
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.shivanshu.project"))
.build();
}
Upvotes: 1
Reputation: 13883
you can configure packages and classes you want instructing Swagger which paths to include
.paths(Predicates.or(
PathSelectors.ant("/api/v1/pck1/**"),
PathSelectors.ant("/api/v1/pck2/**"),
PathSelectors.ant("/api/anotherpath/**"))
)
The paths are defined in the Controller (it doesnt matter which package)
package com.example.controller;
@RestController
@RequestMapping("/api/v1/pck1")
public class MyController {
Upvotes: 0