0

Instead of having multiple separate parameters attached to an endpoint I have grouped them into an object that looks like:

saleParameters:
  in: query
  name: saleParameters
  schema:
    type: object
    properties:
      userIds:
        type: array
        items:
          type: integer
          format: int64
      notification:
        type: boolean
      type:
        $ref: '#/components/schemas/SaleType'
      categories:
        type: array
        items:
          type: string
      purpose:
        type: string
  style: form
  explode: true

Then I'm generating API with swagger generator, but the query parameter values won't bind to an object, because swagger adds @RequestParam like here:

default ResponseEntity<byte[]> getSaleLogs(
@ApiParam(value = "") @Valid @RequestParam(value = "saleParameters", required = false) SaleParametersDTO saleParameters

Without the annotation everything works fine. Is there a way to make swagger not generate @RequestParam annotation?

Maciaz
  • 1,084
  • 1
  • 16
  • 31
  • if it is `in: query` (GET), it will be a `@RequestParam` ..if it is `in: body` (POST/PUT), then a `@RequestBody` ...? – xerx593 Nov 25 '21 at 10:42
  • Meaning there's no way to make generator NOT add the annotation? – Maciaz Nov 25 '21 at 10:43
  • It does exactly what you configured your API to be, if it isn't a parameter then don't write your API in that way. – M. Deinum Nov 25 '21 at 10:49
  • is it a GET or a POST ??? If you do `in: body`, then it will be `@RequestBody` (and the list of alternatives is finite (only @PathVariable (in: path) or @RequestParam (in: query) or ..body) – xerx593 Nov 25 '21 at 10:50
  • @M.Deinum - It is a parameter. Every single value of an object could be a separate parameter. Spring just can't bind the parameter values to that grouping object. – Maciaz Nov 25 '21 at 10:52
  • Query parameters in OpenAPI can only be simple objects with primitive properties, they [cannot be nested objects](https://stackoverflow.com/a/67780788/113116) like in your example. Nested objects should be either passed in the request body (as other commenters suggested), or split into separate query parameters. – Helen Nov 25 '21 at 11:44
  • 1
    As stated OpenAPI generates what you told it to do. Which is that you are sending a parameter, spring has no problem in binding that however the value of the parameter should be then send as a JSON value of that parameter. – M. Deinum Nov 25 '21 at 11:59

0 Answers0