Reputation: 129
I'm using spring-data-rest and I have a JpaRepository like this:
@RepositoryRestResource(path = "projects")
public interface ProjectsRepository extends JpaRepository<MetricsProjects, Integer> {...}
My repository interface:
@RepositoryRestResource(path = "projects")
public interface ProjectsRepository extends JpaRepository<MetricsProjects, Integer> {
List<MetricsProjects> findByProjectName(String projectName);
@Override
@RestResource(exported = false)
public void deleteById(Integer id);
@Override
@RestResource(exported = false)
public void delete(MetricsProjects entity);
@Override
@RestResource(exported = false)
public void deleteAll(Iterable<? extends MetricsProjects> entities);
@Override
@RestResource(exported = false)
public void deleteAll();
@Override
@RestResource(exported = false)
public void deleteInBatch(Iterable<MetricsProjects> entities);
@Override
@RestResource(exported = false)
public void deleteAllInBatch();
}
I've also added disableDefaultExposure() , as suggested somewhere.
My Configuration file:
@Configuration
public class SpringDataRestConfiguration implements RepositoryRestConfigurer {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration restConfig) {
restConfig.disableDefaultExposure();
}
}
But I still see the DELETE methods exposed from my Swagger-UI, how do I prevent this?
Upvotes: 3
Views: 868
Reputation: 754
Modify the configureRepositoryRestConfiguration
to
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration restConfig) {
restConfig.getExposureConfiguration()
.forDomainType(put the class type here)
.withItemExposure((metadata, httpMethods) -> httpMethods.disable(HttpMethod.DELETE))
.withCollectionExposure((metadata, httpMethods) -> httpMethods.disable(HttpMethod.DELETE));
}
Replace put the class type here with the className.class, for example if the className is MetricsProjects, put MetricsProjects.class there.
Upvotes: 1
Reputation: 1
To disable the display of a specific endpoint in Swagger (Springfox library), I have added the annotation ApiIgnore on the associated method in repository class :
@Override
@ApiIgnore
@RestResource(exported = false)
public void deleteById(Integer id);
Upvotes: 0
Reputation: 3423
Create a controller method for the DELETE endpoint and return 405 Method Not Allowed.
Upvotes: 0