Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3619

Grouping path & query request parameters for Swagger UI doc (Spring Boot)

$
0
0

Let's assume that I got two GET method implementations

@RestController@RequestMapping("/products/{id}")public class ProductController {    @GetMapping(path = "/one")    public ResponseEntity<List<Product>> one(            @Parameter(/* doc */) @PathVariable String id,            @Parameter(/* doc */) @RequestParam(required = false) String query,            @Parameter(/* doc */) @RequestParam(defaultValue = "0") Integer offset,            @Parameter(/* doc */) @RequestParam(defaultValue = "10") Integer limit,            @Parameter(/* doc */) @RequestParam(required = false) List<String> categories) {        return ResponseEntity.noContent();    }    @GetMapping(path = "/two")    public ResponseEntity<List<Product>> two(            @Parameter(/* doc */) @PathVariable String id,            @Parameter(/* doc */) @RequestParam(required = false) String query,            @Parameter(/* doc */) @RequestParam(defaultValue = "0") Integer offset,            @Parameter(/* doc */) @RequestParam(defaultValue = "10") Integer limit,            @Parameter(/* doc */) @RequestParam(required = false) List<String> categories) {        return ResponseEntity.noContent();    }}

I tried with creating record

record ProductParameters(    @Parameter(/* doc */) @PathVariable String id,    @Parameter(/* doc */) @RequestParam(required = false) String query,    @Parameter(/* doc */) @RequestParam(defaultValue = "0") Integer offset,    @Parameter(/* doc */) @RequestParam(defaultValue = "10") Integer limit,    @Parameter(/* doc */) @RequestParam(required = false) List<String> categories) {}

but in Swagger UI I got those one and two methods with single param productParameters and just one entry in Schemas below... It looks like a request body with this "solution".

Have you got any idea, how can I group request path/query parameters in Spring Boot to avoid duplications? When I got different project (not Spring based), I just use @BeanParam for that.


Viewing all articles
Browse latest Browse all 3619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>