0

Is there any way to hide the controller name in the swagger-ui.

enter image description here

My class is like this. I do not want my controller name on the ui.

@Api(tags = {"group"})
public class MyControllerName {}

I did check some existing answers. for ex: How to remove controller list from Swagger UI did not help at all.

RamPrakash
  • 2,218
  • 3
  • 25
  • 54

3 Answers3

0

Create Docket bean and assign to it custom ApiInfo object, in this way:

@Bean
public Docket api() {                
    return new Docket(DocumentationType.SWAGGER_2)          
      .select()
      .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
      .paths(PathSelectors.ant("/foos/*"))
      .build()
      .apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
    return new ApiInfo(
      "My REST API", 
      "Some custom description of API.", 
      "API TOS", 
      "Terms of service", 
      new Contact("John Doe", "www.example.com", "myeaddress@company.com"), 
      "License of API", "API license URL", Collections.emptyList());
}
tohhant
  • 103
  • 10
0

You can exclude any controller:

import { Controller, Get } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { AppService } from './app.service';

@ApiExcludeController()
@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
}
Luiggi
  • 358
  • 4
  • 12
-1

This sould be good feature request to springfox team. If you need to customize the swagger-UI you should be doing it on your own.

Maybe the below steps are useful for someone.

  1. Go to https://github.com/swagger-api/swagger-ui
  2. Download the latest code
  3. customize whatever you want to customize
  4. package either as a web jar or as resources in your application
  5. create resource handler mapping if required

Refer - https://github.com/springfox/springfox/issues/1108

Sibin Rasiya
  • 1,132
  • 1
  • 11
  • 15