Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude a Spring Data REST controller from the generated OpenAPI documentation

I am working with a Spring Data MongoDB project which exports its endpoints via Spring Data REST. It uses the springdoc-openapi-data-rest module of the springdoc-openapi library to generate an OpenAPI interface description for the Spring Data REST endpoints in project.

I have a repository endpoint that I would like to exclude from the generated OpenAPI document.

@Repository
public interface ExcludeMeRepository extends
        PagingAndSortingRepository<ExcludeMe, Integer> {}

If this were a Spring MVC controller being included via springdoc-openapi-ui, I could use the @Hidden annotation from the Swagger Annotations library on the controller. However, this does not appear to work when put on a @Repository class.

@Hidden // Does not appear to have an effect
@Repository
public interface ExcludeMeRepository extends
        PagingAndSortingRepository<ExcludeMe, Integer> {}

I have tried out a few things, but haven't found anything that works that doesn't also feel like a hacky workaround.

How can a respository be excluded from the generated OpenAPI document?

like image 932
M. Justin Avatar asked Jul 26 '26 02:07

M. Justin


1 Answers

The @Hidden annotation is now supported as of the v2.0.0 version of springdoc-openapi. This change was added per springdoc-openapi#1881.

@Hidden // Works as of v2.0.0
@Repository
public interface ExcludeMeRepository extends
        PagingAndSortingRepository<ExcludeMe, Integer> {}
like image 184
M. Justin Avatar answered Jul 28 '26 17:07

M. Justin



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!