Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide endpoints from OpenAPI documentation with Springdoc

Springdoc automatically generates a API documentation for all handler methods. Even if there are no OpenAPI annotations.

How can I hide endpoints from the API documentation?

like image 266
Matt Ke Avatar asked Dec 21 '25 08:12

Matt Ke


1 Answers

The @io.swagger.v3.oas.annotations.Hidden annotation can be used at the method or class level of a controller to hide one or all endpoints.

(See: https://springdoc.org/faq.html#how-can-i-hide-an-operation-or-a-controller-from-documentation)

Example:

@Hidden // Hide all endpoints
@RestController
@RequestMapping(path = "/test")
public class TestController {

    private String test = "Test";

    @Operation(summary = "Get test string", description = "Returns a test string", tags = { "test" })
    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success" ) })
    @GetMapping(value = "", produces = MediaType.TEXT_PLAIN_VALUE)
    public @ResponseBody String getTest() {
        return test;
    }

    @Hidden // Hide this endpoint
    @PutMapping(value = "", consumes = MediaType.TEXT_PLAIN_VALUE)
    @ResponseStatus(HttpStatus.OK)
    public void setTest(@RequestBody String test) {
        this.test = test;
    }

}

Edit:

It's also possible to generate the API documentation only for controllers of specific packages.

Add following to your application.properties file:

springdoc.packagesToScan=package1, package2

(See: https://springdoc.org/faq.html#how-can-i-explicitly-set-which-packages-to-scan)

like image 106
Matt Ke Avatar answered Dec 23 '25 22:12

Matt Ke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!