spring-data-rest icon indicating copy to clipboard operation
spring-data-rest copied to clipboard

Hide DELETE method for associations

Open AresEkb opened this issue 2 years ago • 0 comments

According to this answer https://stackoverflow.com/questions/28679934/why-is-delete-not-supported-on-to-many-association-resources-in-spring-data-rest DELETE method not supported for OneToMany and ManyToMany associations. It returns 405 Method not allowed. But this method is visible in Swagger UI and confuses people. Is it possible to hide it?

The following has no any effect:

    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
        config.getExposureConfiguration()
                .withAssociationExposure((metadata, methods) -> methods.disable(HttpMethod.DELETE))
                .withCollectionExposure((metadata, methods) -> methods.disable(HttpMethod.DELETE));
    }

The following disables all delete methods, but I need to disable it for assocations only:

    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
        config.getExposureConfiguration()
                .withItemExposure((metadata, methods) -> methods.disable(HttpMethod.DELETE));
    }

It seems that .withAssociationExposure() is never called.

AresEkb avatar Aug 24 '22 03:08 AresEkb