0

I have written a swagger ui for a GET request that doesn't need a request body. I haven't used the @RequestBody annotation so why is Swagger bringing up a request body field on the ui? Even if I leave it empty, it is causing my API requests to fail with the following error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

I understand why this error exists, the curl that swagger creates has a -d option. But how can I switch this off?

The only annotations I've used are @Get, @Path, @Operation, @ApiResponses, and @Parameters.

Put simply, how can I tell swagger that I don't need a request body?

suleydaman
  • 463
  • 1
  • 7
  • 18
  • 1
    It's not an answer so I'll add it as comment: if you aren't heavily invested in swagger annotations, give up on it and pick Endpoints or Tapis. Time and time again I saw bugs or inconsistencies or counter-intuitive idiosyncrasies of `swagger-core` - while spec itself is OK, Java annotation->spec and spec->code generators are unreliable and you will have such quirks every now and then. – Mateusz Kubuszok Jul 25 '19 at 13:11

1 Answers1

1

If you hadn't annotated some parameter of your method it is automatically considered request body. If you don't want it to, you have to explicitly annotate it as something else or annotate it to ignore param with something like @ApiParam(hidden = true):

  // example usage of Swagger with Akka HTTP
  @ApiOperation(
    httpMethod = "GET",
    response   = classOf[ApiResponseX],
    value      = "docs"
  )
  @ApiImplicitParams(
    Array(
      new ApiImplicitParam(
        name      = "id",
        dataType  = "string",
        paramType = "query",
        value     = "id docs"
      )
    )
  )
  def fetchX(
    // even if this value has custom handling I have to explicitly ignore it,
    // to not make it into a request body
    @ApiParam(hidden = true) id: UUID
  ): Route = ...
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64