How to remove controller list from Swagger UI
Asked Answered
S

7

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?

Severson answered 8/5, 2018 at 8:52 Comment(2)
This sould be good feature request on springfox teamHelpmeet
See this answer, I tried and it works.Sterlingsterlitamak
A
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") 
Amaliaamalie answered 7/6, 2018 at 10:46 Comment(9)
I already had the description attribute (and it's marked as deprecated). Removing it changes nothing :-(Severson
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!Severson
@think01 Solved my problem too. Do you think there is a way to add this when generating swagger code itself?Fredericafrederich
@Fredericafrederich 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 ;-)Severson
@think01 Will do.Fredericafrederich
it hides both in 2.9.2Helpmeet
Are there any options to hide this on the generated swagger code?Merganser
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"}Perse
It hides also in 3.0.0. Thanks a lot for this!Lodmilla
S
33

Try this attribute on the controller

[ApiExplorerSettings(IgnoreApi = true)]

Spain answered 15/2, 2019 at 22:13 Comment(3)
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.csIronwood
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.Polygraph
Is there a way to add this dynamically at run-time?Hormonal
A
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") 
Amaliaamalie answered 7/6, 2018 at 10:46 Comment(9)
I already had the description attribute (and it's marked as deprecated). Removing it changes nothing :-(Severson
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!Severson
@think01 Solved my problem too. Do you think there is a way to add this when generating swagger code itself?Fredericafrederich
@Fredericafrederich 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 ;-)Severson
@think01 Will do.Fredericafrederich
it hides both in 2.9.2Helpmeet
Are there any options to hide this on the generated swagger code?Merganser
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"}Perse
It hides also in 3.0.0. Thanks a lot for this!Lodmilla
S
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 ...{}
Sena answered 16/3, 2022 at 5:15 Comment(0)
B
1

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 :)

Bullard answered 31/7, 2023 at 14:16 Comment(0)
O
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.

Owen answered 6/8, 2020 at 7:33 Comment(0)
J
0

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

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

Jola answered 21/2, 2023 at 5:45 Comment(0)
K
-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")

Kinase answered 13/3, 2020 at 17:35 Comment(1)
Someone already made the same answer: https://mcmap.net/q/490885/-how-to-remove-controller-list-from-swagger-ui Please don't answer on a closed question with the same answer as the accepted answer.Campney

© 2022 - 2024 — McMap. All rights reserved.