Skip to content

@RepositoryRestResource enhancement #1484

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
migueltercero opened this issue Jan 31, 2022 · 2 comments
Closed

@RepositoryRestResource enhancement #1484

migueltercero opened this issue Jan 31, 2022 · 2 comments
Labels
wontfix This will not be worked on

Comments

@migueltercero
Copy link

Describe the bug
When document spring data rest repositories with @RepositoryRestResource, methods declared by CrudRepository or PagingAndSortingRepository are ignored by springdoc. Custom methods works fine.

To Reproduce

Declare RepositoryRestResource repository, and annotate method inherit from PagingAndSourtingRepository, for example, findById with @Operation or @ApiResponses:

@RepositoryRestResource(collectionResourceRel = "people", path = "peopleme")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
	
	@Operation(summary = "find by id")
	@ApiResponses(
			value = {
					@ApiResponse(responseCode = "200", description = "successful operation"),
					@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
					@ApiResponse(responseCode = "404", description = "Contact not found"),
					@ApiResponse(responseCode = "405", description = "Validation exception") }
	)
	@RestResource
	Optional<Person> findById(Long id);

Expected behavior

When call to /v3/api-docs, paths['/peopleme/{id}'].get.description must be description declared by @Operation annotation.

	@Test
	void given_repositoryRestResource_when_getApiDocs_then_findByIdDocumentationOk() {
		// @formatter:off
		given()
		.when()
			.get("/v3/api-docs")
		.then()
			.status(HttpStatus.OK)
			.rootPath("paths['/peopleme/{id}']")
				.body("get.description", equalTo("find by id"));
		// @formatter:on
	}

You can check issue in:

https://github.com/migueltercero/springdoc-issue

https://github.com/migueltercero/springdoc-issue/blob/master/src/test/java/test/org/springdoc/api/app21/PersonRepositoryTest.java

@bnasslahsen bnasslahsen changed the title @RepositoryRestResource problem @RepositoryRestResource enhancement Jan 31, 2022
@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Jan 31, 2022

@migueltercero,

This has never been supported. As the majority of use cases, people do not override the base repositories !
They only add the search methods, which are supported out of the box.
See the initial support here for more details

Your proposal doesn't look achievable with the current implementation.
For example, how would you address: The save / patch / put endpoints which are different per entity, but relies on the same repository method save(S entity)?

If you find a solution for that, feel free to propose directly a PR.

Note that the only Straightforward solution, where you can add your desired changes at the operation level for the spring-data-rest existing endpoints is OpenApiCustomiser.

@bnasslahsen bnasslahsen added enhancement New feature or request wontfix This will not be worked on and removed enhancement New feature or request labels Jan 31, 2022
@migueltercero
Copy link
Author

Thank you for your quickly response!!!

People must override base repositories for security reasons. For example, if you want control wich methods must be exposed or not:

https://docs.spring.io/spring-data/rest/docs/current/reference/html/#getting-started.setting-repository-detection-strategy

And perhaps findById isn´t the best example. For example, method Page<T> findAll(Predicate predicate, Pageable pageable);
is from base repository QuerydslPredicateExecutor from spring data:

@RestResource
Page<T> findAll(Predicate predicate, Pageable pageable);

When use queryDSL, you need document Predicate options, is not trivial like save/ path / put. You need to specify wich param supports, type ...

I know that can be documented use OpenApiCustomiser, but isn´t the best option. Support open api annotations in this methods would be great!!

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants