11package org.openapitools.api
22
33import org.springframework.data.domain.Pageable
4+ import org.springframework.data.web.PageableDefault
45import org.openapitools.model.Pet
56import org.openapitools.model.PetSort
7+ import org.springframework.data.domain.Sort
8+ import org.springframework.data.web.SortDefault
69import org.openapitools.configuration.ValidSort
710import org.springframework.http.HttpStatus
811import org.springframework.http.MediaType
@@ -60,19 +63,94 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
6063 }
6164
6265
63- @ValidSort(allowedValues = [" id,asc" , " id,desc" , " createdAt,asc" , " createdAt,desc" ])
66+ @RequestMapping(
67+ method = [RequestMethod .GET ],
68+ // "/pet/findWithAllDefaults"
69+ value = [PATH_FIND_PETS_WITH_ALL_DEFAULTS ],
70+ produces = [" application/json" ]
71+ )
72+ fun findPetsWithAllDefaults (@PageableDefault(page = 0 , size = 10 ) @SortDefault.SortDefaults (SortDefault (sort = ["name"], direction = Sort .Direction .DESC ), SortDefault (sort = ["id"], direction = Sort .Direction .ASC )) pageable : Pageable ): ResponseEntity <List <Pet >> {
73+ return ResponseEntity (service.findPetsWithAllDefaults(), HttpStatus .valueOf(200 ))
74+ }
75+
76+
77+ @RequestMapping(
78+ method = [RequestMethod .GET ],
79+ // "/pet/findWithMixedSortDefaults"
80+ value = [PATH_FIND_PETS_WITH_MIXED_SORT_DEFAULTS ],
81+ produces = [" application/json" ]
82+ )
83+ fun findPetsWithMixedSortDefaults (@SortDefault.SortDefaults (SortDefault (sort = ["name"], direction = Sort .Direction .DESC ), SortDefault (sort = ["id"], direction = Sort .Direction .ASC )) pageable : Pageable ): ResponseEntity <List <Pet >> {
84+ return ResponseEntity (service.findPetsWithMixedSortDefaults(), HttpStatus .valueOf(200 ))
85+ }
86+
87+
88+ @RequestMapping(
89+ method = [RequestMethod .GET ],
90+ // "/pet/findWithPageAndSizeConstraint"
91+ value = [PATH_FIND_PETS_WITH_PAGE_AND_SIZE_CONSTRAINT ],
92+ produces = [" application/json" ]
93+ )
94+ fun findPetsWithPageAndSizeConstraint (pageable : Pageable ): ResponseEntity <List <Pet >> {
95+ return ResponseEntity (service.findPetsWithPageAndSizeConstraint(), HttpStatus .valueOf(200 ))
96+ }
97+
98+
99+ @RequestMapping(
100+ method = [RequestMethod .GET ],
101+ // "/pet/findWithPageSizeDefaultsOnly"
102+ value = [PATH_FIND_PETS_WITH_PAGE_SIZE_DEFAULTS_ONLY ],
103+ produces = [" application/json" ]
104+ )
105+ fun findPetsWithPageSizeDefaultsOnly (@PageableDefault(page = 0 , size = 25 ) pageable : Pageable ): ResponseEntity <List <Pet >> {
106+ return ResponseEntity (service.findPetsWithPageSizeDefaultsOnly(), HttpStatus .valueOf(200 ))
107+ }
108+
109+
64110 @RequestMapping(
65111 method = [RequestMethod .GET ],
66112 // "/pet/findWithRefSort"
67113 value = [PATH_FIND_PETS_WITH_REF_SORT ],
68114 produces = [" application/json" ]
69115 )
70- fun findPetsWithRefSort (pageable : Pageable ): ResponseEntity <List <Pet >> {
116+ fun findPetsWithRefSort (@ValidSort(allowedValues = [ " id,asc " , " id,desc " , " createdAt,asc " , " createdAt,desc " ]) @PageableDefault(page = 0 , size = 20 ) pageable : Pageable ): ResponseEntity <List <Pet >> {
71117 return ResponseEntity (service.findPetsWithRefSort(), HttpStatus .valueOf(200 ))
72118 }
73119
74120
75- @ValidSort(allowedValues = [" id,asc" , " id,desc" , " name,asc" , " name,desc" ])
121+ @RequestMapping(
122+ method = [RequestMethod .GET ],
123+ // "/pet/findWithSizeConstraint"
124+ value = [PATH_FIND_PETS_WITH_SIZE_CONSTRAINT ],
125+ produces = [" application/json" ]
126+ )
127+ fun findPetsWithSizeConstraint (pageable : Pageable ): ResponseEntity <List <Pet >> {
128+ return ResponseEntity (service.findPetsWithSizeConstraint(), HttpStatus .valueOf(200 ))
129+ }
130+
131+
132+ @RequestMapping(
133+ method = [RequestMethod .GET ],
134+ // "/pet/findWithSortDefaultAsc"
135+ value = [PATH_FIND_PETS_WITH_SORT_DEFAULT_ASC ],
136+ produces = [" application/json" ]
137+ )
138+ fun findPetsWithSortDefaultAsc (@SortDefault.SortDefaults (SortDefault (sort = ["id"], direction = Sort .Direction .ASC )) pageable : Pageable ): ResponseEntity <List <Pet >> {
139+ return ResponseEntity (service.findPetsWithSortDefaultAsc(), HttpStatus .valueOf(200 ))
140+ }
141+
142+
143+ @RequestMapping(
144+ method = [RequestMethod .GET ],
145+ // "/pet/findWithSortDefaultOnly"
146+ value = [PATH_FIND_PETS_WITH_SORT_DEFAULT_ONLY ],
147+ produces = [" application/json" ]
148+ )
149+ fun findPetsWithSortDefaultOnly (@SortDefault.SortDefaults (SortDefault (sort = ["name"], direction = Sort .Direction .DESC )) pageable : Pageable ): ResponseEntity <List <Pet >> {
150+ return ResponseEntity (service.findPetsWithSortDefaultOnly(), HttpStatus .valueOf(200 ))
151+ }
152+
153+
76154 @RequestMapping(
77155 method = [RequestMethod .GET ],
78156 // "/pet/findByStatusWithSort"
@@ -81,7 +159,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
81159 )
82160 fun findPetsWithSortEnum (
83161 @Valid @RequestParam(value = " status" , required = false ) status : kotlin.String? ,
84- pageable : Pageable
162+ @ValidSort(allowedValues = [ " id,asc " , " id,desc " , " name,asc " , " name,desc " ]) @PageableDefault(page = 0 , size = 20 ) pageable : Pageable
85163 ): ResponseEntity <List <Pet >> {
86164 return ResponseEntity (service.findPetsWithSortEnum(status), HttpStatus .valueOf(200 ))
87165 }
@@ -93,15 +171,22 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
93171 value = [PATH_FIND_PETS_WITHOUT_SORT_ENUM ],
94172 produces = [" application/json" ]
95173 )
96- fun findPetsWithoutSortEnum (pageable : Pageable ): ResponseEntity <List <Pet >> {
174+ fun findPetsWithoutSortEnum (@PageableDefault(page = 0 , size = 20 ) pageable : Pageable ): ResponseEntity <List <Pet >> {
97175 return ResponseEntity (service.findPetsWithoutSortEnum(), HttpStatus .valueOf(200 ))
98176 }
99177
100178 companion object {
101179 // for your own safety never directly reuse these path definitions in tests
102180 const val PATH_FIND_PETS_AUTO_DETECTED_WITH_SORT : String = " /pet/findAutoDetectedWithSort"
103181 const val PATH_FIND_PETS_NON_PAGINATED_WITH_SORT_ENUM : String = " /pet/findNonPaginatedWithSortEnum"
182+ const val PATH_FIND_PETS_WITH_ALL_DEFAULTS : String = " /pet/findWithAllDefaults"
183+ const val PATH_FIND_PETS_WITH_MIXED_SORT_DEFAULTS : String = " /pet/findWithMixedSortDefaults"
184+ const val PATH_FIND_PETS_WITH_PAGE_AND_SIZE_CONSTRAINT : String = " /pet/findWithPageAndSizeConstraint"
185+ const val PATH_FIND_PETS_WITH_PAGE_SIZE_DEFAULTS_ONLY : String = " /pet/findWithPageSizeDefaultsOnly"
104186 const val PATH_FIND_PETS_WITH_REF_SORT : String = " /pet/findWithRefSort"
187+ const val PATH_FIND_PETS_WITH_SIZE_CONSTRAINT : String = " /pet/findWithSizeConstraint"
188+ const val PATH_FIND_PETS_WITH_SORT_DEFAULT_ASC : String = " /pet/findWithSortDefaultAsc"
189+ const val PATH_FIND_PETS_WITH_SORT_DEFAULT_ONLY : String = " /pet/findWithSortDefaultOnly"
105190 const val PATH_FIND_PETS_WITH_SORT_ENUM : String = " /pet/findByStatusWithSort"
106191 const val PATH_FIND_PETS_WITHOUT_SORT_ENUM : String = " /pet/findWithoutSortEnum"
107192 }
0 commit comments