Skip to content

Collection methods are added to the supported entity methods #1105

Closed
@bschoenmaeckers

Description

@bschoenmaeckers

Describe the bug
When disabling all single entity access methods and only allowing whole collection endpoints like in the repository bellow. Spring doc will still show a GET method endpoint for a single entity via an ID. The corresponding endpoint will return 405 (Method not allowed) because it is disabled.

generated yaml:

  /notifications:
    get:
      description: get-notification
    ......
  /notifications/{id}:
    get:
      description: get-notification
    ......

To Reproduce
Using springdoc 1.5.4

@RepositoryRestResource
public interface NotificationRepository extends PagingAndSortingRepository<Notification, Long> {

    //This should be the only available endpoint
    @Override
    @RestResource
    List<Notification> findAll();

    @Override
    @RestResource(exported = false)
    Optional<Notification> findById(Long aLong);

    @Override
    @RestResource(exported = false)
    <S extends Notification> S save(S entity);

    @Override
    @RestResource(exported = false)
    void deleteById(Long aLong);
}

Expected behavior
Because the single entity methods are disabled it should not be added to the docs.

  /notifications:
    get:
      description: get-notification
    ......

Additional context
The endpoint is considered enabled because the collection methods are added to the item access methods.

HttpMethods httpMethodsCollection = resourceMetadata.getSupportedHttpMethods().getMethodsFor(ResourceType.COLLECTION);
Set<RequestMethod> requestMethodsCollection = requestMethods.stream().filter(requestMethod -> httpMethodsCollection.contains(HttpMethod.valueOf(requestMethod.toString())))
.collect(Collectors.toSet());
requestMethodsItem.addAll(requestMethodsCollection);

I lack the insight of why this is done in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions