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?

7
  • if it is in: query (GET), it will be a @RequestParam ..if it is in: body (POST/PUT), then a @RequestBody ...? Commented Nov 25, 2021 at 10:42
  • Meaning there's no way to make generator NOT add the annotation? Commented Nov 25, 2021 at 10:43
  • 1
    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. Commented Nov 25, 2021 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) Commented Nov 25, 2021 at 10:50
  • 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. Commented Nov 25, 2021 at 11:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.