28

I'm using springfox-swagger-ui 2.8.0 which ships with Swagger UI 3.7.0.

I want to get rid of the controller list in front of the api documentation page, pretty useless for me (every tab is empty).

I've already tried to annotate the controller class with @ApiIgnore, but of course this removes the rest api documentation as well, which I need.

Basically, I want to remove this:

Controller list to remove/hide

while keeping this:

REST api docs to keep

I digged through online docs, GitHub issues, StackOverflow questions, Google... nothing. Am I the only with this request?

think01
  • 681
  • 1
  • 10
  • 22

7 Answers7

32

Try this attribute on the controller

[ApiExplorerSettings(IgnoreApi = true)]

Victor Oniagba
  • 441
  • 1
  • 4
  • 8
  • If you're using ASPCore and need to assure the route is not accessible, add `app.Map("/api/values", delegate { });` to method `Configure` in `Startup.cs` – Adam Cox Mar 31 '19 at 03:02
  • 1
    Don't know if this attribute works in Java, but in ASP.Net Core 2.2 it works nice. The controller is still accessible via URL, but it's hidden from the swagger output. – ArieKanarie Jun 17 '19 at 11:02
  • Is there a way to add this dynamically at run-time? – JohnOpincar Jun 23 '21 at 12:59
13

Add the attribute description to @Api:

For example:

@Api(value = "Test API Controller", produces = MediaType.APPLICATION_JSON_VALUE, tags = {"test-api-controller"}, description = "Testing API") 
Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
Navin
  • 146
  • 1
  • 3
  • 2
    I already had the description attribute (and it's marked as deprecated). Removing it changes nothing :-( – think01 Jun 08 '18 at 13:56
  • 6
    YES! Your hint led me to the right solution: adding @Api(tags = {"MagazzinoPF"}) to the implementation class. This someway "merges" the empty documentation line to the actual documentation below. If you modify your answer, I'll accept it. Thanks! – think01 Jun 08 '18 at 14:01
  • 1
    @think01 Solved my problem too. Do you think there is a way to add this when generating swagger code itself? – NuttLoose Sep 03 '18 at 11:30
  • @NuttLoose uhm, good idea, unfortunately I don't know how to achieve that. I'll look about it, if you find the way, please share it here ;-) – think01 Sep 04 '18 at 12:46
  • @think01 Will do. – NuttLoose Sep 05 '18 at 03:57
  • it hides both in 2.9.2 – Andrew Sneck May 22 '20 at 14:32
  • Are there any options to hide this on the generated swagger code? – Manoj Kumar S Mar 16 '21 at 05:52
  • its not clear from the ans, using the same tag name on some controllers will merge all apis under them to a single grouping ```@Api(tags = {"GroupingName"}``` – Akshay May 23 '22 at 14:19
3

on springfox v3.0 tried almost every annotations and finally
@ApiIgnore annotation works.
Don't know why @Api(hidden=true) doesn't work.

import springfox.documentation.annotations.ApiIgnore;
@ApiIgnore
@Responsebody
public Object ...{}
Shane Park
  • 81
  • 4
0

I expected the hidden attribute will work but it doesn't. I also tried to set description and also doesn't work.

Another solution is to use the tag in the @Api can help you temporarily hide this rest-controllers list and categorize your APIs in different tags.

Tran Ho
  • 1,442
  • 9
  • 15
0

Set the attribute at controller level [ApiExplorerSettings(IgnoreApi = true)]

To hide the property just use [JsonIgnore] i.e., namespace system.text.json.serialization

Maulik Boghara
  • 129
  • 1
  • 5
0

If you are using the OpenAPI @ApiIgnore and @Api annotations may not work.

Use @Hidden annotation on the controller you want swagger-ui to ignore/exclude and thank me later.

Happy coding :)

-2

springfox api version 2.9.2

works with the below example by adding on a controller class

@Api(value = "Test API Controller", tags = {"test-api-controller"}, description = "Testing API")

  • 2
    Someone already made the same answer: https://stackoverflow.com/a/50739276/5022959 Please don't answer on a closed question with the same answer as the accepted answer. – Nicola Uetz Mar 13 '20 at 17:48