Allow to set up the base path in the Docket configuration (Springfox 3.0.0-SNAPSHOT)
See original GitHub issue- Version 3.0.0-SNAPSHOT
- Feature Request
I am using Springfox 3.0.0-SNAPSHOT in a Spring Boot 2.1.1 WebMvc project. It generates a documentation with basePath : “/” and paths like: /myapp/api/v1/customers. What I would like is basePath: “/myapp” and paths /api/v1/customers.
I have searched for information about how to customize the base path and the endpoints, found this issue where jonaskoperdraat provides a solution and tried it:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.host("localhost:8081")
.pathProvider(new PathProvider() {
private final String ROOT = "/myapp";
@Override
public String getOperationPath(String operationPath) {
return operationPath.replace(ROOT, "");
}
@Override
public String getResourceListingPath(String groupName, String apiDeclaration) {
return null;
}
})
My new paths are ok: /api/v1/customers, but the base path keeps being “/”. I noticed the suggestion of explicitly setting Docket().host() but it didn’t work either.
I have debugged the source code and found this on startup springfox.documentation.spring.web.scanners.ApiDocumentationScanner:
public Documentation scan(DocumentationContext context) {
ApiListingReferenceScanResult result = apiListingReferenceScanner.scan(context);
ApiListingScanningContext listingContext = new ApiListingScanningContext(context,
result.getResourceGroupRequestMappings());
Map<String, List<ApiListing>> apiListings = apiListingScanner.scan(listingContext);
Set<Tag> tags = toTags(apiListings);
tags.addAll(context.getTags());
DocumentationBuilder group = new DocumentationBuilder()
.name(context.getGroupName())
.apiListingsByResourceGroupName(apiListings)
.produces(context.getProduces())
.consumes(context.getConsumes())
.host(context.getHost())
.schemes(context.getProtocols())
.basePath(ROOT)
.extensions(context.getVendorExtentions())
.tags(tags);
As you can see there’s an explicit .base(ROOT) invocation. Couldn’t DocumentationContext offer a context.getBasePath() method that was set based on another Docket().basePath() operation?
If not, what’s the way to customize this?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:16 (1 by maintainers)

Top Related StackOverflow Question
My simple workaround, but I really hope 3.0.0 will released soon 😉
can someone please reopen this issue?
I keeps me from updating to v3.