How to hide endpoints from Swagger documentation with Springfox

前端 未结 5 1486
深忆病人
深忆病人 2021-01-04 12:03

I have a Spring Boot project with next dependency of Springfox:


    io.springfox
    spri         


        
相关标签:
5条回答
  • 2021-01-04 12:42

    You have added the @ApiIgnore annotation on an interface. It looks like, this annotation doesn't work when added on an interface. (I really don't understand why @Api works on an interface and @ApiIgnore don't.

    0 讨论(0)
  • 2021-01-04 12:47

    Another option is to just remove the @Api completely, and your controller and its methods shouldn't be picked up by swagger.

    0 讨论(0)
  • 2021-01-04 12:48

    One more way is to use @ApiOperation(hidden = true) This can be used at controller/handler level method. E.g.

    @RestController
    public HomeController{
    @ApiOperation(value = "<Your Message>", hidden = true)
        public String getMessage(@RequestParam(value = "msg") final String msg){
            return msg;
        }
    }
    
    0 讨论(0)
  • 2021-01-04 12:54

    The scenario where we want to hide only a particular method(s) from the class. For swagger.v3 there is an annotation with name Hidden in io.swagger.core.v3:swagger-annotations:2.0.10 jar. Methods to be hidden can be annotated with Hidden annotation as shown below. The below method shows the method with DELETE operation which needs to be hidden from the swagger documentation.

    @DELETE
    @Hidden
    public void deleteList(int id) {
    //code goes here.
    }
    
    0 讨论(0)
  • 2021-01-04 12:58

    For OpenAPI3 and SpringBoot:
    I used @Hidden annotation on a method of a controller.
    It seems to work both at method level and controller level.

    @Hidden annotation was imported from using:

    import io.swagger.v3.oas.annotations;
    
    0 讨论(0)
提交回复
热议问题