Hello, I would suggest this issue for avoid to declare many query strings in method. In Spring is possible transform a methods like this:
// each query string like a method parameter
@GetMapping
public ResponseEntity<SampleResponse> filter(int page, int size, String sort, String direction){
}
in this method with a class with params
// SampleParam class contains all properties used in prior code: int page, int size, String sort, String direction
@GetMapping
public ResponseEntity<SampleResponse> filter(SampleParam params){
}
Spring provide class for build endpoints with many queryString params ( ex.: pagable responses), also we can split params in more class, ex.:
import org.springframework.data.domain.Pageable;
//Pageable is a Spring interface who pack page params (page, size, direction, sort)
//SampleParam could be contains params used for filter results( ex.: filter by name, date, isActive, etc.)
@GetMapping
public ResponseEntity<SampleResponse> filter(SampleParam params, Pageable pageable){
}
another detail, a pageable spring interface use annotations to configure default values when user don't send nothing, ex.:
// annotations define some default values used by pageable implementation provided by spring
@GetMapping
public ResponseEntity<SampleResponse> filter(
@PageableDefault(size = 20)
@SortDefault.SortDefaults({
@SortDefault(sort = "status", direction = Sort.Direction.DESC),
@SortDefault(sort = "nome", direction = Sort.Direction.ASC)
})
Pageable pageable){
}
it's is very helpfull for avoid to have a method with many arguments, could have a some param for do this in openapi,yml (ex.: x-class-query-string-pack), ex:
parameters:
- name: size
in: query
x-class-query-string-pack: org.springframework.data.domain.Pageable # refer to spring interface
x-class-query-string-annotation: @PageableDefault(size = 20) # to input annotation in spring object
- name: page
in: query
x-class-query-string-pack: org.springframework.data.domain.Pageable # refer to spring interface
#other params ....
- name: isActive
in: query
x-class-query-string-pack: SampleParam # could be a class name used to create a custom pack class
# for custom class dont need annotation, is possible define default, if have using contructor, prop init value
- name: startDate
in: query
x-class-query-string-pack: SampleParam # could be a class name used to create a custom pack class
#other params ....
and this config could generate a method with a class/classes pack a query string params
Hello, I would suggest this issue for avoid to declare many query strings in method. In Spring is possible transform a methods like this:
in this method with a class with params
Spring provide class for build endpoints with many queryString params ( ex.: pagable responses), also we can split params in more class, ex.:
another detail, a pageable spring interface use annotations to configure default values when user don't send nothing, ex.:
it's is very helpfull for avoid to have a method with many arguments, could have a some param for do this in openapi,yml (ex.: x-class-query-string-pack), ex:
and this config could generate a method with a class/classes pack a query string params