Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Spring API

I am using Spring Swagger library v1.0.2

Maven:

<dependency>
    <groupId>com.mangofactory</groupId>
    <artifactId>swagger-springmvc</artifactId>
    <version>1.0.2</version>
</dependency>

I am able to scan my REST APIs and view it on the Swagger UI. I have even implemented OAuth and it is working great.

However, there is one feature that I need to implement. I want to hide some of the REST APIs. I need to do this at the class level as well as on the method level. I read about an 'hidden' attribute in the @Api annotation. I set it to 'true' but I can still see my class and all its method being displayed in the Swagger UI.

Example:

 @Api( 
        description="This class is not covered by Spring security.", 
        value="/unauthorize",
        hidden=true)
 @RequestMapping("/unauthorize")
 @Controller
 public class UnauthorizeResource {}

Can someone please tell me how I can prevent the 'UnauthorizeResource' class from being displayed?

like image 798
Raj Avatar asked Sep 17 '15 14:09

Raj


People also ask

What is Swagger API in spring boot?

Swagger2 is an open source project used to generate the REST API documents for RESTful web services. It provides a user interface to access our RESTful web services via the web browser.

What is Swagger API used for?

Swagger helps users build, document, test and consume RESTful web services. It can be used with both a top-down and bottom-up API development approach. In the top-down, or design-first, method, Swagger can be used to design an API before any code is written.

Does Swagger have an API?

The ability of APIs to describe their own structure is the root of all awesomeness in Swagger. Why is it so great? Well, by reading your API's structure, we can automatically build beautiful and interactive API documentation.


1 Answers

You can utilize the @ApiIgnore annotation:

@ApiIgnore
@RequestMapping("/unauthorize")
@Controller
public class UnauthorizeResource {}
like image 133
Dragan Bozanovic Avatar answered Oct 29 '22 18:10

Dragan Bozanovic