Skip to content

Collection methods are added to the supported entity methods #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bschoenmaeckers opened this issue Mar 14, 2021 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@bschoenmaeckers
Copy link

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.

@bnasslahsen
Copy link
Collaborator

@bschoenmaeckers,

I have added a fix for it.
You can test it using the latest snapshot.

This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants