I have two identical @GetMapping, but different from each other by having one parameter. I presented them from below.
@GetMapping
public ResponseEntity<Response> getAll() {
List<Task> tasks = service.findAll();
Response response = TaskGetListResponse.success(tasks);
return convert(response);
}
@GetMapping(params = "name")
public ResponseEntity<Response> getByName(String name) {
List<Task> tasks = service.findSoftlyByName(name);
Response response = TaskGetListResponse.success(tasks);
return convert(response);
}
As you can see, they differ only in the name parameter. Then I connected the maven dependency to automatically configure the REST API - Swagger UI.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
But I get one endpoint that includes two at once. This can be seen by the name parameter, which is located in Parameters.
How do I differentiate into two endpoints?
You can, of course, change the path of the endpoint, but I don't want to change the style of naming the REST API.
This is what the swagger documentation says-
Operations
For each path, you define operations (HTTP methods) that can be used to access that path. OpenAPI 3.0 supports get, post, put, patch, delete, head, options, and trace. A single path can support multiple operations, for example GET /users to get a list of users and POST /users to add a new user. OpenAPI defines a unique operation as a combination of a path and an HTTP method. This means that two GET or two POST methods for the same path are not allowed – even if they have different parameters (parameters have no effect on uniqueness)